How bcrypt Works — Salting, Cost Factor & Why It's Slow on Purpose
bcrypt is a password-hashing function designed to be deliberately slow so that stolen password hashes are expensive to crack. It builds in a per-password salt (stopping rainbow tables) and a tunable cost factor you raise as hardware gets faster. This guide explains the anatomy of a bcrypt hash, why slowness is a feature, and how to choose a cost factor.
Last updated:
Core Concepts
- Why a password hash should be slow
- General-purpose hashes like SHA-256 are built to be fast — billions per second on a GPU — which is exactly wrong for passwords, because an attacker who steals your hash database can try billions of guesses per second too. bcrypt is an adaptive hash: it's deliberately slow (milliseconds per hash), so a login is barely affected but brute-forcing a stolen database becomes economically infeasible. 'Fast' is a feature for checksums and a vulnerability for passwords.
- Salt — defeating rainbow tables
- A salt is a random value mixed into each password before hashing, and bcrypt generates and stores a unique salt per password automatically. Because every user's salt differs, two users with the same password get different hashes, and precomputed 'rainbow table' attacks become useless — an attacker would have to build a separate table per salt. The salt isn't secret; it's stored inside the hash string itself.
- The cost factor (work factor)
- bcrypt's cost factor (e.g. 10, 12) is a power-of-two number of iterations: each increment doubles the work. You raise it over the years as hardware gets faster, keeping cracking expensive without changing your code. A cost of 10–12 is a common balance in 2026 — high enough to resist offline attacks, low enough that verifying a login stays fast. Benchmark on your hardware and target ~50–250 ms per hash.
- Anatomy of a bcrypt hash
- A bcrypt hash looks like `$2b$12$R9h/...22-char-salt...hash`. The parts are: the algorithm identifier (`$2b$`), the cost factor (`12$`), then a 22-character Base64 salt immediately followed by the 31-character hash — all in one self-describing string. Because the algorithm, cost, and salt travel with the hash, verification needs only the stored hash and the candidate password. This is also exactly the format Apache's `htpasswd -B` writes.
Frequently Asked Questions
Is bcrypt still secure in 2026?
Yes, bcrypt remains a solid, widely-recommended password hash. Its salting and tunable cost factor keep it effective — just raise the cost factor as hardware improves. Newer memory-hard functions like Argon2 and scrypt add resistance to GPU/ASIC attacks and are preferred for new systems that can use them, but bcrypt is a perfectly acceptable, battle-tested choice.
What cost factor should I use for bcrypt?
Pick the highest cost your login latency can tolerate — commonly 10 to 12 in 2026. Benchmark on your production hardware aiming for roughly 50–250 ms per hash. Too low is weak against offline cracking; too high adds noticeable login delay and lets attackers tie up your server.
Why do two hashes of the same password look different?
Because bcrypt adds a unique random salt to each one. The salt is stored inside the hash string, so verification still works, but it means identical passwords produce different hashes — which is exactly what defeats rainbow-table attacks.
Try these related tools
Bcrypt Generator →
Generate and verify bcrypt password hashes online. Configurable cost factor (4–15), shows computation time so you can pick a cost matching your server hardware. Parses and displays hash version and cost from any pasted hash. 100% local — passwords never leave your browser.
htpasswd Generator →
Generate .htpasswd entries for Apache and Nginx HTTP Basic Authentication. Enter a username and password to get a bcrypt-hashed user:hash line, ready to paste into your htpasswd file. 100% local — the password never leaves your browser.
Hash Generator →
Generate MD5, SHA-1, SHA-256, and SHA-512 hashes of any text online. Free, no signup — all hashing runs entirely in your browser via the Web Crypto API, so nothing is uploaded.
Password Strength →
Analyze password strength free in your browser: entropy in bits, estimated crack time under four attack scenarios (online throttled/unthrottled, offline GPU fast hash, offline bcrypt slow hash), and structural findings (dictionary words, keyboard sequences, repeated patterns). Optional k-anonymous Have I Been Pwned check — no signup, your password never leaves the tab.
SHA-256 Generator →
Compute SHA-256 (256-bit) hashes of text or files instantly online. The gold-standard cryptographic hash for signatures, blockchain, and integrity. Drag-and-drop file support; verify against a known SHA-256 in one click. 100% local.