What bcrypt embeds when a password meets a new salt and a chosen cost
Bcrypt stretches a password with Blowfish and packs salt, cost, and digest into one printable line. The password is the UTF-8 bytes of the text that was typed. A prefix such as $2a$, $2b$, or $2y$ names the variant, then two digits from 04 through 15 name the work factor, then a dollar sign, then fifty-three characters from the bcrypt base64 alphabet. The full string is sixty characters in the usual layout.
Each hash draws a fresh random salt, so hashing the same password twice at cost 10 yields two different sixty-character lines. The segment $2a$10$ in $2a$10$N9qo8uLOickgx2ZMRZoMyeIjZAgcfl7p92ldGxad68LJZdL17lhWy names cost 10; the following fifty-three characters hold salt and hash together. Only a compare against the full line can confirm a password. This page defaults cost to 10.
Password storage also uses slow PBKDF2 and memory-hard Argon2. A single fast digest without salt belongs under hash digest, and legacy MD5 was never meant for logins. Human-chosen secrets are easier to reason about with a password generator before they are hashed.
How prefix, cost digits, salt, and the fifty-three tail fit one verify step
Why $2a$, $2b$, and $2y$ label bcrypt variants that share salt and cost rules
- $2a$ is the common prefix many libraries emit for new hashes. $2b$ is a corrected $2a$ branch common in Node stacks. $2y$ often appears in PHP password_hash output.
- All three use the same sixty-character shape, the same two-digit cost field, and the same fifty-three character tail alphabet using dot and slash.
- Verify treats them interchangeably when the library is current. The prefix does not name a different password algorithm, only which bugfix label the emitter chose.
Why cost digits from 04 through 15 sit inside the string and scale each guess
- The two digits after the first dollar block are the work factor. Cost 4 is the minimum here, cost 15 is the maximum, and cost 10 is the default.
- Each step up doubles the Blowfish setup work inside the hash. Cost 12 is noticeably slower than cost 10 on the same hardware.
- The cost is stored in the string, so verification reads the same digits the hash was created with. Changing the slider only affects newly generated lines.
Why a new salt on every hash makes identical passwords produce different lines
- The random salt lives inside the fifty-three character tail, not in a separate database column, though apps may still store the whole line in one field.
- Two hashes of the word password at cost 10 share the $2a$10$ header pattern but diverge in every tail character.
- That divergence blocks rainbow tables built for one salt. It does not hide the password; it only forces per-hash guessing work.
Why verification needs the entire stored line including every prefix byte
- Compare parses prefix, cost, salt, and digest from the hash argument. A truncated copy or a bare digest without the $2a$ header is invalid input.
- The regular form is dollar, 2, variant letter, dollar, two cost digits, dollar, then exactly fifty-three alphabet characters.
- Matching means the password bytes and the full hash string pair correctly. It does not recover the password from the line alone.
Where the database line and the typed password quietly disagree
The same short password hashed twice at cost 10
Run hash twice on the word password with cost 10. Both lines begin with $2a$10$ or $2b$10$ depending on the library, and both are sixty characters long. The tails differ because the salt is new each time. A test that expected the same string twice is misunderstanding bcrypt. Verification still accepts either line when the password field holds password and the hash field holds the matching full string.
A row that stored only the fifty-three tail without the $2a$10$ header
Verification expects the complete printable hash. Dropping the prefix and cost removes the salt framing the algorithm needs. Pasting N9qo8uLOickgx2ZMRZoMyeIjZAgcfl7p92ldGxad68LJZdL17lhWy without $2a$10$ in front fails format checks. Production tables store one column with the entire line copied from registration. Debugging login means comparing the whole field, not a substring.
A legacy table that still holds unsalted MD5 beside a modern bcrypt column
MD5 of a password is one fast step with no cost field and no embedded salt. Moving users forward means rehashing at login with bcrypt cost 10 or higher, or running a staged migration. MD5 pages explain the digest shape. hash digest covers other bare hashes. PBKDF2 and Argon2 are alternate slow stores when policy picks them instead of bcrypt.