Password hashing is the practice of storing a password not as plain text but as the output of a deliberately slow, salted one-way function, so that the system can verify a login without ever keeping the password itself. In cryptography, it is a specialized application of hashing designed for one goal: making offline guessing of stolen password databases as expensive as possible.
A general-purpose hash function such as SHA-256 is built to be fast, which is exactly wrong for passwords. Dedicated password hashing functions such as Argon2, scrypt, bcrypt and PBKDF2 add a unique salt and a tunable work factor, turning each guess into a measurable cost in time and memory for any attacker.
How password hashing protects stored credentials
Password hashing protects credentials by ensuring that a database breach yields verifiers, not passwords. When a user registers, the server generates a random salt, combines it with the password, runs the result through the password hashing function and stores the salt, the parameters and the resulting digest together.
At login, the server repeats the same computation with the stored salt and parameters and compares the result with the stored digest using a constant-time comparison. Because the function is one-way, an attacker who copies the database must guess candidate passwords and hash each one, paying the full cost of the function for every attempt.
The table below lists the components found in a typical stored password record and the role each plays.
| Component | Typical size or value | Purpose |
|---|---|---|
| Salt | 16 bytes, random per user | Makes identical passwords produce different hashes |
| Work factor | Iterations, memory, parallelism | Sets the cost of each guess |
| Digest | 32 bytes or more | The value compared at login |
| Algorithm identifier | For example $argon2id$ | Allows verification and later upgrades |
| Pepper | Secret key outside the database | Adds protection if only the database leaks |
Formats such as the PHC string format or the modular crypt format pack all of these values into one string, which lets applications upgrade parameters gradually by rehashing a password the next time its owner signs in successfully.
Password hashing algorithms and their parameters
Modern password hashing algorithms differ mainly in whether they are memory-hard, which determines how well they resist attackers using GPUs and custom hardware. Memory hardness forces each guess to use a large block of RAM, which is expensive to replicate across thousands of parallel cores.
| Algorithm | Year | Memory-hard | Main tuning parameters |
|---|---|---|---|
| Argon2id | 2015 | Yes | Memory, iterations, parallelism |
| scrypt | 2009 | Yes | CPU/memory cost N, block size r, parallelism p |
| bcrypt | 1999 | Limited, 4 KiB | Cost factor as a power of two |
| PBKDF2 | 2000 | No | Iteration count and underlying HMAC |
Argon2id, the winner of the Password Hashing Competition and specified in RFC 9106, is the current first choice for new systems. PBKDF2 remains relevant because it is approved under FIPS 140 validation regimes, which matters in government and regulated environments, but it needs very high iteration counts to compensate for its lack of memory hardness.
bcrypt is still widely deployed and reasonably strong, although it has a 72-byte input limit: characters beyond that length are silently ignored, which can surprise developers who prehash or concatenate values.
Password hashing compared with related techniques
Password hashing is often confused with general hashing and with encryption, yet each technique serves a different purpose. The comparison below shows why only a dedicated password hashing function is appropriate for stored credentials.
| Technique | Reversible | Speed | Suitable for passwords |
|---|---|---|---|
| Password hashing | No | Deliberately slow | Yes, the intended use |
| Fast hash such as SHA-256 | No | Billions per second on GPUs | No, guessing is too cheap |
| Symmetric encryption | Yes, with the key | Fast | No, key theft reveals all passwords |
| Key derivation for encryption | No | Configurable | Related, same functions often reused |
The distinction between hashing and encryption is decisive: an encrypted password table is only as safe as its key management, and a single key compromise exposes every password. Hashing removes that single point of failure, because no key exists that reverses the digests.
Choosing parameters for production systems
Parameters should be chosen so that one verification takes roughly 100 to 500 milliseconds on the production server, which is unnoticeable to a user but multiplies attacker cost enormously. The right values depend on hardware, login volume and acceptable server load.
Widely cited baselines from the OWASP password storage guidance give a practical starting point. Teams should benchmark on their own hardware and raise the parameters as servers get faster, typically reviewing them every year or two.
| Algorithm | Suggested minimum setting | Notes |
|---|---|---|
| Argon2id | 19 MiB memory, 2 iterations, 1 lane | Increase memory first if capacity allows |
| scrypt | N of 2^17, r of 8, p of 1 | Uses about 128 MiB per hash |
| bcrypt | Cost factor of 10 or higher | Watch the 72-byte input limit |
| PBKDF2-HMAC-SHA256 | 600,000 iterations | Use only when compliance requires it |
- Use a well-maintained library rather than implementing the algorithm yourself.
- Generate salts with a cryptographically secure random generator, never from usernames or timestamps.
- Store a pepper in a hardware security module or secrets manager, separate from the database.
- Rate limit login endpoints, because slow hashing increases denial-of-service exposure.
Common mistakes and failure modes
Most real-world password breaches that led to mass cracking involved avoidable implementation errors rather than flaws in modern algorithms. The table below lists the mistakes security reviewers encounter most often.
| Mistake | Consequence | Correct practice |
|---|---|---|
| Unsalted hashes | Rainbow tables crack many accounts at once | Unique random salt per password |
| Fast hash functions | GPU cracking at enormous speed | Use Argon2id, scrypt or bcrypt |
| Static low work factor | Protection erodes as hardware improves | Review and raise parameters regularly |
| Logging plaintext passwords | Hashing is bypassed entirely | Scrub credentials from logs and traces |
| Non-constant-time comparison | Timing side channels | Use library verification functions |
Password hashing also has inherent limits. It cannot protect a weak password such as a common dictionary word, because the attacker will try it within the first few guesses regardless of cost. It also offers no defense when credentials are phished or reused from another breach, which is why MFA and breached password screening remain necessary companions.
A plain-language summary
Password hashing means a website never keeps your actual password. Instead, it keeps a scrambled fingerprint of it that cannot be turned back into the original. When you sign in, the site scrambles what you typed the same way and checks whether the fingerprints match.
The scrambling is made slow on purpose. For you, waiting a fraction of a second is unnoticeable. For a thief who stole the database and wants to test millions of guesses, that small delay adds up to years of work. The key takeaway is that good hashing buys time, but a strong, unique password is still what makes guessing fail.
An example from practice
An online learning platform with 2 million user accounts discovered during a security audit that its legacy code stored passwords as unsalted SHA-1 hashes. Testing on a single modern GPU showed that a large share of the hashes could be cracked within hours using common password lists.
The engineering team adopted Argon2id with 64 MiB of memory and three iterations, which took about 200 milliseconds per login on their servers. Because they could not recover the original passwords, they wrapped each existing SHA-1 digest inside Argon2id immediately and replaced it with a direct Argon2id hash at each user’s next successful sign-in. Within six months most active accounts had migrated, and the cost of cracking each remaining hash rose by several orders of magnitude.