Skip to content
Tutorials Center
My learning

Topics

Lesson 15 of 31 ยท Password Security

Password Strength, Entropy and Cracking Resistance

Understand password strength with math: keyspace, entropy in bits, guess rates, why wordlists beat complexity rules, passphrases and the role of MFA.

"Is this password strong?" sounds like a question about how it looks. It is really a question about how many guesses an attacker needs. A password is strong when the cheapest sensible strategy for guessing it takes longer than anyone will wait, or costs more than it is worth. This lesson gives you the math to reason about that: keyspace, entropy, guess rates, and why human habits matter more than special characters.

Everything here is defensive. You will calculate sizes of search spaces and time estimates for fictional guess rates. You will not crack any real hash. The previous lesson, Password Storage and Hashing, explained why the guess rate depends on how a site stores passwords, and that number is the other half of every estimate in this lesson.

Keyspace and entropy

The keyspace is the number of possible passwords under some rule. If a password is L characters long and each is chosen from an alphabet of N symbols, the keyspace is N to the power L.

  • 8 lowercase letters: 26^8, about 2.1 x 10^11
  • 8 characters from upper, lower and digits (62 symbols): 62^8, about 2.2 x 10^14
  • 12 characters from about 94 printable symbols: 94^12, about 4.8 x 10^23

Entropy expresses the same size in bits: bits = L x log2(N). Each extra bit doubles the number of guesses. This is convenient because you can add things up: 40 bits is about a trillion possibilities, 60 bits is about a quintillion, and every 10 bits multiplies the work by roughly 1,000.

Reading entropy in bits

One more bit Doubles the guesses.
Ten more bits About 1,000 times more work.
Length wins Each added character adds log2(N) bits.

On average an attacker needs half the keyspace.

1 / 2

The formula assumes characters are picked uniformly at random. That is the catch: people do not pick randomly, so the real number is far smaller than the formula for human-chosen passwords.

Python Keyspace and entropy calculator

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The last line is the key lesson from the table: length beats complexity. Sixteen plain lowercase letters carry far more entropy than eight characters with digits and capitals.

From keyspace to time

To turn a keyspace into time, divide by the guess rate, in guesses per second. The rate depends entirely on the situation:

  • Online guessing against a login page: maybe 10 per second per account before lockouts and rate limits step in.
  • Offline guessing against a stolen database with a fast hash like MD5 or unsalted SHA-256: billions per second on a graphics card.
  • Offline guessing against bcrypt, scrypt or Argon2 with a sensible cost: thousands, or fewer, per second.

The same password can be hopeless against one setup and practically unbreakable against another. The numbers below are illustrative round figures, not measurements of any real hardware.

On average, an attacker finds the password after trying half the keyspace, so the code divides by two.

Python Time to search a keyspace

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Read the output across the rows. Eight random lowercase letters fall in seconds against a fast hash but would last centuries against an online login with a rate limit. The honest reading: you cannot judge strength without also knowing how the password is stored and how guessing is limited.

Why wordlists beat the math

Real attackers rarely try every combination. They try likely passwords first. Leaked-password lists contain hundreds of millions of real choices, and humans cluster heavily: password, qwerty, names, years, Summer2024!. Attackers then apply mangling rules: capitalize the first letter, add 1 or ! at the end, swap a for @, append the current year.

This is why the usual composition rules ("one capital, one digit, one symbol") perform badly. The result is Password1!, which satisfies the rule, appears in every list, and carries almost no real entropy. Current guidance, such as NIST SP 800-63B, therefore recommends:

  • favoring length over composition rules,
  • allowing long passwords and all characters, including spaces,
  • blocking passwords found in breach lists and common-password lists,
  • not forcing periodic changes without evidence of compromise, since forced changes push people toward predictable patterns like Summer1, Summer2.

A passphrase of several random words has high entropy and is easier to remember. If words are picked uniformly from a list of 7,776 words (the size of the well-known Diceware list), each word adds log2(7776), about 12.9 bits. Four words give about 51.7 bits, five give about 64.6, six give about 77.5. The words must be chosen by dice or a program, not by the person, because "pick four words you like" lands back in the predictable zone.

Python Passphrases versus complex passwords

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

MFA changes the picture

Even a strong password can be stolen by phishing, malware or reuse on another site. Multi-factor authentication (MFA) adds a second proof: something you have (a security key, an authenticator app) in addition to something you know. Then a leaked password alone is not enough.

Not all second factors are equal. SMS codes are better than nothing, but they can be intercepted or redirected through SIM swapping. Authenticator-app codes are better. FIDO2/WebAuthn security keys and passkeys are the strongest common option because they are bound to the real site's domain, so a fake login page cannot capture them.

A short checklist for defenders:

  • Use a password manager so every account gets a long random password.
  • Turn on MFA everywhere it is offered, starting with email and financial accounts.
  • Never reuse passwords between sites: a breach on one then opens the others (credential stuffing).
  • On the server side, store with a slow hash, rate-limit logins and check against breached-password lists. The next lesson, Auditing Your Own Credential Policy, covers those controls.

What is real and what is the stand-in

The formulas, the guidance and the relative comparisons are real. The guess rates are round example numbers, not benchmarks, and the code only does arithmetic. It tests no password against any hash.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What is the entropy of a password made of 10 characters chosen uniformly at random from an alphabet of 64 symbols?

    10 x log2(64) = 10 x 6 = 60 bits.
  2. 2. Why do composition rules such as 'one capital, one digit, one symbol' often give weak passwords?

    Human choices cluster in predictable patterns, and mangling rules cover them. Length and blocking known-bad passwords work better.
  3. 3. A stolen database uses a fast unsalted hash and an attacker has strong hardware. Which statement is most accurate?

    Offline attacks against fast hashes run at billions of guesses per second, so only long random passwords hold up.
  4. 4. Why must passphrase words be chosen randomly (for example by dice)?

    The 12.9 bits per word figure assumes uniform random selection from the list. Personal choices are far less random.

Summary

  • Keyspace is alphabet size to the power of length, and entropy in bits is length times log2 of alphabet size.
  • Every extra bit doubles the guesses; length adds more entropy than complexity rules.
  • Time to crack depends on guess rate, which depends on how the password is stored and how guessing is limited.
  • Real attackers use leaked lists and mangling rules, so human-chosen patterns are far weaker than the formulas suggest.
  • Random passphrases, password managers, breach checks and MFA (ideally security keys or passkeys) are the practical defenses.

Next: Auditing Your Own Credential Policy.