Should password hashing be fast or slow? bcrypt, salt and pepper explained
Updated 24 October 2026 · 7 min read
bcryptargon2password hashingsaltpeppersecuritydeveloper
Almost everything in software is better when it is faster. Password hashing is the rare exception: the slower it is, within limits, the safer your users are. A quick hash is a gift to an attacker, and a deliberately slow one is the reason a stolen database does not automatically become a pile of stolen passwords.
This guide explains why, then walks through the parts. It covers how bcrypt keeps a password and checks it later, what a salt and a pepper each add, how slow is slow enough, and what an attacker actually faces if your database leaks. You can follow along with the Password Hash Generator, which shows the time every hash takes on your own device.
First, hashing is not encryption
Encryption can be undone with a key. A hash cannot be undone at all: it turns a password into a fixed-length string, and there is no key that turns that string back. Sites store the hash, not the password, so even the developers cannot read a user’s password.
When you log in, the site hashes what you typed and compares it with the stored hash. If they match, the password was right. That is the whole mechanism, and it is also the whole weakness: an attacker who steals the stored hashes cannot reverse them, but can guess passwords, hash each guess and look for a match. Everything below is about making each guess expensive.
Why a fast hash is a weak lock
SHA-256 and MD5 were designed to be fast, because they checksum files and sign data. That speed is exactly wrong for passwords. A single high-end graphics card can compute tens of billions of SHA-256 hashes per second, and that is before renting more cards.
Take an eight-letter, lowercase-only password, which has 26 to the power of 8 possibilities, or 208,827,064,576 in all. At about 20 billion guesses a second, a fast hash gives up every one of them in roughly ten seconds. The same card against bcrypt at cost 12 manages around a thousand or so guesses a second in published benchmarks, which stretches that same search to years. The password is identical; only the hash changed.
These are rough figures, and real attackers try likely passwords first instead of every combination. The shape of the result is what matters: the hash’s speed sets the price of each guess, and a slow hash multiplies that price by millions.
Slow for them, fast enough for you
The trick works because of an asymmetry. A real user triggers one hash per login, so a delay of a quarter of a second is invisible. An attacker needs billions of hashes, so the same delay is a wall.
The usual aim is about 100 milliseconds to 1 second per hash on the server that will run it. Much below 100 ms and you are leaving protection on the table; much above a second and logins feel sluggish and a burst of sign-ins can swamp the server. Measure on your own production hardware, not a laptop, and pick the strongest setting that stays inside that band.
Hardware keeps getting faster, so the setting is not permanent. Review it every year or two, and raise it when hashing starts finishing in well under 100 ms. Each stored hash records its own cost, so old accounts keep working and can be upgraded the next time the user logs in.
How bcrypt stores a password
bcrypt is the long-standing choice, and its output shows the whole design in one 60-character string. Take $2a$10$/uaF/uaF/uaF/uaF/uaF/uD0e/sucR/PGZJ9O7QyMSDHiIBe57XtS, the hash of correct horse battery staple that the generator uses as its sample:
$2a$is the version of the bcrypt format.10$is the cost. It is an exponent, so cost 10 means 2 to the power of 10, or 1,024 rounds. Every +1 doubles the work, so cost 12 takes four times as long as cost 10.- The next 22 characters are the salt, stored in plain sight.
- The remaining 31 characters are the hash itself.
Because the version, cost and salt all travel inside the string, the database needs a single column. Nothing else has to be remembered to check a password later.
One limit is worth knowing: bcrypt reads only the first 72 bytes of the password and silently ignores the rest. Non-English characters take several bytes each, so the limit can arrive sooner than 72 characters. The pepper step below sidesteps it.
How bcrypt checks a password later
At login, the server fetches the stored hash and does four things:
- It reads the cost and salt out of the stored string.
- It hashes the password the user just typed using that same salt and cost.
- It compares the new hash with the stored one, using a constant-time comparison so the time taken does not leak how many characters matched.
- If they are equal, the password is correct. The original password is never recovered, and nothing was decrypted.
This is why checking costs about as much as creating, and why the Check a password tab in the generator reports a similar time to the Generate tab. A library call such as bcrypt.compare or password_verify does all four steps for you.
What a salt is and why every password needs one
A salt is a random value, unique to each password, mixed in before hashing. bcrypt generates one for you and stores it in the hash, as the 22 characters above. Salts are not secret, and they do not need to be.
They fix two problems. Without salts, two users with the same password get the same hash, so cracking one reveals both, and a single glance at the database shows who reuses passwords. And without salts an attacker can use rainbow tables, giant precomputed lists of hash-to-password pairs, to look hashes up instead of computing them. With a unique salt on each account, every hash must be attacked separately, from scratch.
You can see this in the generator: hash the same password twice and you get two different strings, yet both verify.
What a pepper adds
A pepper is also an extra input to the hash, but it differs from a salt in two ways. It is one secret shared by every password, and it is stored outside the database, for example in an environment variable or a secrets manager.
The point is a split of risk. Many leaks expose only the database, through an injected query or a stolen backup. If the pepper is not in there, the attacker holds hashes they cannot even begin to test, because every guess needs a secret they do not have.
A common way to apply one with bcrypt is to compute an HMAC-SHA256 of the password using the pepper as the key, then bcrypt the Base64 of that result. As a bonus the output is always 44 characters, so the 72-byte limit never applies. Argon2 accepts a pepper directly as its built-in secret. The cost is operational: if you ever change the pepper, existing hashes stop matching, so plan for rotation (for example by storing a pepper version beside each hash) before you need it.
Argon2id, the newer option
bcrypt makes guessing slow. Argon2id makes it slow and memory-hungry, and that second part is what hurts attackers. A graphics card has thousands of cores but little memory per core, so demanding tens of megabytes for every guess removes most of its advantage.
Argon2 has three settings: memory, passes over that memory and lanes of parallelism. OWASP’s minimum is 19 MiB, 2 passes and 1 lane, with 46 MiB, 1 pass and 1 lane as an alternative. As with bcrypt, tune it until one hash takes roughly 100 ms to 1 second on your server. For new projects Argon2id is the usual recommendation; bcrypt at cost 10 or higher is still sound if your stack already uses it.
If the database leaks, what stops the attacker?
Each layer removes something the attacker would like to have:
- Hashing means the passwords are not stored, so there is nothing to read.
- A slow hash makes every guess cost real time, which defeats brute force.
- A unique salt makes every account a separate puzzle and rules out lookup tables.
- A pepper keeps a database-only leak from being testable at all.
- Long, unique passwords put the correct guess outside the part of the search an attacker can afford to try.
No single layer is enough, and none of them rescues a password like 123456 that an attacker tries in the first second. Slow hashing buys time and raises the cost; it works together with strong passwords and breach alerts.
Mistakes to avoid
- Storing a plain SHA-256 or MD5 of the password. Fast hashes are the problem described above.
- Inventing your own scheme, such as hashing twice or mixing in the username. Use a maintained library and its defaults.
- Setting the cost once and never revisiting it as hardware improves.
- Truncating or trimming passwords by accident, including the 72-byte bcrypt cutoff.
- Comparing hashes with
==instead of the library’s constant-time check. - Logging passwords or request bodies, which makes every other protection pointless.
Frequently asked questions
Should password hashing be fast or slow?
Slow, within limits. A hash that takes about 100 ms to 1 second is invisible to a user logging in once, but multiplies the cost for an attacker who needs billions of guesses.
Is bcrypt still safe to use?
Yes, at cost 10 or higher, as long as passwords stay within its 72-byte limit. Argon2id is the usual choice for new systems, but bcrypt has no known practical weakness.
Do I need both a salt and a pepper?
You always need a salt, and good libraries add one automatically. A pepper is an optional extra layer that helps when the database leaks without your application secrets.
Why can I not just encrypt passwords instead?
Encrypted passwords can be decrypted by anyone who gets the key, and the key tends to be stored near the data. A hash cannot be reversed, so there is nothing to decrypt even if the whole system is taken.
How do I raise the cost on existing users?
When a user logs in successfully, you hold the real password for a moment. If their stored hash has a lower cost than your current setting, hash it again with the new cost and save the result.