You are setting up a login demo, a voucher batch or a set of classroom codes, and the first decision looks trivial: how many digits? It is not trivial. A password can mix letters, symbols and length until guessing becomes hopeless. A numeric code has ten symbols and nothing else, so every digit changes the odds by a factor of ten, and length becomes the entire security budget.
This guide works through what 4, 6 and 8 digits buy you, why the right answer depends on how many guesses an attacker is allowed, and how to produce codes of any of those lengths with the free Random PIN and OTP Code Generator on Ovatly.
Contents
- Quick answer
- The maths: each digit multiplies the possibilities by ten
- Length is the whole security budget
- How many guesses does an attacker get?
- Choosing a length for the job in front of you
- How to generate codes of a chosen length, step by step
- Worked example: five 6-digit codes
- Limitations and honest tradeoffs
- Common mistakes
- FAQs
- Conclusion
- References
Quick answer
Pick the length by the guessing room the code will face. Four digits give 10,000 possibilities and only hold up when guesses are tightly limited and the code expires fast. Six digits give 1,000,000 possibilities, the familiar OTP-style length. Eight digits give 100,000,000 for higher-value codes such as vouchers. On Ovatly, open the Random PIN and OTP Code Generator, choose the digits per code and how many codes you need up to 500, generate, then copy the list or download it as a text file.
The maths: each digit multiplies the possibilities by ten
A numeric code is a row of positions, each holding one of ten digits. One digit gives 10 possibilities. Two digits give 10 times 10, which is 100. The pattern is simple: the number of possibilities is ten raised to the power of the length.
So a 4-digit code has 10,000 possibilities, from 0000 to 9999. A 6-digit code has 1,000,000. An 8-digit code has 100,000,000. Moving from 4 to 6 digits does not make a code half again as strong; it makes it one hundred times harder to guess by chance. Moving from 6 to 8 multiplies the work by another hundred.
This is also why short codes feel fragile. An attacker trying every 4-digit code needs at most 10,000 attempts, and on average half that. Against 6 digits the same search needs up to a million attempts; against 8, up to a hundred million. Length is not one factor among many here. It is the factor.
Length is the whole security budget
A long password draws strength from several places at once: length, a large alphabet, and unpredictability. A numeric code gives up the alphabet entirely. Every code is digits only, the attacker knows that, and the search space is exactly the number the previous section calculated. There is nothing else to spend.
That has a practical consequence: you cannot rescue a short code with cleverness. A 4-digit code chosen to be obscure, say 7391 instead of 1234, still sits inside the same 10,000 possibilities. Random generation matters because it removes the human patterns attackers try first, but it does not enlarge the space. Only length does that.
How many guesses does an attacker get?
Length never works alone. The other half of the equation is how many guesses the surrounding system allows before it locks or expires the code. A code that expires in minutes and allows a handful of attempts can be short, because the attacker never gets to use the full search space. A code valid for days with unlimited retries needs every digit it can get.
Rate limits and expiry are properties of the system that checks the code, not of the code itself, and they are the reason 4-digit PINs survive at all on devices that lock after a few wrong tries. If you do not control the checking system, or are not sure it limits attempts, choose the longer length and let the extra digits carry the weight.
Choosing a length for the job in front of you
Four digits is the classic PIN length. It suits test data, classroom codes and placeholder OTPs, where the cost of a guessed code is low. Treat it as a convenience format, not a barrier.
Six digits is the OTP-style length most people recognise from login codes. A million possibilities is a sensible default for single-use codes that also expire, and it is short enough to read out and type without errors.
Eight digits, or more, fits vouchers and codes that carry value or stay valid longer: when a code is worth money, the extra hundredfold work is cheap insurance.
How to generate codes of a chosen length, step by step
- Open the Random PIN and OTP Code Generator.
- Set the digits per code: 4 for a classic PIN, 6 for OTP-style, more for vouchers.
- Set how many codes you need, up to 500.
- Click Generate codes. Each code is drawn from a cryptographic random source, with digits kept uniform and no bias toward any value.
- Copy the list, or download it as a text file with one code per line. Nothing is stored, so download before you leave the page.
Worked example: five 6-digit codes
One real run of the generator, set to five codes of six digits, produced this list:
492715
004730
835137
959162
298439
Look at the second code. It starts with two zeros, and the generator kept them, so 004730 is a full six-digit code. If leading zeros were dropped, that code would collapse to 4730, a four-digit code in a space one hundred times smaller than the one you asked for. Any system you paste these into has to treat them as characters, not as a number.
Limitations and honest tradeoffs
These are standalone random codes, not time-based one-time passwords. A real OTP is derived from a shared secret and the clock, which is why it changes every few seconds. The generator does not do that, and its codes are not a substitute for TOTP or for SMS and app-based login flows.
Pre-generated single-use codes can still work, but only when the storing system treats them properly: stored hashed, and expired after use or after a set time. A plain list in a spreadsheet is a list anyone can copy.
Duplicates are also part of the deal. Codes are drawn independently, so repeats happen by chance, and with 500 four-digit codes they are likely, because only 10,000 exist. That is the birthday effect, not a bug. If every code must be unique, deduplicate after generating. Finally, nothing is saved: leave the page without downloading and the batch disappears.
Common mistakes
- Using 4 digits where guesses are unlimited. Ten thousand possibilities is nothing to an automated attacker with no rate limit in the way.
- Stripping leading zeros. Storing codes as numbers turns 004730 into 4730 and silently shortens the code.
- Treating generated codes as authenticator codes. They are random and standalone; they do not rotate.
- Assuming a big batch is automatically unique. Independent random draws repeat by chance. Check for duplicates.
- Leaving the page before downloading. The generator stores nothing, so an unsaved batch is lost.
FAQs
How many possibilities does a 6-digit code have? A 6-digit code has 1,000,000 possibilities, from 000000 to 999999. That is one hundred times the 10,000 possibilities of a 4-digit code, because each added digit multiplies the total by ten.
Is a 4-digit code long enough? It can be, when the system strictly limits guesses and the code expires quickly. With only 10,000 possibilities, a 4-digit code depends on those limits far more than a 6 or 8-digit code does, so it suits low-risk uses such as classroom codes rather than account recovery.
Why do generated codes sometimes start with zero? Because every position is chosen at random, including the first. Leading zeros are kept, so 004730 stays six digits. A code that dropped its leading zeros would be shorter and weaker than the length you asked for.
Are these codes the same as the ones an authenticator app makes? No. The generator makes standalone random codes. A real one-time password from an authenticator app is time-based: it is derived from a shared secret and the clock, and it changes on a schedule. Random codes are not a substitute for that system.
Can a generated batch contain the same code twice? Yes, by chance, and it gets more likely as the batch grows. With 500 four-digit codes, repeats are likely because only 10,000 exist. Deduplicate the list afterwards if every code has to be unique.
Conclusion
For a numeric code, length is not a detail, it is the defence: 10,000 possibilities at 4 digits, 1,000,000 at 6, and 100,000,000 at 8, with rate limits and expiry deciding how much of that space an attacker ever gets to search. The Random PIN and OTP Code Generator makes codes of any of those lengths in batches of up to 500, leading zeros intact. Our companion guide on PIN mistakes: sequences, repeats and years covers the human patterns that make codes easy to guess. For more guides in this series, see our Security and Privacy guides.
References
- NIST Special Publication 800-63B, on memorized secrets and one-time passwords: https://pages.nist.gov/800-63-3/sp800-63b.html
- MDN Web Docs, on the Web Crypto API and
crypto.getRandomValues: https://developer.mozilla.org/en-US/docs/Web/API/Crypto/getRandomValues