bcrypt - Time-Tested Password Hashing
About 2 min read
bcrypt is a password hashing function based on the Blowfish cipher, designed in 1999 by Niels Provos and David Mazières. Its defining feature is a design in which adjusting the cost factor (work factor) increases the computational cost exponentially, allowing the security strength to be raised in step with improvements in hardware performance. The OWASP Password Storage Cheat Sheet (as of October 2026) says bcrypt should only be used for legacy systems where Argon2 and scrypt are not available.
Historical Background
Before bcrypt appeared, Unix systems used the DES-based crypt function for password hashing. However, by the late 1990s the speedup of CPUs made the computational cost of crypt insufficient, and dictionary attacks and brute-force attacks had become realistic threats. As part of the OpenBSD project, Provos and Mazières designed bcrypt as an adaptive hash function intended to "remain secure even on future hardware."
How the Cost Factor Works
bcrypt's cost factor is specified as an integer from 4 to 31, and internally it performs 2-to-the-cost-power iterations. Increasing the cost factor by 1 roughly doubles the computation time.
| Cost factor | Iterations | Approximate processing time | Use case |
|---|---|---|---|
| 10 | 1,024 | About 100 ms | OWASP minimum |
| 12 | 4,096 | About 400 ms | Above the minimum |
| 14 | 16,384 | About 1.5 seconds | Beyond the one-second guideline |
The OWASP cheat sheet says the work factor should be as large as the performance of the verification server allows, and gives as a general rule that calculating a hash should take less than one second. The cost factor can be raised later as hardware becomes more powerful.
Automatic Salt Generation and Storage Format
bcrypt automatically generates a 128-bit salt and stores it together with the hash value as a single string. As a result, developers do not need to separately implement salt generation or management.
├ 12$ ... cost factor
├ LJ3m4ys3Lg7Ey6yGqV8sZe ... salt (22 characters)
└ KxYBCfGJZiNL5.mDHbgA7cWyPCkxbC6 ... hash value (31 characters)
Comparison with Argon2
One difference between bcrypt and Argon2 is whether they are memory-hard. bcrypt is a CPU-bound function and does not demand large amounts of memory for its computation. As a result, it offers less resistance than Argon2 against attacks that run hash computations in parallel on GPUs with thousands of cores. For new systems, Argon2id is the first choice. When migrating a system that already uses bcrypt, one approach is to re-hash on the next login. The overall design of password storage is explained in the secure password management guide.
Caveats of the 72-Byte Limit
Most bcrypt implementations have a limitation in that the input password is truncated at 72 bytes. In UTF-8 encoding, a single Japanese character consumes 3 bytes, so for a password consisting only of Japanese characters the effective upper limit is 24 characters. With a mix of alphanumeric characters, up to 72 characters are valid, but anything beyond that is ignored. To work around this limit, there is a technique of pre-hashing the password with SHA-256 before passing it to bcrypt, but it can be dangerous because of pitfalls such as the null-byte problem. OWASP calls for a password policy that enforces a maximum password length of 72 bytes or less.
Common Misconceptions
The perception that "bcrypt is old, so it is dangerous" is not accurate. What becomes a problem is when the cost factor is too low (below 10) or when an old implementation containing library bugs continues to be used. The historical evolution of password hashing is also introduced in the article on the history and culture of passwords. For the basics of cryptography, see the basics of encryption.
Was this article helpful?
Related Terms
- Password Hashing - Irreversible Storage for CredentialsPassword hashing transforms passwords into irreversible digests for storage. Combined with salting and stretching, it eliminates plaintext risk and resists offline cracking after a breach.
- Password Salting - Why Hashing Alone Falls ShortA salt adds unique random data to a password before hashing so identical passwords yield different digests. Learn how salting protects against rainbow table attacks.
- scrypt - Memory-Hard Key Derivationscrypt is a memory-hard password hashing function designed by Colin Percival in 2009 for Tarsnap. Its high memory requirement makes GPU and ASIC parallel attacks significantly harder.
- PBKDF2 - Password-Based Key DerivationPBKDF2 derives cryptographic keys from passwords and is standardized in NIST SP 800-132. Used in Wi-Fi WPA2, it lacks GPU resistance, so migration to Argon2 or bcrypt is recommended.