Nano ID generator — short, URL-safe random IDs with collision maths

Pick an alphabet and a length and the tool makes Nano IDs, shows how many bits of randomness each one carries, and tells you how many you could create before the chance of a duplicate reaches 1%.

Live demo · real result from this tool

Press Generate to create a result.

Processed on your device — nothing is uploaded.

How to use the Nano ID generator

  1. Choose an Alphabet: URL-safe (64 characters, the Nano ID default), Alphanumeric (62), Lowercase + digits (36), No look-alikes (49), Hex (16), Digits only, or Custom….
  2. For Custom, type your characters into Custom alphabet. Repeated characters are counted once.
  3. Set the Length (2 to 256; 21 by default) and How many IDs (up to 1,000).
  4. Press Generate, then copy the list. The stats show Entropy per ID and IDs for a 1% collision chance.

What it does and when to use it

Nano IDs are short random strings used as database keys, public record IDs, file names and short-link slugs. They are shorter than a UUID for the same safety, because they use more symbols per character. The URL-safe alphabet needs no escaping in paths or query strings.

The useful part of this page is the second number. Teams often shorten IDs to look tidy without checking the risk. The tool does the sum for you, so you can see how far a shorter ID really goes. For standard 36-character IDs, use the UUID generator. For IDs that sort by creation time, see the ULID generator. For free-form random text, try the random string generator.

How it works

Each character is picked with crypto.getRandomValues and rejection sampling, so every symbol in the alphabet is equally likely.

  • Entropy = length × log2(alphabet size). Each URL-safe character carries 6 bits, so 21 characters give 126 bits.
  • Collision estimate. With N = alphabet size ^ length possible IDs, the number you can make before a 1% chance that any two match is about √(2 × N × ln(1 / 0.99)). This is the birthday-problem approximation.

Worked examples

  • Default Nano ID. URL-safe alphabet, length 21: Entropy per ID: 126 bits, and the 1% point is about 1.3 × 10^18 IDs.
  • Short lowercase slug. Lowercase + digits, length 12, gives 62 bits and IDs for a 1% collision chance: 308,617,316. That is plenty for a blog, but a busy event log could pass it.
  • Six digits. Digits only, length 6, gives 19.9 bits and a 1% risk after just 142 IDs. Short numeric codes need a uniqueness check in your database.
  • Bad custom alphabet. “aaaa” has only one distinct character, so the tool replies “The alphabet needs at least two different characters.”

Limits and tips

  • The tool does not check for duplicates inside a batch or against your data. Add a unique index in the database as a final guard.
  • A 1% chance across the whole lifetime of a system is already high for most teams; aim for numbers far below it.
  • Custom alphabets with spaces or quotes may need escaping in your code.

Frequently asked questions

Are these the same as the nanoid npm package?
They use the same default alphabet (A–Z, a–z, 0–9, underscore and hyphen) and the same default length of 21, and both draw from a cryptographic random source. Any 21-character string from that alphabet is a valid Nano ID, so they work wherever nanoid output is expected.
How short can I safely go?
It depends on how many IDs you will ever create. Read the "IDs for a 1% collision chance" figure and keep your expected total well below it. With 12 lowercase-and-digit characters that limit is about 309 million; with 6 digits it is only 142.
What does the "No look-alikes" alphabet remove?
It keeps 49 characters and drops ones that are easy to confuse when read aloud or typed, such as 0 and O, 1, l and I, 2 and Z, and 5 and S. Use it for IDs people will copy from a screen or a printed label.
Can I use a Nano ID as a secret token?
A 21-character Nano ID has 126 random bits, which is enough to be unguessable, so it can serve as an invite or reset token. Store such tokens like passwords and give them an expiry.

Written by the ToolsRift team · Last updated

Pages are drafted with AI assistance and checked by automated tests. How we write and check pages.

Was this tool useful?

Report a problem

Start typing to search every tool.

↑ ↓ to moveEnter to openEsc to close