0Pricing
Cryptology Academy · Lesson

bcrypt: Algorithm & Cost Factor

Learn bcrypt internals, the work factor, and proper cost tuning.

bcrypt: Algorithm & Cost Factor is a free Cryptology Academy lesson on CoddyKit — lesson 2 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Cryptology Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

Welcome

bcrypt is a password hashing algorithm designed in 1999 specifically to be slow and resistant to hardware attacks. It remains the most widely deployed password hashing algorithm.

bcrypt Origins

Designed by Niels Provos and David Mazières, based on the Blowfish cipher. The 'b' stands for Blowfish. Its key insight: use Blowfish's expensive key setup for intentional slowness.

bcrypt Hash Format

$2b$12$saltsaltsaltsaltsaltsalthashhashhashhashhashhashhash $2b$: algorithm version 12: cost factor (log2 of iterations) salt: 22 base64 characters (16 bytes) hash: 31 base64 characters (24 bytes)

Cost Factor

Cost 12 = 2^12 = 4096 iterations. Cost 13 = 8192 iterations. Each increment doubles computation time. Tune so hashing takes ~100-300ms on your hardware. Attacker's speed scales identically.

bcrypt in Python

import bcrypt password = b'my_password' salt = bcrypt.gensalt(rounds=12) # generates random salt hashed = bcrypt.hashpw(password, salt) # Verify: bcrypt.checkpw(password, hashed) # True

Built-in Salt

bcrypt always generates and stores the salt automatically. gensalt() produces a cryptographically random 16-byte salt. You never need to manage salt separately — it's embedded in the hash string.

bcrypt 72-Character Limit

bcrypt truncates input at 72 bytes. Passwords longer than 72 characters are treated as identical after the first 72 bytes. Workaround: pre-hash with SHA-512 before bcrypt (but validate approach).

Password Verification Flow

Login: 1. User submits password 2. Retrieve stored hash from DB 3. bcrypt.checkpw(submitted, stored_hash) 4. checkpw extracts salt from stored hash and recomputes 5. Returns True/False Never store the raw password.

Benchmarks

bcrypt cost 12: - Consumer CPU: ~150ms per hash - GPU (RTX 4090): ~50,000 hashes/sec (vs 10B for SHA-256) Attacker advantage reduced from 1 billion to ~300 with bcrypt cost 12.

Cost Factor Recommendations

OWASP 2024: bcrypt cost factor ≥ 10. Recommended: 12. Check annually — as hardware improves, increase the factor. Implement online re-hashing: on login, check and upgrade if needed.

bcrypt Limitations

bcrypt weakness: not memory-hard. Attackers can use custom ASICs optimized for bcrypt. For new applications, prefer Argon2id which is memory-hard and ASIC-resistant.

Quick Check

What does the cost factor 12 mean in a bcrypt hash?

Recap

bcrypt is solid but not memory-hard. Next we study Argon2 — the modern champion of password hashing with configurable memory requirements.

Frequently asked questions

Is the “bcrypt: Algorithm & Cost Factor” lesson free?

Yes — the full text of “bcrypt: Algorithm & Cost Factor” is free to read here on the web, and the Cryptology Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Cryptology Academy course, upgrade to CoddyKit PRO.

What will I learn in “bcrypt: Algorithm & Cost Factor”?

Learn bcrypt internals, the work factor, and proper cost tuning. You practise Cryptology Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Cryptology Academy?

No prior experience is required. Cryptology Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 2 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “bcrypt: Algorithm & Cost Factor” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Cryptology Academy lesson?

Yes. Every Cryptology Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Why Plain SHA-256 Fails for Passwords
  2. bcrypt: Algorithm & Cost Factor
  3. Argon2: Memory-Hard Password Hashing
  4. PBKDF2 & Choosing the Right Algorithm
← Back to Cryptology Academy