NanoID Generator
Published Updated
Generate one NanoID of 2 to 128 characters, 21 by default, from the 64-symbol URL-safe alphabet or from characters you type. Each symbol adds log2 of the alphabet size in bits, so the default carries 126 bits and a 10-character hex ID only 40.
Length, alphabet and bits
The Nano ID README puts the default at 126 random bits against 122 for a version 4 UUID. The table applies the same arithmetic to other settings, with the collision estimate for a one-in-a-million chance.
| Setting | Possible IDs | Bits | IDs for a 1 in a million collision |
|---|---|---|---|
| 21 characters, 64 symbols (default) | 8.5 x 10^37 | 126 | about 13 quadrillion |
| 12 characters, 64 symbols | 4.7 x 10^21 | 72 | about 97 million |
| 10 characters, hex | 1.1 x 10^12 | 40 | about 1,500 |
| 8 characters, hex | 4.3 x 10^9 | 32 | about 93 |
These come from the birthday approximation n = sqrt(2 x N x ln(1 / (1 - p))), the formula printed in the birthday problem article that the Nano ID collision calculator names for its maths, and the one its script computes. For chances this small it equals sqrt(2 x p x N) to five figures, and it reproduces the README's 103 trillion for UUID version 4 at one in a billion. At the calculator's own 1% chance, the default needs about 1.3 x 10^18 IDs.
Even odds for every symbol
Taking a random byte modulo the alphabet size favours some symbols, a mistake the README warns about. This page redraws any value that would cause that bias.
The counts measured in three browsers are in the tables below. A skewed alphabet would show the other side: aab would give a 2 in 3 share to a, because duplicates weight the draw, which is why the page refuses alphabets with a repeated character.
How each symbol is drawn
Every character of an ID is its own call to crypto.getRandomValues, which MDN describes as a way to get cryptographically strong random values. For an alphabet of up to 256 symbols the code reads one byte, above that two. It keeps a value only if it falls below the largest multiple of the alphabet size and draws again otherwise; the kept value modulo the size picks the symbol. With the default 64 symbols every byte is kept.
Measured with the site's own code in Google Chrome 157, Firefox 155 and Playwright's WebKit build (not the Safari app), 100,000 symbols per alphabet size:
| Symbols in the alphabet | Bytes per draw | Values kept | Redrawn, from the code | Redrawn: Chrome 157 / Firefox 155 / the WebKit build |
|---|---|---|---|---|
| 2, 16, 64 (default), 128 or 256 | 1 | all 256 | 0% | 0% in all three |
| 10 (the digits) | 1 | 250 | 2.34% | 2.42% / 2.30% / 2.35% |
| 26 (a to z) | 1 | 234 | 8.59% | 8.57% / 8.55% / 8.58% |
| 36 (a to z and digits) | 1 | 252 | 1.56% | 1.56% / 1.57% / 1.55% |
| 62 (letters and digits) | 1 | 248 | 3.13% | 3.04% / 3.14% / 3.10% |
| 100 | 1 | 200 | 21.88% | 21.96% / 21.87% / 21.80% |
| 1,000 | 2 | 65,000 | 0.82% | 0.84% / 0.79% / 0.85% |
Symbol counts in three browsers
A chi-square test compares the counts with an even draw. Every p-value below is above 0.05, so none of the three browsers' counts differs significantly from an even draw at the usual 5% level.
| Generated IDs | Chrome 157 | Firefox 155 | The WebKit build |
|---|---|---|---|
| 100,000 default IDs (2.1 million symbols): share per symbol, ideal 1.5625% | 1.547% to 1.583% | 1.541% to 1.585% | 1.535% to 1.587% |
| Chi-square, 63 degrees of freedom | 64.8 (p = 0.41) | 70.6 (p = 0.24) | 71.2 (p = 0.22) |
| 50,000 IDs from 0123456789: share per digit, ideal 10% | 9.958% to 10.054% | 9.942% to 10.078% | 9.964% to 10.034% |
| Chi-square, 9 degrees of freedom | 10.6 (p = 0.31) | 12.9 (p = 0.17) | 4.9 (p = 0.85) |
| 10,000 default IDs, median of 5 runs | 250 ms | 171 ms | 78 ms |
| 10,000 IDs of 128 characters, median of 5 runs | 1,529 ms | 882 ms | 394 ms |
Making an ID
Step 1
Set the length
Drag the slider from 2 to 128 characters. The default is 21, and the ID changes each time the slider moves.
Step 2
Optionally switch on a custom alphabet
Type the characters you want. The default alphabet is A to Z, a to z, 0 to 9, the underscore and the hyphen.
Step 3
Copy NanoID
Press refresh for another ID. The page makes one at a time and keeps no list of earlier ones.
Picking settings
- Keep the default length for database keys, and shorten only where a collision costs little.
- Use a lowercase alphabet for case-insensitive systems, but add length to keep the bits.
- For a time-ordered ID, ULID Generator fits better, and UUID Generator covers the standard format.
NanoID questions
How many IDs before a collision becomes likely?
The birthday estimate is about the square root of twice the probability times the number of possible IDs. For the default 21 characters, a one-in-a-billion chance needs about 413 trillion IDs. For 10 hex characters, a one-in-a-million chance arrives at about 1,500.
Is it the same as the nanoid npm package?
It produces the same kind of ID. Compared in Node.js 22.23.1, the default alphabet holds the same 64 characters as the urlAlphabet of nanoid 3.3.18, in a different order, and both default to 21 characters. Order does not change the odds, since every position is equally likely. The page uses its own code, drawing each symbol from crypto.getRandomValues with rejection sampling, rather than the package.
Can a custom alphabet repeat a character?
No. An alphabet such as aa or aab is refused with a message naming the repeated characters, because a repeated character would be picked more often than the others. At least two different characters are needed.
What if my alphabet contains emoji?
Each emoji counts as one symbol, so a 5-character ID is 5 emoji. JavaScript reports its length as 10, so a length check in your own code may disagree with the slider.
Are IDs sorted by time?
No. Every character is random, unlike ULIDs or UUID version 7, which start with a timestamp. A NanoID is a poor database key where insert order matters.
Is anything sent to a server?
The ID is generated in your browser; this page does not upload it. The tool's code makes no network request and writes nothing to browser storage. Its random source is crypto.getRandomValues, part of the Web Crypto API that the nanoid README names for browsers.
Why does a custom alphabet need more random draws?
Values that would favour some symbols are thrown away and drawn again. With the 10 digits, 250 of the 256 byte values are kept, so 2.34% of draws are redrawn; Chrome 157 redrew 2.42% over 100,000 symbols. A 100-symbol alphabet redraws 21.88%, the most of the sizes measured, while 2, 16, 64, 128 and 256 symbols never redraw.
Can I make an ID of digits only?
Yes. Tick Use a custom alphabet and type 0123456789, and the ID becomes 21 digits, about 69.8 random bits. At the collision calculator's 1% chance that allows about 4.5 x 10^9 IDs, against about 1.3 x 10^18 for the default alphabet.
Do flag emoji work in a custom alphabet?
Not as flags. The alphabet is split into code points and a flag is two of them, so an alphabet of two flags counts as 4 symbols and the ID mixes their halves at random: a 6-symbol ID was 6 regional-indicator letters, which a phone may pair into other flags. Single-code-point emoji work: 3 smileys gave 5-emoji IDs that JavaScript counts as 10 characters.
How long does it take to make an ID?
10,000 default IDs took a median of 250 ms in Chrome 157, 171 ms in Firefox 155 and 78 ms in the WebKit build over 5 runs, 8 to 25 microseconds per ID. On the tool, a new ID was on screen a median of 0.8, 6 and 2 ms after a slider move.