Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4791 pages

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

By Maaz Zindani · Updated

Only for the collision time below.
Your first ID

Wt2Y8OheLqW1Kfj1c3kUu21 characters, 126 bits of randomness

Wt2Y8OheLqW1Kfj1c3kUu aEuTItdpceL4EG2V7RWFE qnKkt-lHfjEjhVg6M8E71 3fX17y9znsq6cbb7ZlrrJ bbWhsktX_mWUqy8-xxBKl
  • 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

  1. Choose the Characters to use, or pick "My own alphabet" and type the symbols.
  2. Set the Length of each ID and How many IDs you want.
  3. Press Copy or Download, or Generate again for a fresh batch.
  4. 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 of the ID with the 64 symbol alphabet, at 1,000 IDs per second
LengthBitsIDs for a 1% repeat chanceTime at 1,000 per second
8482.4 millionunder a day
12729.7 billion113 days
169639.9 trillion1,265 years
211261.31e1841.4 million years
321921.12e283.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.

Six alphabets at 12 characters
AlphabetSymbolsBitsIDs for a 1% repeat chance
Hex lowercase1648.02.4 million
Digits only1039.9141,777
Lowercase and digits3662.0309 million
No look alikes, 31 symbols3159.5126 million
Letters and digits6271.58.1 billion
URL safe, 64 symbols6472.09.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

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.

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.