Find a course

Module 2: Identity and AccessLesson 3 of 1214 min

Passwords, Entropy and Hashing

Measure password strength in bits of entropy, see why length beats complexity, and learn how services store passwords safely with salted hashes.

Step 1 of 10Learn

Why "P@ssw0rd!" is weak

"P@ssw0rd!" has uppercase, lowercase, numbers and symbols. Many sites would accept it happily. It's also one of the first guesses any cracking tool will try, because attackers know exactly how people "strengthen" common words: capitalize the first letter, swap a for @ and o for 0, add an exclamation mark at the end.

Attackers rarely guess passwords one by one at a login page; those are rate-limited. The real danger is offline cracking. When a site is breached, attackers steal the database of stored password hashes and test billions of guesses per second on their own hardware. They start with wordlists of real leaked passwords, apply common substitutions, and only then fall back to brute force.

So password strength is about unpredictability, not about looking complicated. A random 16-character password, or a passphrase of four or five random words such as "orbit-velvet-candle-harbor", is far stronger than a short password with symbols, because the number of possibilities grows enormously with length.

The other big problem is reuse. Billions of username and password pairs from old breaches circulate online. In credential stuffing attacks, bots try those pairs on banks, email and shopping sites. If you reused a password, one breach anywhere opens every account that shares it. The practical answer is a password manager: it generates and remembers a long, unique password for every site, so you only need to remember one strong master passphrase.

Step 2 of 10Learn

Entropy: counting the guesses

Security people measure password strength in bits of entropy. For a password chosen truly at random:

Entropy (bits) = length × log₂(size of the character set)

The number of possible passwords is (character set size)^length, and entropy is just that number expressed as a power of two. Every extra bit doubles the work for an attacker.

Common character sets:

  • Digits only: 10 symbols, about 3.3 bits per character.
  • Lowercase letters: 26, about 4.7 bits per character.
  • Upper and lowercase: 52, about 5.7 bits.
  • All printable keyboard characters: about 94, about 6.55 bits.

Compare an 8-character password using all 94 characters (8 × 6.55 ≈ 52 bits) with a 16-character password of just lowercase letters (16 × 4.7 ≈ 75 bits). The longer, simpler one is about 223, or roughly 8 million, times harder to brute-force.

For passphrases, count words instead of characters. With a list of 7,776 words (the size of the classic diceware list), each random word adds about 12.9 bits. Five random words give about 65 bits; six give about 78.

One crucial caveat: the formula only applies to randomly generated passwords. A human-chosen password like "Summer2025!" has far less real entropy than its length suggests, because attackers guess patterns, not random strings.

Step 3 of 10Explore

Entropy grows with length

The line shows entropy in bits for a random password as length increases. Change the character set size to compare digits (10), lowercase (26), mixed case (52) and full keyboard (94).

050100150 5101520
Bits per character
4.7
Entropy at 8 characters
37.6 bits
Entropy at 16 characters
75.2 bits

Step 4 of 10Try the calculator

Brute-force time estimator

Estimate how long an attacker would need to try every possible random password. Offline attacks on weak, fast hashes can reach tens of billions of guesses per second on a single rig; slow password hashes cut that by many orders of magnitude.

Entropy
37.6 bits
Seconds to try every combination
21 s
Years to try every combination
0 years

Step 5 of 10Practice · Work it out

Use the estimator: at 10 billion guesses per second, about how many seconds does it take to try every possible 8-character password made only of lowercase letters? Round to the nearest second.

Step 6 of 10Practice · Code challenge

Write a function entropyBits(length, charsetSize) that returns the entropy of a random password in bits, rounded to the nearest whole number. Use Math.log2 and Math.round.

Runs in a sandbox in your browser.
  • entropyBits(8, 26)
  • entropyBits(12, 94)
  • entropyBits(4, 10)
  • entropyBits(20, 2)

Step 7 of 10Learn

How services should store passwords

A well-built website never stores your actual password. Instead it stores a hash: the output of a one-way function that turns any input into a fixed-length fingerprint. When you log in, the site hashes what you typed and compares the result with the stored hash. If they match, you're in. Because the function is one-way, a stolen hash can't simply be reversed; an attacker has to guess passwords, hash each guess and look for a match.

Two more ingredients make this much stronger:

Salting. Before hashing, the system adds a random value, the salt, unique to each user, and stores it alongside the hash. Without salts, everyone who chose "sunshine1" would have the identical hash, and attackers could use huge precomputed tables (rainbow tables) to look up millions of hashes at once. With salts, every hash is different, so each one must be attacked separately.

Slow hashing. General-purpose hashes like SHA-256 are designed to be fast, which helps attackers try billions of guesses per second. Password hashing algorithms such as bcrypt, scrypt and Argon2 are deliberately slow and memory-hungry, and can be tuned so each guess takes a noticeable fraction of a second. For a user logging in once, that's unnoticeable; for an attacker trying billions of guesses, it's crippling.

If a breach notice says passwords were stored in plain text or with a fast unsalted hash, change that password everywhere you used it, immediately.

Step 8 of 10Note

Step 9 of 10Compare

Password storage methods

AspectMethodIf the database is stolen
Plain textStores the password itselfEvery password is exposed instantly
Fast hash, no saltStores SHA-256(password)Common passwords cracked in seconds with lookup tables
Fast hash with saltStores salt + SHA-256(salt + password)No lookup tables, but billions of guesses per second still possible
Slow password hash with saltStores salt + bcrypt, scrypt or Argon2 outputEach guess is expensive; strong passwords stay safe for a very long time

Step 10 of 10Practice · Choose one

What is the main purpose of adding a unique salt to each password before hashing?