If you're storing passwords, you don't store passwords. You store a hash, and bcrypt is still one of the best-understood, hardest-to-mess-up ways to do that. It's been around since 1999, it's battle-tested, and it's available in pretty much every language you'll touch. For most applications, reaching for bcrypt is a boring, correct decision — which is exactly what you want from security code.

What bcrypt actually is

Bcrypt is a password-hashing function built on the Blowfish cipher. Unlike a plain cryptographic hash such as SHA-256, bcrypt is deliberately slow and includes a few features that make it suitable for passwords specifically:

  • Built-in salting. Every hash gets a random salt baked into the output, so identical passwords produce different hashes.
  • A tunable cost factor. You decide how expensive the hashing is. Crank it up as hardware gets faster.
  • A self-contained output. The salt, cost, and hash all live in one string, so you don't need a separate column for the salt.

A typical bcrypt hash looks like this:

$2b$12$R9h/cIPz0gi.URNNX3kh2OPST9/PgBkqquzi.Ss7KIUgO2t0jWMUW

Reading it left to right: $2b$ is the algorithm version, 12 is the cost factor, the next 22 characters are the salt, and the rest is the actual hash. Everything you need to verify a password later is in that single string.

Why slow is a feature

Fast hashes are great for checksums and terrible for passwords. If an attacker steals your database, they'll run offline brute-force or dictionary attacks against the hashes. With SHA-256, a GPU can try billions of guesses per second. Bcrypt's cost factor exists specifically to ruin that math.

The cost is an exponent. Cost 12 means 2^12 = 4,096 rounds of the internal key setup. Bump it to 13 and you double the work. You tune it so that a single hash takes something like 100–300ms on your production hardware — slow enough to make brute force painful, fast enough that your login endpoint stays responsive.

When to use it (and when not to)

Use bcrypt when you're hashing user passwords for storage and later verification. That's the sweet spot. It's a great default because it's everywhere and hard to misuse.

Don't use bcrypt for:

  • General-purpose hashing — file integrity, cache keys, deduplication. Use SHA-256 for that; it's meant to be fast.
  • Deriving encryption keys — look at a proper KDF like Argon2, scrypt, or PBKDF2 depending on your needs.

If you're starting a greenfield project and have Argon2id available, it's arguably the modern recommendation. But bcrypt remains a completely defensible choice, and if your stack already uses it, there's rarely a good reason to rip it out.

The gotchas that bite people

The 72-byte limit

Bcrypt only looks at the first 72 bytes of the input. Anything past that is silently ignored. This matters if you accept very long passwords or if you've chained bcrypt onto another hash. A common mitigation is to pre-hash the password with SHA-256 and base64-encode it before passing it to bcrypt — but be aware this introduces its own subtleties, so only do it if you understand why.

Null bytes

Some older bcrypt implementations truncate at the first null byte. This has been the source of real vulnerabilities. Use a maintained library and you'll be fine, but it's worth knowing the history.

Don't invent your own salt scheme

Bcrypt generates and stores the salt for you. You don't need a separate salt column, and you definitely shouldn't reuse a global salt. Let the library do its job.

Comparing hashes correctly

Always verify using your library's built-in compare function, not a plain string equality check. The compare function re-derives the hash using the stored salt and cost, which is the only correct way to check a password.

A worked example

Here's the whole lifecycle in Node.js using the bcrypt package. Hashing on signup, verifying on login.

const bcrypt = require('bcrypt');

const COST = 12;

// On signup
async function hashPassword(plain) {
  return bcrypt.hash(plain, COST);
}

// On login
async function verifyPassword(plain, storedHash) {
  return bcrypt.compare(plain, storedHash);
}

// Usage
const hash = await hashPassword('correct horse battery staple');
const ok = await verifyPassword('correct horse battery staple', hash);
console.log(ok); // true

Notice there's no manual salting, no concatenation, no second column. bcrypt.hash produces the self-contained string, and bcrypt.compare handles verification. The same pattern holds in Python (bcrypt), PHP (password_hash with PASSWORD_BCRYPT), Ruby, Go, and most other ecosystems.

When you want to eyeball what a hash looks like or test a value quickly without wiring up code, our Bcrypt Hash Generator lets you produce and inspect hashes in the browser — handy for debugging or sanity-checking your cost factor.

Upgrading cost over time

Hardware gets faster, so a cost factor that's comfortable today may be too cheap in a few years. The nice thing: because the cost is stored inside each hash, you can upgrade transparently. On a successful login, check whether the stored hash uses your current cost and re-hash if not.

async function verifyAndMaybeRehash(plain, storedHash) {
  const ok = await bcrypt.compare(plain, storedHash);
  if (!ok) return { ok: false };

  const needsRehash = bcrypt.getRounds(storedHash) < COST;
  const newHash = needsRehash ? await bcrypt.hash(plain, COST) : null;
  return { ok: true, newHash };
}

If newHash comes back non-null, persist it. Your users' credentials silently strengthen every time they log in, with zero disruption.

The short version

Bcrypt gives you salting, a tunable work factor, and a tidy self-contained output, all through a two-function API in every serious language. Pick a cost that takes a couple hundred milliseconds, use the library's hash and compare functions, mind the 72-byte limit, and plan to bump the cost as time goes on. Do that, and password storage stops being something you need to worry about.

Photo by FlyD on Unsplash