How Bcrypt Works

Bcrypt is a password-hashing function designed by Niels Provos and David Mazières in 1999. Decades later, it remains one of the absolute best ways to securely store user passwords in a database.

Hashing vs Encryption

First, it's important to understand that Bcrypt is a hash, not an encryption algorithm. Encryption is a two-way street; you can decrypt data if you have the key. Hashing is a one-way street. Once a password is hashed with Bcrypt, it is mathematically impossible to reverse it back into the original plain-text password. When a user logs in, the system hashes their typed password and compares the hashes to see if they match.

Why Bcrypt is Superior

What makes Bcrypt special compared to older hashes like MD5 or SHA-256?

1. Built-in Salting

A "salt" is a string of random characters added to a password before it gets hashed. This defends against "Rainbow Table" attacks (hackers using pre-computed lists of hashes). Bcrypt automatically generates a secure, random salt and bakes it directly into the final hash string.

2. Intentional Slowness (Work Factor)

Bcrypt is an adaptive hashing algorithm. It features a "cost factor" (or work factor) that dictates how many computational rounds the algorithm must run. Because computers get faster every year, older hashes like MD5 can now be cracked at a rate of billions per second. With Bcrypt, as hardware gets faster, developers can simply increase the cost factor, making the algorithm exponentially slower and highly resistant to brute-force attacks.

Anatomy of a Bcrypt Hash

A standard Bcrypt hash looks like this: $2a$10$N9qo8uLOickgx2ZMRZoMyeIjZAgcfl7p92ldGxad68LJZdL17lhWy * $2a$ - The algorithm version. * $10$ - The cost factor (2^10 rounds). * N9qo8uLOickgx2ZMRZoMye - The randomly generated 22-character salt. * IjZAgcfl7p92ldGxad68LJZdL17lhWy - The actual hashed password.

You can securely generate and verify Bcrypt hashes instantly in your browser using our Bcrypt Hash Generator.