← Hashito System home 日本語 Tools Blog
Settings
Result
0
Possible combinations with these settings
0
Until a one percent chance of collision
Alphabet

Where the default length of 21 comes from

NanoID defaults to 21 characters drawn from a 64-character URL-friendly alphabet. Sixty-four to the twenty-first power is 2 to the 126th, about 8.5 x 10 to the 37th. The random part of a UUID v4 is 122 bits, about 5.3 x 10 to the 36th, so the default NanoID is somewhat larger. The length of 21 was chosen to match or beat UUID strength in 21 characters instead of 36. Shortening it costs strength, so when you change the length it is worth watching how the number of combinations moves. That is why this tool reports the years-to-collision next to the IDs.

Shrinking the alphabet has the same effect. Digits alone give ten characters, dropping the information per character from about 6 bits to about 3.32. Keeping the same strength then takes nearly twice the length. Wanting a shorter ID and wanting a smaller alphabet both spend from the same budget.

Why the modulo shortcut is wrong

When picking characters from random bytes, taking the remainder after dividing by the alphabet size makes the first characters slightly more likely. Divide 256 by 62 and you get 4 with 8 left over, so the first eight characters get five slots each while the other fifty-four get four. This tool follows upstream NanoID: mask the byte down to the smallest bit pattern that covers the alphabet and discard values that fall outside it. That reads a few more random bytes, but every character becomes equally likely.

AlphabetPer characterCombinations at 21 charactersComparable to
64 characters (default)6 bitsabout 8.5 x 10^37 (2^126)a little larger than a UUID v4's random part (about 5.3 x 10^36)
62 characters (alphanumeric)about 5.95 bitsabout 4.4 x 10^37where symbols are not allowed; practically the same size
36 characters (lowercase and digits)about 5.17 bitsabout 4.8 x 10^32places where case cannot be kept
16 characters (hexadecimal)4 bitsabout 1.9 x 10^25 (2^84)a truncated hash
10 characters (digits)about 3.32 bits10^21short codes, compensated with length

Randomness comes from the browser's crypto.getRandomValues. Where secure randomness is unavailable the tool says so and generates nothing, rather than silently switching to a predictable source.

Frequently asked questions

Why is the default length 21?

Twenty-one characters drawn from a 64-character alphabet give 64 to the 21st power, which is 2 to the 126th, about 8.5 x 10 to the 37th. The random part of a UUID v4 is 122 bits, about 5.3 x 10 to the 36th, so the default NanoID is somewhat larger. It is the length that matches or beats UUID strength in 21 characters instead of 36.

When should I use a UUID instead?

Use a UUID when the format is fixed for you: a UUID column in the database, or an external specification that requires it. If the value only has to live in your own URLs or file names, a NanoID is shorter and uses just two symbol characters.

How is the years-to-collision figure calculated?

It uses the birthday approximation k = sqrt(2 x N x ln(1 / (1 - p))), where N is the alphabet size raised to the length and p is one percent. The result is divided by the hourly generation rate and converted to years. The arithmetic is done in logarithms because the numbers are large.

Are the generated IDs sent anywhere?

No. Randomness comes from the browser's crypto.getRandomValues and generation happens entirely on this page. If secure randomness is unavailable the tool says so rather than silently falling back to a predictable source.