Choosing the Right Bcrypt Cost Factor in 2026

Bcrypt is one of the most trusted ways to store passwords, and its secret weapon is the cost factor (also called work factor or rounds). Choosing it well is the difference between a database that resists cracking and one that falls quickly. Here is how to choose it in 2026.

What the cost factor does

In a bcrypt hash like $2y$12$..., the 12 is the cost. Bcrypt runs its expensive key setup 2cost times, so:

  • Cost 10 = 1,024 iterations
  • Cost 12 = 4,096 iterations (4× slower than 10)
  • Cost 14 = 16,384 iterations (16× slower than 10)

Each +1 doubles the time to compute one hash. That barely matters for a user logging in once, but it doubles the cost for an attacker trying billions of guesses.

The right target: about 250 ms per hash

A practical rule is to choose the highest cost that keeps hashing under about 250 milliseconds on your production server. Login stays fast for users, and attackers are slowed by thousands of times compared with fast hashes like MD5 or SHA-256.

  • 10: PHP’s long-time default. Acceptable, but on the low side for new projects.
  • 12: a good default for most web apps today. PHP 8.4 raised its default to 12.
  • 13–14: for high-value systems with fast servers and few logins per second.

How to measure on your server

Time a hash at different costs on the real production hardware. In PHP:

foreach ([10, 11, 12, 13] as $cost) {
    $t = microtime(true);
    password_hash('test', PASSWORD_BCRYPT, ['cost' => $cost]);
    printf("cost %d: %.0f ms\n", $cost, (microtime(true) - $t) * 1000);
}

Pick the highest value under your target. Try it in the browser with our Bcrypt Generator: you will feel each step take twice as long.

Upgrading existing hashes

You don’t need to force a password reset to raise the cost. On each successful login, check whether the stored hash needs updating and rehash it:

if (password_verify($password, $hash) && password_needs_rehash($hash, PASSWORD_BCRYPT, ['cost' => 12])) {
    $hash = password_hash($password, PASSWORD_BCRYPT, ['cost' => 12]);
    // save $hash
}

Bcrypt limits to know

  • 72-byte limit: bcrypt ignores anything after 72 bytes. Long passphrases with non-English characters can exceed it. Some systems (including WordPress 6.8+) pre-hash the password with HMAC-SHA384 to avoid this.
  • Don’t go too high: a huge cost can let attackers overload your login page. Combine it with rate limiting.
  • Consider Argon2id for brand-new systems where it is available. It is memory-hard and recommended by OWASP. Bcrypt remains a solid, widely supported choice.

Quick checklist

  1. Use cost 12 as a baseline, then measure.
  2. Target 100–250 ms per hash on production hardware.
  3. Rehash on login when you raise the cost.
  4. Rate-limit login attempts.
  5. Test hashes with the Bcrypt Checker during development.
Menu