Skip to content
Agents tracked: 440 Downloads (7d): 202M down 19.5% GitHub stars: 10.4M Releases (7d): 607 Agent status: 3 with issuesSince last limit reset: Claude 28d · Codex 0d Updated Oct 21, 2026

Salt rounds and cost in bcryptjs

The round count sets how much work each hash takes. Raising it makes hashing slower, and the count is stored inside the hash itself.

All bcryptjs examples bcryptjs: usage and stats

Salt rounds and cost in bcryptjs: screenshot of the example below running
The code below, running in Chromium on our server (Oct 12, 2026). Press Run to see it live and change it.

How it works

  1. Hash at several costs. The loop hashes the same password with 4, 6, 8, 10 and 12 rounds and measures each call with performance.now(), so you can see the time grow in your browser. [1]
  2. Read the rounds back. bcrypt.getRounds(hash) returns the round count stored in each hash, which the example prints next to the timing. [1]
  3. Extract the salt. bcrypt.getSalt(hash) returns the salt part of the last hash. It only slices the string. [1]

Run and edit it

It runs in your browser, in a sandboxed frame that cannot see this site; the packages load from esm.sh only after you press Run.

import bcrypt from 'bcryptjs'

const password = 's3cret-passphrase'
let lastHash = ''

console.log('rounds | time      | getRounds(hash)')
for (const rounds of [4, 6, 8, 10, 12]) {
  const t0 = performance.now()
  const hash = await bcrypt.hash(password, rounds)
  const ms = (performance.now() - t0).toFixed(0)
  console.log(`${String(rounds).padStart(6)} | ${ms.padStart(6)} ms | ${bcrypt.getRounds(hash)}`)
  lastHash = hash
}

console.log('Last hash:      ', lastHash)
console.log('getSalt(hash):  ', bcrypt.getSalt(lastHash))
console.log('Still matches?  ', await bcrypt.compare(password, lastHash))
Ctrl/⌘ + Enter runs

Free for signed-in members, with a daily limit. Describe the change in plain words; the new code runs only in your browser.

Watch the milliseconds grow with each round count; add 13 to the list to see it climb further. Code written by AgentGid [1].

Checked Oct 12, 2026: it starts without errors in Chromium with bcryptjs 3.0.3. Needs WebGL.

More bcryptjs examples

Hashing and checking a password with bcryptjs Synchronous hashing in bcryptjs Checking the 72-byte limit with bcryptjs Hash progress and callbacks in bcryptjs

Sources

  1. bcryptjs README (GitHub)

Explanations written by AgentGid from the official docs; the numbers in brackets point here. The code marked "written by AgentGid" is ours and free to copy.

Building something with bcryptjs? Ask AgentGid →