Password strength and entropy

Introduction

"Your password must have an upper-case letter, a digit and a symbol." So people write Rahim@2004, which ticks every box and is guessed quickly, because it is a name, a symbol where everyone puts one, and a birth year. Meanwhile correct horse battery staple, four plain words, fails the rules and is much harder to guess.

This lesson gives you a way to measure strength honestly, entropy, and shows why the way a password was chosen matters more than how it looks.

How it works

If a password is picked at random, its strength is the number of guesses needed to be sure of finding it. That number is pool^length: with 26 lower-case letters and 8 characters there are 26⁸, about 209 billion possibilities. Big numbers like that are easier to compare as bits of entropy:

entropy = length × log₂(pool size)

Each extra bit doubles the guesses. On average an attacker finds a random password after trying half of the possibilities, 2^(bits − 1).

Length helps more than variety. Adding characters multiplies the guesses by the whole pool each time, while adding a character type only makes the pool somewhat bigger. Four random words from a list of 7776 (the Diceware list, one word per five dice rolls) give 4 × log₂(7776) ≈ 51.7 bits, as much as 8 random characters from all 95 printable ones, and much easier to remember.

The catch is the word random. Entropy measures how the password was chosen, not how it looks. People do not choose at random: they use names, years, keyboard runs and the same few favourites, and attackers try those first. Type your own examples into the meter: it shows the pool, the bits, the average guessing time at three assumed attack speeds, and the patterns that make the real number much lower.

Example

The program compares random passwords of different lengths and pools with random passphrases.

// Entropy of a randomly chosen password: length x log2(pool size).
function bits(length, pool) {
  return length * Math.log2(pool);
}

console.log("8 lower-case letters:      " + bits(8, 26).toFixed(1) + " bits");
console.log("8 from all 95 printable:   " + bits(8, 95).toFixed(1) + " bits");
console.log("12 from all 95 printable:  " + bits(12, 95).toFixed(1) + " bits");
console.log("4 words from 7776:         " + bits(4, 7776).toFixed(1) + " bits");
console.log("6 words from 7776:         " + bits(6, 7776).toFixed(1) + " bits");
Open in compiler

Line by line

  1. bits(length, pool) is the entropy formula: length × log₂(pool).
  2. 8 lower-case letters give 8 × log₂(26) ≈ 37.6 bits.
  3. Using all 95 printable characters raises 8 characters to 52.6 bits, but going to 12 characters gives 78.8 bits: length wins.
  4. Four words from 7776 give 51.7 bits, about the same as 8 fully random characters; six words give 77.5 bits.

Expected result

8 lower-case letters:      37.6 bits
8 from all 95 printable:   52.6 bits
12 from all 95 printable:  78.8 bits
4 words from 7776:         51.7 bits
6 words from 7776:         77.5 bits

How many bits are enough depends on the attack. An online login that blocks repeated failures allows only a few guesses an hour, so even 40 bits is plenty. A stolen database of fast hashes can be guessed billions of times a second, so the same password may fall in minutes. That is why the previous lesson's slow, salted hashes matter as much as the password.

In the real world

  • The US guideline NIST SP 800-63B asks sites to check new passwords against lists of leaked ones and to allow long passphrases, and advises against forced composition rules and forced regular changes.
  • Password managers generate long random passwords, so each site gets its own, and you remember just one strong passphrase.
  • Leaked-password lists contain hundreds of millions of real passwords, so anything a person once used is likely in them.
  • Mobile wallets add a short PIN and a second factor, so a weak PIN alone is not enough; the next lesson explains that layer.

Common mistakes

  • Judging strength by how it looks. P@ssw0rd! uses four character types and is still in every guessing list.
  • Making small, predictable changes. Rahim2024 to Rahim2025 is the first change an attacker tries.
  • Reusing one password everywhere. A leak at one site then opens all the others.
  • Trusting a meter's number alone. Entropy assumes random choice; a person's choice is weaker.

Best practices

  • Prefer length: a passphrase of four to six random words, or a long random password from a manager.
  • Use a different password for every site, kept in a password manager.
  • As a developer, allow long passwords, check them against leaked lists, and do not force composition rules.
  • Turn on a second factor for important accounts.

Summary

The strength of a randomly chosen password is its entropy, length × log₂(pool size), and each bit doubles the guessing work. Length adds far more than extra character types, so random passphrases are both strong and memorable. Entropy only counts if the choice was random: names, years, keyboard runs and common passwords are guessed first. Combine long, unique passwords with slow password hashing on the server and a second factor.

Quick check

1. A password is 10 random digits. About how many bits of entropy does it have?
2. Which change adds the most entropy to a random 8-character lower-case password?
3. Why can the meter's number be far too high for a password like Rahim2004?
4. Four words chosen at random from a 7776-word list give about how many bits?

Key takeaways

  • Entropy of a random password is length × log₂(pool size); each bit doubles the work.
  • Length beats variety, so random passphrases are strong and memorable.
  • Entropy assumes random choice; names, years and common passwords fall first.
  • Use a different long password per site, a password manager and a second factor.

Practice problems for this lesson

Was this lesson clear?

My notes

Write down what you want to remember from this lesson. Notes are saved on this device as you type, and appear on your dashboard.