ToolZoneX
Blog

Nano ID Generator

Generate short, URL-safe, customizable-length unique IDs using unbiased rejection sampling over a secure random source.

Nano ID's real-world default is 21 characters.

64 unique characters. Default is the standard URL-safe Nano ID alphabet.

Generated Nano IDs:

How to Use the Nano ID Generator

Set your desired ID length (21 characters is Nano ID's standard real-world default) and, optionally, a custom character alphabet — the default is the standard URL-safe Nano ID alphabet of 64 characters (A-Za-z0-9_-). Click Generate to produce fresh IDs using crypto.getRandomValues with unbiased rejection sampling: each random byte is masked down to the smallest range that covers the alphabet, and any byte that falls outside the alphabet's actual length is discarded and redrawn, so every character in the alphabet has exactly equal probability — unlike a naive byte % alphabet.length approach, which subtly favors some characters over others.

Example

Generating a 21-character ID with the default alphabet produces something like V1StGXR8_Z5jdHi6B-myT — short, URL-safe, and with negligible collision probability at typical usage volumes.

Common Use Cases

  • Generating short, URL-safe IDs for use directly in URLs, slugs, or short links.
  • Creating compact database primary keys or object IDs for a web application.
  • Producing unique client-side identifiers where a full UUID would be longer than needed.

FAQs

  • How is a Nano ID different from a UUID? A UUID (see our UUID Generator) is a fixed 36-character format with hyphens and specific version/variant bits baked in, always the same length regardless of use case. A Nano ID is shorter by default, fully customizable in length and character set, and URL-safe out of the box — which is why it's commonly used for IDs that show up directly in URLs or database keys in modern web apps.
  • Is a shorter Nano ID less safe from collisions than a UUID? At the default 21-character length with the 64-character alphabet, collision probability is still astronomically low for virtually any realistic application — comparable in practice to UUID v4. Shortening the length or alphabet further trades off some collision resistance for a shorter ID, so pick a length appropriate to how many IDs you expect to generate.
  • Why does the alphabet need to be unbiased? If you map a random byte onto the alphabet with a plain modulo operation, characters near the start of the alphabet get selected very slightly more often whenever 256 isn't evenly divisible by the alphabet length. Rejection sampling discards those uneven leftover byte values instead of using them, so every character has exactly equal probability.