Security

Password Entropy Explained: How to Calculate It (With Examples)

Password entropy measures how many guesses a random password would take to find, in bits: entropy = length × log2(number of possible characters). A 12-character password drawn at random from the 94 printable ASCII characters has 12 × 6.55 ≈ 78.7 bits, meaning an attacker faces 278.7 possibilities; each extra bit doubles the work.

The password entropy formula

For a password where every character is picked independently and uniformly at random:

E = L × log2(N)

E = entropy in bits
L = length (number of characters, or number of words)
N = size of the pool each character (or word) is drawn from

Equivalently, the number of possible passwords is NL, and entropy is log2 of that count. An attacker who tries every possibility needs at most 2E guesses and, on average, half that: 2E−1.

Pool sizes for the common character sets:

Character setPool size NBits per character, log2(N)
Digits 0 to 9 (a PIN)103.32
Lowercase a to z264.70
Upper and lowercase letters525.70
Letters and digits625.95
All printable ASCII (letters, digits, 32 symbols)946.55
One word from the EFF long wordlist7,77612.92

Worked examples

A 4-digit PIN: 4 × log2(10) = 4 × 3.32 = 13.3 bits. That is 10,000 combinations, which is why PINs rely on lockouts after a few wrong tries.

An 8-character random password, letters and digits: 8 × 5.95 = 47.6 bits, or 628 ≈ 218 trillion possibilities.

A 16-character random password, all printable ASCII: 16 × 6.55 = 104.9 bits.

A six-word diceware passphrase: 6 × 12.92 = 77.5 bits. The EFF's own page puts it as one of 221,073,919,720,733,357,899,776 alternatives, "about 277". That number is exactly 7,7766, and you can check it in any calculator.

To compute it yourself in Python:

python -c "import math; print(16 * math.log2(94))"
104.8734216268422

Entropy by length: the full table

Bits of entropy for passwords generated uniformly at random (calculated with the formula above, rounded to 0.1):

LengthDigits (10)Lowercase (26)Letters + digits (62)Printable ASCII (94)EFF words (7,776)
413.318.823.826.251.7
619.928.235.739.377.5
826.637.647.652.4103.4
1239.956.471.578.7155.1
1549.870.589.398.3193.9
1653.275.295.3104.9206.8
2066.494.0119.1131.1258.5

Read across a row and the pattern is clear: length matters more than character variety. A 16-character lowercase password (75.2 bits) beats a 12-character password using every symbol on the keyboard (78.7 bits) by only a little, but 20 lowercase characters (94.0 bits) beat it comfortably, and lowercase is far easier to type on a phone.

What the bits mean in guessing time

Entropy turns into time once you assume a guessing rate. The rate depends entirely on the situation, so here are two illustrative rates rather than a claim about any particular attacker: 10 guesses per second (an online login form with rate limiting) and 10 billion guesses per second (an offline attack on a stolen database of fast, unsalted hashes). Average time is 2E−1 divided by the rate:

EntropyAt 10 guesses/secondAt 10 billion guesses/second
40 bitsabout 1,700 yearsabout 55 seconds
60 bitsabout 1.8 billion yearsabout 1.8 years
80 bitsfar longer than the age of the universeabout 1.9 million years
128 bitsfar longer than the age of the universeabout 5 × 1020 years

The gap between the two columns is the point NIST makes in Appendix A of SP 800-63B: online guessing "can be mitigated by limiting the permitted login attempt rate", but after a database breach there is no rate limit, so passwords must be "orders of magnitude more complex" to survive offline attacks.

The catch: entropy only applies to random passwords

The formula assumes every character was chosen at random. Humans don't choose that way, so applying it to a password you made up gives a number that is too high, sometimes absurdly so.

Take Password1!. Naively it is 10 characters from a pool of 94, so 65.5 bits. In reality it is one of the first things any cracking tool tries, because it is a dictionary word, capitalised at the start, with a digit and a symbol tacked on the end. NIST uses exactly this example: research found that a user who would pick "password" tends to pick "Password1!" when a symbol is required. That is also why NIST says estimating entropy for user-chosen passwords "is challenging" and bases its rules mainly on length instead.

The honest way to think about it: entropy is a property of the process that generated the password, not of the string itself. kq7#Lp2!xW9z has about 78.7 bits if a generator produced it uniformly from 94 characters. The same string has almost no entropy if it is printed in this article and you copy it, because an attacker who has read this page can try it first.

What NIST requires instead of entropy

NIST SP 800-63B-4 sets length and blocklist rules rather than entropy targets:

  • Passwords used as the only authentication factor must be at least 15 characters. Passwords used as part of multi-factor authentication must be at least 8.
  • Verifiers should accept passwords of at least 64 characters.
  • No composition rules: sites "SHALL NOT impose other composition rules", such as requiring a mix of character types.
  • No forced periodic changes, unless there is evidence of compromise.
  • New passwords must be checked against a blocklist of commonly used, expected or compromised passwords.

Notice how this lines up with the table: 15 random lowercase letters already give 70.5 bits, and the blocklist catches the predictable human choices that the formula overrates.

How to get real entropy

The only way to know a password's entropy is to generate it randomly with a cryptographically secure source. Options:

  • A password manager's generator. Set the length to 16 or more.
  • A browser-based generator such as the larely password generator, which runs locally in your browser and shows the length × log2(pool) entropy for the settings you pick.
  • Dice. The EFF method: roll five dice per word, look the number up in the long wordlist, and use at least six words.
  • Python's secrets module, which the Python documentation says "should be used in preference to the default pseudo-random number generator in the random module". The random module is designed for simulation, not security.
python -c "import secrets, string; a = string.ascii_letters + string.digits; print(''.join(secrets.choice(a) for _ in range(16)))"

That prints a 16-character letters-and-digits password with 16 × 5.95 = 95.3 bits of entropy. Run it again and you get a different one.

Entropy for other secrets

The same arithmetic applies to API keys, tokens and recovery codes. The Python secrets documentation notes that, as of 2015, 32 bytes (256 bits) of randomness was believed sufficient for typical uses, and secrets.token_urlsafe(32) produces exactly that as a 43-character string. A one-time code from an authenticator app is a different case: six digits is only 19.9 bits, which is safe only because each code expires within seconds and servers limit attempts. How 2FA codes work explains that design.

Frequently asked questions

How many bits of entropy is a good password?
For a randomly generated password protecting something important, aim for at least 70 to 80 bits. That is about 12 to 13 random characters from all 94 printable ASCII characters, 16 random lowercase letters, or six words from the EFF long wordlist. Each extra bit doubles the number of guesses an attacker needs.
Does adding a symbol make my password much stronger?
Only if the password is random. Going from 62 to 94 possible characters adds about 0.6 bits per character, while adding one more random character adds 5.9 to 6.6 bits. For a human-chosen password, a symbol added in a predictable place, such as an exclamation mark at the end, adds very little.
Why do password strength meters disagree?
Simple meters apply the length × log2(pool) formula to whatever you type, so they overrate predictable passwords like Password1!. Better meters also look for dictionary words, keyboard patterns, dates and known breached passwords. No meter can know how the password was really chosen, which is what entropy actually depends on.
Is a passphrase better than a random password?
Per bit, they are equal: 77 bits is 77 bits. A passphrase reaches that with six random words, which many people find easier to type and remember than 12 random characters. The words must be picked randomly, with dice or a generator, not chosen by you.

Sources