Every small app reaches the same awkward moment. You are wiring up password storage, the library asks for a bcrypt cost factor, and a search returns confident answers that all disagree. One post says 10, another says 12, a third says anything under 14 is careless. None of them know your server or your users.
The honest answer is that cost is not a magic number to copy. It is a measurement to make on your own hardware, with a clear target to aim at. This guide explains what the cost factor controls, why the target is roughly 250 ms per check, and how to use the free bcrypt Hash Generator on Ovatly to feel each step before you commit to a setting in production.
Contents
- Quick answer
- What the cost factor actually does
- Why 250 ms is the target
- How to choose a cost, step by step
- Worked example: one password at cost 10
- Limitations and honest tradeoffs
- Common mistakes
- FAQs
- Conclusion
- References
Quick answer
To choose a bcrypt cost for a small app: start at cost 10, run one password check on your own production server, and raise the cost one step at a time until a single check takes roughly 250 ms. Most apps land between cost 10 and cost 13 using that method. Each step doubles the work, so cost 12 is four times slower than cost 10. Before you change production settings, try the bcrypt Hash Generator, which offers cost 4 to 12, and notice how quickly the delay grows. Then re-tune whenever your hardware changes, because the right cost is a moving target.
What the cost factor actually does
bcrypt hashes a password slowly, on purpose. When a user logs in, your app hashes the password they typed and compares it with the stored hash. If the two match, the password was correct. The cost factor sets how much work goes into each hash. A higher cost means more computation, so each hash and each check takes longer.
That delay is the entire defence. If your password database ever leaks, an attacker can guess passwords offline, hashing each guess and checking it against the stolen values. A fast hash lets them test guesses in huge numbers. bcrypt makes every guess expensive, and the cost factor decides how expensive. Raise it by one and every guess takes twice as long. Raise it by two, from 10 to 12, and every guess takes four times as long.
Two details matter here. First, bcrypt uses a fresh random salt for every password, stored inside the resulting hash string. Identical passwords therefore produce different hashes, and an attacker cannot precompute one table of guesses and reuse it against every account. Second, bcrypt truncates input at 72 bytes, so characters beyond that point add no strength. That limit is worth knowing, but it rarely affects a cost decision.
Why 250 ms is the target
Real applications pick a cost that makes one check take roughly 250 ms on the production server. That figure is a balance, not a law of nature. A quarter of a second is short enough that a person logging in barely notices it. At the same time, it hurts an attacker badly: a quarter of a second per guess means only a handful of guesses per second per machine, instead of the millions per second a fast hash would allow.
Commonly, that measurement lands between cost 10 and cost 13. Cost 10 is the classic default and a sensible starting point. A fast modern server might complete a cost 10 check well under 250 ms, in which case you should raise it. An older or shared server might already be near the target at cost 10, in which case raising it further would tax every login for little benefit. The number follows the measurement, never the other way round.
Hardware also moves. Servers get faster every year, so a cost that produced 250 ms five years ago may produce far less today. The setting that protected your users at launch quietly weakens as machines improve. That is why the cost needs re-tuning from time to time: measure again on the new hardware and adjust so one check returns to roughly 250 ms.
How to choose a cost, step by step
- Open the bcrypt Hash Generator and enter a test password, such as the phrase in the worked example below.
- Set the cost to 10 and generate a hash. Then generate again at 11 and at 12, and feel how the wait grows. The tool warns at cost 11 and 12, because in a browser the longer computation can freeze the tab. On a server the same growth applies, just without the frozen tab.
- On your production server, time one real password check at cost 10.
- If one check takes well under 250 ms, raise the cost by one and measure again, until a single check takes roughly 250 ms.
- Record the cost you landed on, and re-measure when the server hardware changes.
Worked example: one password at cost 10
Hashing the password "correct horse battery staple" at cost 10 produced this result in one run:
$2b$10$jT61zASMuZO.BYMYrC8tVOrG4f70YI6WdfYJA2RvF4xQe9jYzcUa.
Your run will produce a different string, and that is expected. A fresh random salt is generated every time and stored inside the result, so the same password never hashes to the same value twice. What stays constant is the structure: the opening characters name the format, the 10 records the cost, and the rest carries the salt and hash together.
Now read the cost through the doubling rule. If cost 10 gives a check near 250 ms on your server, cost 11 gives roughly 500 ms and cost 12 roughly a full second, four times the cost 10 time. For a small app, a one second login delay is usually where users start to notice. That is the practical ceiling the measurement protects you from crossing by accident.
Limitations and honest tradeoffs
The generator in your browser is a learning and testing tool, not a benchmark of your server. Browser timing shows how the delay scales, but the number you ship must come from timing checks on the production machine itself.
bcrypt is also not the newest option. It remains widely used and acceptable, but newer systems often choose Argon2id. If your app already uses bcrypt, a correctly measured cost is a sound defence.
Finally, a good cost does not rescue weak passwords. bcrypt slows guessing; it does not make a predictable password strong. Unique passwords and a second factor do work that cost cannot.
Common mistakes
- Copying a cost from a blog post. The right number depends on your server's speed. Measure on your own hardware, aiming for about 250 ms per check.
- Setting the highest cost available. Every login pays it. Overshooting makes sign-in slow and loads a small server, for little extra safety.
- Never re-tuning. Hardware improves, so yesterday's 250 ms becomes today's 60 ms. Re-measure when the server changes.
- Using a fast hash for passwords. Fast hashes are built for speed, which is exactly what password storage must avoid.
- Assuming a high cost fixes weak passwords. Cost slows guessing; it does not make a predictable password strong.
FAQs
What bcrypt cost should a small app start with? Start at cost 10, the classic default, then measure one check on your production server. Raise the cost until a single check takes roughly 250 ms. Most apps land between 10 and 13 by that method.
Why does cost 12 take four times as long as cost 10? Each cost step doubles the amount of work bcrypt does. Going from 10 to 11 doubles it, and going from 11 to 12 doubles it again, so cost 12 is four times slower than cost 10.
What happens if the cost is too high? Every login, signup and password change pays the cost, so an oversized setting makes sign-in feel slow and loads your server during busy periods. The cost should be as high as you can afford at about 250 ms per check, not higher.
Can I try different costs before changing my app? Yes. The bcrypt Hash Generator on Ovatly offers cost 4 to 12, so you can generate hashes at several costs and feel how the delay grows as the number climbs. It warns at cost 11 and 12 because higher costs can freeze a browser tab.
Should I ever store passwords with a fast hash like SHA-256 instead? No. Fast hashes let an attacker test guesses at very high speed if the password database leaks. bcrypt is deliberately slow and salted, which is exactly what password storage needs. Newer systems often use Argon2id, which is the modern alternative.
Conclusion
Choosing a bcrypt cost is a measurement task: time one check on your own server, aim for roughly 250 ms, expect to land between cost 10 and 13, and measure again as hardware improves. For the opposite end of hashing, a fast algorithm used for file checks, see the companion guide on comparing an MD5 hash against a published value. For more guides in this series, see our Security and Privacy guides, which pair each technique with the free tool that performs it.
References
- OWASP Cheat Sheet Series, on password storage and choosing work factors: https://cheatsheetseries.owasp.org/cheatsheets/Password_Storage_Cheat_Sheet.html
- Provos and Mazieres, the original bcrypt paper, "A Future-Adaptable Password Scheme": https://www.usenix.org/legacy/events/usenix99/provos.html