Free tool · Developer tools
NanoID generator
The default settings make IDs of 21 characters from 64 URL safe symbols, which is 126 bits of randomness. Change the alphabet, the length or the count, copy the list, and read how many IDs it takes before a repeat becomes likely.
- Free
- No sign-up
- Runs in your browser
Wt2Y8OheLqW1Kfj1c3kUu21 characters, 126 bits of randomness
- crypto.getRandomValues
- No biased modulo
- Alphabet size
- 64 characters
- Randomness per ID
- 126 bits
- 1% chance of a repeat after
- 1.31e18 IDs
- Time to get there
- 41.4 million years
How to use the NanoID Generator
- Choose the Characters to use, or pick "My own alphabet" and type the symbols.
- Set the Length of each ID and How many IDs you want.
- Press Copy or Download, or Generate again for a fresh batch.
- Check the facts under the list: the bits of randomness and the number of IDs at which a repeat reaches a 1% chance.
What is a nanoid and how is it made?
A nanoid is a short random string built from an alphabet you choose. Each position takes one symbol, and every symbol in the alphabet is equally likely. The usual setup is 21 characters from the 64 symbols A to Z, a to z, 0 to 9, the low line _ and the hyphen, so the ID can sit in a URL, a file name or a database key without escaping.
Randomness comes from the browser's cryptographic generator, crypto.getRandomValues, never from Math.random. A byte has 256 values, which does not divide evenly into most alphabets, and the shortcut of taking the byte modulo the alphabet size makes some symbols a little more likely than others. This page avoids that. It masks each byte down to the next power of two above the alphabet size and throws away any value that points past the end of the alphabet, so every symbol keeps the same chance.
With 64 symbols the mask is 63 and no byte is thrown away. With a 36 symbol alphabet the mask is 63 as well, so about 44% of the bytes are discarded, and the page reads more bytes to make up the difference. You never see this, and the result stays uniform.
How long should an ID be?
Length and alphabet size together set the number of possible IDs. The bits of randomness are the length times the base 2 logarithm of the alphabet size. At length 21 with 64 symbols that is 21 times 6, or 126 bits, which is 1.31e18 IDs before the chance of a first repeat reaches 1%. At a rate of 1,000 new IDs every second, that count takes about 41.4 million years.
The repeat estimate uses the birthday formula: the number of IDs for a probability p is the square root of 2 times N times the natural log of 1 divided by (1 minus p), where N is the number of possible IDs. The table fixes the 64 symbol alphabet and changes the length.
| Length | Bits | IDs for a 1% repeat chance | Time at 1,000 per second |
|---|---|---|---|
| 8 | 48 | 2.4 million | under a day |
| 12 | 72 | 9.7 billion | 113 days |
| 16 | 96 | 39.9 trillion | 1,265 years |
| 21 | 126 | 1.31e18 | 41.4 million years |
| 32 | 192 | 1.12e28 | 3.56e17 years |
Which alphabet should I pick?
A smaller alphabet gives fewer bits per character, so you need more characters for the same safety. Digits only give about 3.3 bits per character. The 64 symbol alphabet gives 6. The table compares six choices at a fixed length of 12 characters.
Hex and digits suit places that accept nothing else. The no look alike set drops 0, o, 1, l and i so an ID read aloud or copied by hand is less likely to be mistyped. A short ID from a small alphabet is fine for a label on a small table. For example, 8 lowercase letters and digits give a 16.2% chance of at least one repeat among a million IDs, which is too high for a primary key.
Use the UUID generator when a standard format is required, and the password generator when the string must be secret and typed by a person. A random ID is an identifier. It is not a login credential.
| Alphabet | Symbols | Bits | IDs for a 1% repeat chance |
|---|---|---|---|
| Hex lowercase | 16 | 48.0 | 2.4 million |
| Digits only | 10 | 39.9 | 141,777 |
| Lowercase and digits | 36 | 62.0 | 309 million |
| No look alikes, 31 symbols | 31 | 59.5 | 126 million |
| Letters and digits | 62 | 71.5 | 8.1 billion |
| URL safe, 64 symbols | 64 | 72.0 | 9.7 billion |
Can I use my own alphabet?
Yes. Choose "My own alphabet" and type 2 to 255 different characters. A repeated character is refused, because it would make that symbol more likely than the others. The page counts what you see as one symbol, so a flag emoji, a family emoji and a letter typed as a base letter plus a separate accent mark each count once and are never split in the middle of an ID.
The page shows the list as lines, a JSON array or quoted lines for pasting into code. IDs are made on your device and nothing is sent to a server.
Use it with
- Username Generator: available-style username ideas.
- Random Number Generator: numbers in a range, no repeats.
- Password Generator: strong random passwords.
Questions
What is the default nanoid length and alphabet?
The default is 21 characters from the 64 URL safe symbols A to Z, a to z, 0 to 9, the low line _ and the hyphen. That is 126 bits of randomness.
How does a nanoid compare with a UUID v4?
A version 4 UUID has 122 random bits in 36 characters. A 21 character nanoid with 64 symbols has 126 bits in 21 characters, so the chance of a repeat is in the same range with a shorter string.
Is the output really random?
The bytes come from crypto.getRandomValues, the browser generator meant for security uses. Bytes that would bias the result are discarded, so every symbol is equally likely.
How many IDs can I make before a repeat?
The page shows the number at which the chance of a first repeat reaches 1%. For the default it is about 1.31e18 IDs. Shorter lengths and smaller alphabets lower it quickly.
Why is a repeated character in my alphabet refused?
A repeated symbol would take two slots in the draw, so it would appear more often than the others. Remove the duplicate to keep the IDs uniform.
Does the page store my IDs?
No. Each batch exists in the open page until you leave or generate again, and nothing is uploaded.
Sources
The tool's results are computed in your browser by the code on this page, using the sources listed above; the explanations are checked against the tool's own output.