Cryptography

Bcrypt Explained: How It Works and Why It's Still the Standard

9 min read
By
Bcrypt Explained: How It Works and Why It's Still the Standard

Photo by Pixabay from Pexels

If you have ever created an account on a website, your password was almost certainly run through something called bcrypt. You probably never noticed. But behind the scenes, bcrypt has been quietly protecting billions of passwords for over two decades.

Let's break down what bcrypt actually is, how it works, and why it is still the standard for password hashing in 2026.

What Is Bcrypt, Really?

Bcrypt is a password hashing function designed by Niels Provos and David Mazières in 1999. The name comes from "Blowfish crypt" because it is based on the Blowfish cipher's key scheduling algorithm.

Here is the key insight that makes bcrypt different from something like SHA-256: bcrypt is deliberately slow.

A general-purpose hash function like SHA-256 is designed to be as fast as possible. That is great for verifying file integrity or building blockchain systems. It is terrible for passwords. When an attacker steals a database of SHA-256 password hashes, they can try billions of password guesses per second on a modern GPU. A weak password like "summer2026" would be cracked in milliseconds.

Bcrypt flips this on its head. It is designed to take a meaningful amount of time per hash, somewhere in the range of 100 to 400 milliseconds on modern hardware. That feels instant to a legitimate user logging in. But to an attacker trying billions of guesses, it is agonizingly slow.

The $2b$ Format: Anatomy of a Bcrypt Hash

Here is what a bcrypt hash actually looks like:

$2b$12$N9qo8uLOickgx2ZMRZoMyeIjZAgcfl7p92ldGxad68LJZdL17lhWy

That string looks like gibberish, but it is actually four pieces of information packed together. Let's break it down.

**$2b$** — This is the version prefix. Bcrypt has gone through a few versions. The original was $2$, then $2a$ fixed an issue with handling long passwords, and $2b$ fixed a minor integer overflow bug. In practice, $2a$ and $2b$ produce identical results for passwords under 72 bytes, which is almost all of them. If you see $2a$ in an existing database, it is fine. If you are starting fresh, use $2b$.

**12** — This is the cost factor. It determines how many iterations of the key scheduling algorithm run. The number is an exponent: the algorithm runs 2^12 (4,096) iterations. Change this number to 13 and you double the work. Change it to 14 and you double it again. This is bcrypt's superpower, and we will dig into it in our bcrypt cost factor guide.

**N9qo8uLOickgx2ZMRZoMyeI** — This is the 22-character salt. It is 16 bytes of random data encoded in a base64-like scheme. The salt ensures that even if two users pick the same password, their hashes will be completely different. We cover this in depth in our post on bcrypt salts.

**IjZAgcfl7p92ldGxad68LJZdL17lhWy** — This is the actual 31-character hash output. It is a 23-byte (184-bit) hash derived from the password, salt, and cost factor.

The brilliant thing about this format is that the salt and cost factor are embedded in the hash string itself. You store one string per user. When someone logs in, bcrypt reads the cost factor and salt from the stored hash, re-hashes the submitted password with those same parameters, and checks if the output matches. You never have to manage a separate salt column.

Why Bcrypt Is Adaptive (and Why That Matters)

The single most important feature of bcrypt is that it is adaptive. The cost factor lets you make hashing slower over time as hardware gets faster.

In 1999, a cost factor of 6 was considered reasonable. That meant 2^6 = 64 iterations, which took a noticeable amount of time on the hardware of the day. Today, a cost factor of 6 would be trivially fast for an attacker with a modern GPU. But you can bump it to 12 or 13 and bcrypt is right back to being painful to attack.

This is not a theoretical advantage. It is a practical one. When you choose SHA-256 for password hashing, you are making a one-time bet on the speed of hardware. When you choose bcrypt, you are making a renewable bet. Every time hardware gets faster, you bump the cost factor and you are secure again. No algorithm change, no data migration, just a configuration update.

Bcrypt vs SHA-256: A Practical Comparison

Let's say you are building an app and deciding between bcrypt and SHA-256 for password storage. Here is what the numbers look like on a single modern GPU:

- **SHA-256**: roughly 2.5 billion hashes per second - **Bcrypt (cost 12)**: roughly 2 to 3 hashes per second

If an attacker steals your database and wants to try the top 10,000 most common passwords against every hash:

- **SHA-256**: 10,000 guesses × 1 million users = 10 billion hashes. At 2.5 billion per second, that takes about 4 seconds. Every weak password in your database is cracked before you finish your coffee. - **Bcrypt (cost 12)**: 10,000 guesses × 1 million users = 10 billion hashes. At 3 per second, that takes about 105 years. The attacker will move on to an easier target.

That difference is not incremental. It is the difference between "every weak password is compromised" and "the attack is not worth attempting."

Why Salt Prevents Rainbow Tables

A rainbow table is a precomputed list of hashes for common passwords. An attacker generates a massive table of "password → hash" pairs once, then uses it to crack any database instantly by looking up the hashes.

Bcrypt's built-in salt makes rainbow tables useless. Because every password is hashed with a unique random salt, the same password produces a different hash every time. An attacker would need to build a separate rainbow table for every possible salt, which is computationally infeasible.

Even better, bcrypt handles the salt for you. The salt is generated automatically and embedded in the hash string. You do not need to write any salt management code. For a deeper dive, read our explanation of what a salt is and why bcrypt needs one.

When Bcrypt Is Not the Right Choice

Bcrypt is not perfect. Its main limitation is the 72-byte password limit. Bcrypt only processes the first 72 bytes of any password. If someone uses a 100-character passphrase, bcrypt silently ignores everything past byte 72. This is rarely a problem in practice, but it is worth understanding. We cover this in detail in our post on the bcrypt 72-byte limit.

The other consideration is that bcrypt is CPU-hard but not memory-hard. Newer algorithms like Argon2id require significant memory in addition to CPU time, which makes them more resistant to specialized hardware attacks. For most applications, bcrypt is still more than adequate. But if you are building something with particularly high security requirements, you should compare your options in our bcrypt vs Argon2 vs scrypt breakdown.

The Bottom Line

Bcrypt is not the newest password hashing algorithm. It is not the fanciest. But it is the most battle-tested. It has been protecting passwords for over 25 years, it is supported by virtually every programming language and framework, and its adaptive cost factor means it can keep up with hardware improvements.

If you are building a new application today, bcrypt with a cost factor of 12 is a solid, defensible choice. If you are maintaining an older application that uses MD5 or SHA-1, you should plan a migration. We walk through how to do that without resetting everyone's passwords in our migration guide.

Want to see bcrypt in action? Try our bcrypt generator to hash passwords with different cost factors and see the output in real time.

Frequently Asked Questions

What does a bcrypt hash look like?

A bcrypt hash is a single string that starts with $2b$, followed by a cost factor, a 22-character salt, and a 31-character hash. For example: $2b$12$someSaltCharactersHere...hashValue. The entire string is self-contained, meaning the salt and cost factor are embedded in the hash itself.

Is bcrypt still secure in 2026?

Yes, bcrypt remains secure when used with a cost factor of 10 or higher. While newer algorithms like Argon2id offer advantages (particularly memory hardness), bcrypt is battle-tested, widely supported, and resistant to GPU attacks when properly configured. It remains recommended by OWASP alongside Argon2id and scrypt.

What is the difference between bcrypt and SHA-256?

SHA-256 is a general-purpose hash function designed to be fast. Bcrypt is a password hashing function deliberately designed to be slow. SHA-256 can compute billions of hashes per second on a GPU, making it trivial to crack passwords. Bcrypt with a cost factor of 12 takes roughly 0.4 seconds per hash, making brute-force attacks impractical.

Why does bcrypt include the salt in the hash string?

Embedding the salt directly in the hash string means you only need to store one value per user. When verifying a password, bcrypt extracts the salt and cost factor from the stored hash, re-hashes the input password with those same parameters, and compares the result. This eliminates the need to manage a separate salt column in your database.

Try NovelCrypt Tools

Experience military-grade encryption for your sensitive data. Create self-destructing messages, encrypt files, or explore our experimental lab tools.

Explore NovelCrypt