Everyday math · Phones & the internet
Why can’t a website tell you your old password?
Short answer: a website that stores passwords properly doesn’t keep your password at all. It keeps a “hash”, the output of a one-way function: going from password to hash is instant, but going from the hash back to the password is not possible. So the site has no old password to send back. All it can do is send you a link to set a new one.
A hash is a one-way function
Think of a function in math class: put in x, get out f(x). One widely used hash is SHA-256 (standard FIPS 180-4 from the U.S. institute NIST). Feed it a message of any length and you always get 256 bits out, which is 64 characters in hexadecimal.
- Same message in, same hash out, every time ⇒ this is how a website checks your password
- Change just 1 character and almost the whole hash changes ⇒ the hash gives no hint of what the password is close to
Example: “atmath” and “atmatH” differ only in the last letter
SHA-256(“atmath”)a5e19fc5ead3b732433def686284bf131bdf64b58c3dadce35c3e4f019b00ff0
SHA-256(“atmatH”)88e8bcfc878e267e07c09d307853f9da865e1a14f5ffd204ef5c9cb1cf1f07db
129 of 256 bits differ · of the 64 hex characters, only 2 match (orange = different)
We repeated this on a computer 10,000 times (a random 8-character message, then 1 character changed): on average the hash changed 128.1 bits (fewest 98, most 156), almost exactly half of 256 bits, which is what a good hash function should do
How can a website check your password without storing it?
- When you sign up: the site picks a short random string just for you, called a salt, and stores only the salt and hash(salt + password). The real password is thrown away
- When you log in: what you type + the same salt are hashed again · matching hash = correct password
- When you forget it: the site has no old password to look at, so it sends a reset link · guidance from OWASP (a web security community) also says never send passwords by email
Flip it around: if you click “forgot password” and the site sends your old password back, it is storing passwords in a reversible form. Don’t reuse that password anywhere else.
Try it
⚠️ Don’t type a real password. Made-up words show the idea just as well (everything runs on your device; nothing you type is sent anywhere)
1 · Change 1 character: how much does the hash change?
2 · What does salt do?
2 people happen to use the same password · turn salt off and on and look at the hashes the site stores
Simple demo: hash = SHA-256(salt + password) · the salt is 32 bits
3 · If an attacker gets the hash, how long does guessing take?
Choose which kinds of characters the password may use, and its length · assume the password is random characters
Why it can’t be reversed
- Information is lost on the way (just count): there are endlessly many possible messages, but a 256-bit hash has only 2256 ≈ 1.2 × 10⁷⁷ possible values ⇒ many messages must share the same hash (the pigeonhole principle), so a hash doesn’t carry enough information to give the real password back
- No shortcut: SHA-256 mixes the bits with wrap-around addition (remainder after dividing by 232), shifts and rotations, repeated for 64 rounds · FIPS 180-4 calls it “secure” because finding a message that gives a chosen hash is computationally infeasible · what’s left is guessing one password at a time and comparing hashes
The attacker’s only way: guessing · longer takes longer
For a password L characters long, with n choices per character, there are nL possible passwords (the multiplication principle) · the table shows the time to try every one (on average the right one turns up in about half this time)
Wide table ⇒ swipe left and right to see it all
| Password | nL | Possibilities | Fast hash | Slow hash |
|---|---|---|---|---|
| 4-digit PIN | 104 | 10,000 | under 1 second | 1.0 seconds |
| 8 lowercase | 268 | 208,827,064,576 | 21 seconds | 242 days |
| 8 lower+upper+digits | 628 | 218,340,105,584,896 | 6.1 hours | 692 years |
| 8, all 4 kinds | 948 | 6.1 × 10¹⁵ | 7.1 days | 19,329 years |
| 12 lowercase | 2612 | 9.5 × 10¹⁶ | 110 days | 302,603 years |
| 15 lowercase | 2615 | 1.7 × 10²¹ | 5,319 years | 5.3 × 10⁹ years |
The guessing speeds are assumed numbers for comparison: fast hash 10 billion guesses per second · slow hash 10,000 guesses per second (1,000,000 times slower) · a year = 365 days
- Length beats complexity: 12 lowercase letters give about 437 times more possibilities to guess than an 8-character password mixing lower, upper and digits · NIST SP 800-63B-4 asks for passwords used on their own to be at least 15 characters (at least 8 when combined with another factor) and says sites should not force a mix of character types
- ⚠️ This table only applies to truly random passwords. Words and popular patterns (like 123456, or a name + birth year) are always tried first, so they fall much faster than the table says
What salt is for
A salt is a random string unique to each person, attached to the password before hashing · OWASP explains that different salts make identical passwords produce different hashes, and stop attackers from using precomputed hash tables (rainbow tables) · NIST requires salts of at least 32 bits
Example: 2 people with the password “123456”
No salt (same for the 2 people)8d969eef6ecad3c29a3a629280e686cf0c3f5d5a86aff3ca12020c923adc6c92
salt 9f2c4a1e43f396b73b8ec016aa9abacfc35c0f22667f24c4265d841ae41293ad85c4073b
salt 03b7d58ced0b2093066df075b9c918faa42173423f1726c8d470a9cd17dce48616b01a93
Why real websites don’t use plain SHA-256
Because it is too fast · OWASP says fast hashes like SHA-256 are unsuitable for storing passwords, since attackers can make huge numbers of guesses ⇒ sites should use functions designed to be slow on purpose, such as Argon2id (the first recommendation), scrypt, bcrypt or PBKDF2 · this page uses SHA-256 only to show the idea
Watch the video
Watch on YouTube · Watch on TikTok
Watch on YouTube
The video loads from YouTube (youtube-nocookie.com) only after you press play. · YouTube channel: atmath (@atmathapp)
The math behind it
- Directly: functions (1 input always gives 1 output) · the multiplication principle and exponents (nL) · the pigeonhole principle
- Behind the scenes: binary and hexadecimal (1 hex character = 4 bits ⇒ 256 bits = 64 characters) · remainders (mod) inside SHA-256
Good to know
- Never type a real password into any site or app other than that service’s genuine login page
- If you reuse one password on many sites and one site leaks and the password gets guessed, attackers can try it on other sites right away
Next (cryptography series, part 2): a padlock anyone can lock but only one person can open, the prime-number math that lets us send secret messages
References
- NIST FIPS 180-4: Secure Hash Standard (SHS) · SHA-256
- OWASP: Password Storage Cheat Sheet
- OWASP: Forgot Password Cheat Sheet
- NIST SP 800-63B-4 §3.1.1 Passwords
Accessed 19 Nov 2026 · the numbers and hashes on this page were computed with our own script (SHA-256 checked against the standard’s “abc” test value)