Password hashing explained in plain terms starts with a leak. When a database of user accounts is stolen, the question is whether the thief walks away with passwords or with useless strings, and the answer is hashing: storing a one-way fingerprint of each password instead of the password itself. The central question is why some fingerprints resist cracking for years while others fall in hours, and the answer is salt plus deliberate slowness, two ingredients that turn a fast calculation into an expensive one for attackers.
A hash function takes a password and produces a fixed-length string that cannot be reversed. The same password always gives the same hash, a different password gives a different one, and there is no way to run the process backwards. When you log in, the server hashes what you typed and compares it with the stored hash, and your real password never needs to be kept anywhere.
That sounds complete, but a plain hash is not enough, as the great breaches of the last twenty years have shown again and again. This article explains the seven rules that separate a hashing scheme that holds up from one that collapses.
Key takeaways
- Never store passwords; store salted hashes made by a slow, modern algorithm.
- A unique random salt per user stops rainbow tables and identical-password matching.
- Slow hashing makes each guess expensive, which is exactly what defenders want.
- Argon2 is the current best choice, with bcrypt and scrypt as sound alternatives.
- Fast hashes such as MD5 and SHA-256 alone are not password hashing.
Rule 1: never store the password itself
The first rule is absolute: a system should never store a password in plain text, encrypted with a reversible key, or in any form that can be turned back into the password. A hash is one-way by design, so even the operator of the service cannot read your password, and a stolen database yields fingerprints rather than logins.
Encryption is not a substitute, because encryption is reversible by anyone holding the key, and keys leak, get copied into backups, and end up in the hands of people who should not have them. Hashing removes the password from the system entirely, which is a far stronger guarantee than hiding it behind a key.
The history here is grim. Breach after breach has exposed millions of plain-text passwords, and each one became a credential-stuffing list that attackers tried against banks, email, and shops for years. A hashed database still hurts when it leaks, but the damage is measured in weeks of cracking effort rather than instant compromise.
Rule 2: give every password its own salt
A salt is a random string, unique to each user, that is mixed with the password before hashing. It is stored beside the hash in plain text, because it is not a secret; its job is to make every hash different, even when two users choose the same password.
Without salts, an attacker can precompute the hashes of millions of common passwords once, in a rainbow table, and then match them against every account in a stolen database in seconds. With salts, that table is useless, because each password must be hashed separately with each user’s salt, and the work multiplies by the number of users.
Salts also hide the fact that two users share a password. Without them, identical hashes betray identical passwords, and attackers start with the most common one. With them, every hash looks unrelated, and the attacker learns nothing from the pattern of the database itself.
Rule 3: make hashing deliberately slow
General-purpose hashes such as SHA-256 are designed to be fast, which is the opposite of what password storage needs. A modern graphics card can try billions of SHA-256 hashes per second, so a leaked database of fast hashes falls quickly to a dictionary attack, however strong the passwords look.
Password hashing algorithms are deliberately slow and tunable. Argon2, bcrypt, and scrypt each have a cost setting that makes one hash take a noticeable fraction of a second, which a user logging in never notices, but which turns billions of guesses into years of work for an attacker.
The cost should rise as hardware improves. A setting chosen in 2016 is too cheap today, so teams should review their cost factor each year and re-hash passwords at login, when the plain password is briefly available, to move users onto stronger settings without asking them to do anything.

Rule 4: use a modern algorithm
Argon2 is the current recommendation, winner of the Password Hashing Competition in 2015, and it is designed to resist both graphics-card attacks and custom hardware by using memory as well as time. Its memory cost makes each guess expensive in a way that money cannot easily buy around.
Bcrypt, from 1999, remains a sound choice, and it is built into many frameworks, which makes it the easiest good option for teams starting today. Scrypt is also strong, and it shares Argon2’s memory-hard design, though it is less widely supported in standard libraries.
MD5, SHA-1, and plain SHA-256 are not password hashing algorithms at all, however often they have been used as such. They are fast, unsalted in most careless implementations, and broken for this purpose, and any system still using them should be treated as a breach waiting to happen. Our guide to passkeys explains a login method that removes passwords from the equation entirely.
Rule 5: compare hashes in constant time
Comparing two hashes with an ordinary string comparison can leak information, because the comparison stops at the first character that differs. An attacker who can measure response times precisely can learn the hash one character at a time, which is a timing attack.
The fix is a constant-time comparison, which always takes the same time regardless of where the strings differ. Every serious framework provides one, and teams should use it rather than writing their own, because getting the details right is harder than it looks.
The same thinking applies to login responses. A system that says “wrong password” for one account and “no such user” for another tells an attacker which accounts exist. The safe answer is a single generic message for every failed login, and the same delay, so nothing leaks through timing either.
Rule 6: plan for the leak, not just the lock
Good teams assume the database will leak one day, and design for that day. Peppering adds a secret value, stored separately from the database, usually in the application configuration, which is mixed into every hash. If the database alone is stolen, the hashes cannot be cracked without the pepper, which the thief does not have.
Monitoring matters too. A sudden wave of failed logins, or logins from unusual places, should trigger alerts and, where appropriate, force a password reset. Our guide to rate limiting explains how to slow down guessing without locking out real users, and it pairs naturally with strong hashing.
When a breach does happen, the response should be fast and honest: reset the affected passwords, tell users plainly what happened, and upgrade the hashing at the same time. A breach is also the moment to move users from an old algorithm to a modern one, since the reset forces everyone through the new path anyway.
Rule 7: help users choose passwords worth hashing
Even the best hash cannot save a password like the name of a football team followed by a single digit, because the attacker will try that guess in the first minute. Length is what matters most: a passphrase of four ordinary words is far stronger than a short jumble of symbols, and far easier to remember.
Systems should check new passwords against lists of breached passwords, and refuse the ones that have already appeared in a leak. They should also drop outdated rules, such as forced rotation every ninety days, which pushes people towards weak, predictable passwords written on sticky notes.
Multi-factor authentication is the strongest partner a hash can have. Even if a password is cracked, a second factor stops the login, and our guide to zero trust explains why trusting a password alone is no longer enough for anything important.
Comparing password hashing algorithms
Choosing between the modern algorithms is less important than leaving the broken ones behind, but the differences are worth knowing. Argon2 leads on resistance to custom hardware, bcrypt leads on maturity and library support, and scrypt sits between them.
The table below compares the main options.
| Aspect | Argon2 | bcrypt | scrypt | SHA-256 alone |
|---|---|---|---|---|
| Designed for passwords | Yes | Yes | Yes | No |
| Memory-hard | Yes | No | Yes | No |
| Built-in salt | Yes | Yes | Needs one added | No |
| Tunable cost | Time and memory | Cost factor | Time and memory | None |
| Verdict | Best choice today | Safe and simple | Strong alternative | Not suitable |
The honest summary is that any of the first three, used properly with a unique salt and a sensible cost, will protect your users. The dangerous choice is the last column, or any home-grown scheme invented in an afternoon.
Password hashing checklist
- Store only salted hashes, never plain-text passwords or reversible encryption.
- Use Argon2 where you can, bcrypt or scrypt where you cannot.
- Generate a unique random salt for every user, at least 16 bytes long.
- Set the cost so one hash takes a noticeable fraction of a second.
- Compare hashes in constant time and give one generic message for failed logins.
- Add a pepper stored separately from the database for extra defence.
- Check new passwords against breach lists and refuse the leaked ones.
- Re-hash at login when the cost settings rise, without bothering the user.
- Pair hashing with multi-factor authentication on anything important.
Frequently asked questions
What is password hashing?
It is the practice of storing a one-way fingerprint of a password, rather than the password itself, so that a stolen database does not hand the thief your login.
Why do passwords need salt?
A salt is a unique random value mixed into each hash, which stops attackers precomputing hashes in bulk and hides the fact that two users chose the same password.
Is SHA-256 good enough for passwords?
No. It is designed to be fast, so an attacker with a graphics card can try billions of guesses per second. Password hashing needs an algorithm that is deliberately slow, such as Argon2 or bcrypt.
What is the difference between hashing and encryption?
Hashing is one-way and cannot be reversed, while encryption is reversible with the right key. Passwords should be hashed, because there is no reason for anyone, including the operator, to recover them.
Can a hashed password be cracked?
Yes, if the password is weak or the hash is fast and unsalted. A strong, unique passphrase hashed with Argon2 and a salt is, for practical purposes, beyond the reach of cracking.
Should users still use a password manager?
Absolutely. A manager creates a long, random password for every site, so one leak never endangers another account, and it removes the memory burden that pushes people towards weak passwords.
The bottom line
Password hashing explained in one line is this: salt every password, hash it slowly with a modern algorithm, and never keep the password itself.
The rules are few and the cost of following them is small, while the cost of ignoring them is measured in breaches, lawsuits, and users who never come back.
This article is general information about how password hashing works, not advice about securing a particular application.







