Bcrypt is a password-hashing function designed by Niels Provos and David Mazieres in 1999, based on the Blowfish cipher. It hashes each password with a unique random salt and a tunable cost factor that makes hashing deliberately slow, so stolen hashes are expensive to crack. OWASP now lists bcrypt only for legacy systems, with a work factor of 10 or more, and prefers Argon2id for new systems.
Key takeaways
- Bcrypt is deliberately slow and salted, which makes stolen password hashes expensive to crack by brute force.
- Use a work factor of at least 10, and 12 for most new deployments; each step up doubles the hashing time.
- For new systems OWASP prefers Argon2id; keep bcrypt only where it is already deployed, and respect its 72-byte limit.
If a database leaks, the passwords inside it should still be useless to the thief. That is the whole job of bcrypt: turn a password into a hash that takes real time and real money to guess, even with powerful hardware.
What is bcrypt?
Bcrypt is a password-hashing function designed by Niels Provos and David Mazieres in 1999, based on the Blowfish block cipher. It was built for one purpose: storing passwords safely.
Unlike general-purpose hashes such as MD5 or SHA-256, which are designed to be fast, bcrypt is deliberately slow. I
also generates a fresh random salt for every password, so two users with the same password get completely different hashes. OWASP states in its Password Storage Cheat Sheet that passwords should never be stored in plain text and must be protected with strong, slow hashing algorithms such as Argon2id, bcrypt or PBKDF2.
Bcrypt is not encryption. You cannot decrypt a bcrypt hash back into a password. When a user logs in, the system hashes the password they typed with the same salt and cost factor, then compares the result with the stored hash.
How does bcrypt work?
Bcrypt runs the Blowfish key schedule many times over, using the password and a random 128-bit salt as inputs. The number of repetitions is set by the cost factor, and the result is a 60-character hash string that stores everything needed to verify the password later.
The process has three ideas working together. First, the salt makes every hash unique, so an attacker cannot precompute one table of hashes and reuse it against every account. Second, the cost factor makes each guess expensive. Third, the output format is self-contained: the version, cost, salt and hash all travel together in one string.
A typical hash looks like this: $2b$12$LQv3c1yqBWVHxkd0LHAkCOYz6TtxMQJqhN8/LewKyJ.NfBu4nEqfa. The $2b$ part is the version, 12 is the cost factor, the next 22 characters are the salt, and the final 31 characters are the hash itself.
What does a bcrypt hash look like?
A bcrypt hash is a 60-character string in Modular Crypt Format, split into four parts by dollar signs. Reading it from left to right tells you the version, the cost factor, the salt and the digest.
| Part | Example | What it means |
|---|---|---|
| Version | $2b$ | Algorithm variant. $2b$ is the current standard; $2a$ is older, $2y$ is a PHP marker. |
| Cost factor | 12 | Work factor. The hash runs 2 to the power of 12, or 4,096, rounds. |
| Salt | 22 characters | 128 bits of random data, encoded in bcrypt's own Base64 alphabet. |
| Digest | 31 characters | The resulting hash, 23 of the 24 computed bytes. |
Because the salt and cost are stored inside the string, verification needs nothing else. A system that receives a login attempt can read the cost and salt straight from the stored hash, hash the typed password the same way, and compare.
What cost factor should you use?
Use a work factor of at least 10, and 12 for most new deployments of existing bcrypt systems. Each increase of one doubles the hashing time, so the choice is a balance between security and login speed.
OWASP says in the same cheat sheet that the bcrypt work factor should be as large as verification server performance will allow, with a minimum of 10. It also says that, as a general rule, calculating a hash should take less than one second. Many teams aim for roughly 250 milliseconds per login on their production hardware and then pick the highest cost that stays near that target.
| Cost factor | Rounds (2 to the power of cost) | Rough time on a modern CPU core | When it fits |
|---|---|---|---|
| 10 | 1,024 | About 60 to 100 ms | OWASP minimum; older default |
| 11 | 2,048 | About 120 to 130 ms | A step up from the old default |
| 12 | 4,096 | About 250 to 400 ms | Sensible baseline for most systems today |
| 13 | 8,192 | About 500 ms | Higher-security logins |
| 14 | 16,384 | About 1 second | Admin or low-volume logins only |
Exact times depend on hardware, but the doubling holds everywhere. Benchmark on your own servers, not on a laptop, and recheck every couple of years: as hardware gets faster, a cost that took 250 milliseconds today will take less tomorrow. When you raise the cost, re-hash each password at the user's next login, which is the standard upgrade path OWASP describes.
Why does bcrypt use a salt?
A salt stops attackers from precomputing hashes once and reusing them against every account. Bcrypt generates a fresh 128-bit random salt for every password, so identical passwords produce different hashes.
Without a salt, an attacker could build a rainbow table: a huge precomputed list of common passwords and their hashes. With a unique salt per user, that table is useless, because the attacker must crack each hash one at a time, using that user's salt. OWASP makes the same point: salting means the time required grows in direct proportion to the number of hashes.
Salting also hides whether two users chose the same password. You cannot tell from the stored hashes alone, because the salts differ. The salt is not secret, and it does not need to be stored separately; it is embedded in the hash string itself.
Bcrypt vs SHA-256 vs MD5: what is the difference?
MD5 and SHA-256 are general-purpose hash functions designed to be fast, which is exactly what makes them wrong for passwords. Bcrypt is designed to be slow, salted and tunable, which is what password storage needs.
A fast hash lets an attacker test billions of guesses per second on modern GPU hardware. A slow hash forces the attacker to spend real time and money on every single guess. That difference is the whole point: a login happens once per user, but cracking a leaked database means guessing millions of passwords.
| Property | MD5 / SHA-256 | Bcrypt | Argon2id |
|---|---|---|---|
| Designed for | Checksums, file integrity | Password storage | Password storage |
| Speed | Very fast | Deliberately slow | Deliberately slow |
| Salt | Not built in | Built in, 128-bit | Built in |
| Tunable cost | No | Yes, cost factor | Yes, memory, time, parallelism |
| Memory-hard | No | No | Yes |
| OWASP view | Not suitable for passwords | Legacy systems only | First choice for new systems |
Never store passwords with plain MD5, SHA-1 or SHA-256, even with a salt added by hand. Use a dedicated password-hashing function, and let a well-tested library handle the salt and parameters for you.
Is bcrypt still secure, or should you use Argon2id?
Bcrypt is still secure when configured correctly, but OWASP now prefers Argon2id for new systems. Argon2id adds memory-hardness, which forces attackers to use large amounts of RAM as well as compute time, making GPU cracking far more expensive.
OWASP's current summary is clear: use Argon2id with a minimum of 19 MiB of memory, 2 iterations and 1 degree of parallelism. If Argon2id is not available, use scrypt with a cost parameter of 2 to the power of 17, a block size of 8 and parallelism of 1.
For legacy systems using bcrypt, use a work factor of 10 or more, with a password limit of 72 bytes. If FIPS-140 compliance is required, use PBKDF2 with 600,000 or more iterations and HMAC-SHA-256.
That summary is the current OWASP position, and it is worth reading in full before you implement it.
That does not mean you must rip bcrypt out of a working system tomorrow. If your application already uses bcrypt at cost 12, it is in reasonable shape. Plan a migration instead: support Argon2id for new and changed passwords, and re-hash existing bcrypt passwords to Argon2id when each user next logs in.
What are bcrypt's limitations?
Bcrypt has three limits worth knowing before you rely on it: a 72-byte input cap, no memory-hardness, and a fixed 4 KB internal state. None of them makes bcrypt broken, but each shapes how you should use it.
First, most bcrypt implementations only read the first 72 bytes of a password. Anything longer is silently ignored, so two long passwords that share the first 72 bytes would hash the same way. OWASP advises enforcing a maximum password length of 72 bytes, or less if your library has a smaller limit.
Second, bcrypt is not memory-hard. An attacker with GPUs can run many bcrypt guesses in parallel, because each guess needs little memory. Argon2id was designed to close exactly that gap. Third, bcrypt's output is fixed at 60 characters, and its algorithm cannot be tuned for memory, only for time.
Pre-hashing a long password with SHA-256 before bcrypt sounds like a workaround, but OWASP warns it is dangerous if done naively, because of null bytes and a flaw called password shucking. If you must pre-hash, OWASP says to use HMAC-SHA-384 keyed with a pepper and base64-encode the output. The simpler fix is to choose Argon2id for new systems.
How do you use bcrypt in practice?
Use a well-tested library in your language, never write your own bcrypt implementation. You can experiment with hash output safely using our hash generator. In most frameworks the code is only a few lines: hash on registration and password change, verify on login, and re-hash when the cost rises.
On registration, generate the hash with your chosen cost and store the full 60-character string in the password column. Never store the plain password, and never store the salt in a separate column, because it is already inside the hash.
On login, pass the typed password and the stored hash to your library's verify function; it extracts the salt and cost, hashes the typed password, and compares the results in constant time.
Keep three rules. First, generate salts with a cryptographic random source, which good libraries do for you. Second, never cap the cost at the library default without checking it; defaults from years ago are often cost 10, and 12 is a better starting point today.
Third, add a pepper only if you can store it separately, in a secrets vault or hardware module, because a pepper stored next to the database adds little.
For users, bcrypt is invisible, which is how it should be. If you want to check whether a password you use has already appeared in a breach, try our pwned password checker to see if it has appeared in a known breach.
What mistakes do teams make with bcrypt?
The most common mistakes are using a fast hash instead of bcrypt, using too low a cost, and rolling a custom scheme. Each one quietly removes the protection bcrypt is supposed to provide.
- Hashing with MD5 or SHA-256 alone. Fast hashes fall to GPU cracking in hours, not years.
- Using one salt for every user. A shared salt lets an attacker crack all identical passwords at once.
- Leaving the cost at 4 or 5. Low costs are for tests only; production needs 10 or more.
- Storing passwords encrypted instead of hashed. Encryption is reversible, so a stolen key exposes every password.
- Writing your own password hashing. Small errors in salt generation or comparison leak badly; use a maintained library.
- Forgetting the 72-byte limit. Long passphrases can be truncated without warning.
A related mistake is treating hashing as a substitute for everything else. Bcrypt protects a leaked database, but it does not stop phishing, credential stuffing with passwords reused from other breaches, or weak passwords such as "password1!". Pair it with strong password rules, breach checks and multi-factor authentication.
The bottom line
Bcrypt is a proven, deliberately slow, salted password hash that has protected logins since 1999. At cost 12, with a unique salt per password, it still makes stolen hashes expensive to crack.
For new systems, follow OWASP and choose Argon2id; for existing systems, keep bcrypt, raise the cost to at least 10 and preferably 12, respect the 72-byte limit, and re-hash on login as hardware improves. Check your own password habits with the password strength checker while you are at it.
Frequently asked questions
What is bcrypt in simple terms?
Bcrypt is a password-hashing function that turns a password into a slow, salted hash that is expensive for an attacker to crack. It was designed in 1999 by Niels Provos and David Mazieres, based on the Blowfish cipher.
What cost factor should I use for bcrypt?
Use a work factor of at least 10, and 12 for most systems today. Each increase of one doubles the hashing time, so benchmark on your own server and pick the highest cost that keeps logins under about one second.
Is bcrypt still secure in 2026?
Yes, when configured correctly at cost 10 or more. OWASP now prefers Argon2id for new systems because it is memory-hard, and lists bcrypt only for legacy systems, but a bcrypt hash at cost 12 is still expensive to crack.
What is the 72-byte limit in bcrypt?
Most bcrypt implementations only read the first 72 bytes of a password, and anything longer is silently ignored. OWASP advises enforcing a maximum password length of 72 bytes, or less if your library has a smaller limit.
What does a bcrypt hash look like?
A bcrypt hash is a 60-character string such as $2b$12$..., where 2b is the version, 12 is the cost factor, the next 22 characters are the salt, and the final 31 characters are the hash itself.
Is bcrypt better than SHA-256 for passwords?
Yes, for password storage. SHA-256 is a fast general-purpose hash, so an attacker can test billions of guesses per second. Bcrypt is deliberately slow and salted, which makes each guess expensive.
Sources
The engineers and analysts who build Cysoro's domain scanner, email-authentication checks and free security tools. We test what we write about every day — SPF, DKIM, DMARC, certificates, look-alike domains and phishing — and check each guide against the relevant standards, government guidance and vendor documentation.
Checked against the OWASP Password Storage Cheat Sheet, NIST SP 800-63B and the original Provos and Mazieres bcrypt paper.
How we write and fact-check →