Nano ID is a compact, URL-safe unique-ID format that is widely used as a shorter alternative to UUIDs for database primary keys, short links, session tokens, filenames, and API identifiers. This generator produces Nano IDs entirely in your browser with the length, count, and alphabet you specify.
How it works
Each character is chosen from your alphabet using rejection sampling — the same unbiased technique used by the reference nanoid JavaScript library. The generator computes the smallest power-of-two bitmask that covers the alphabet size, draws cryptographically random bytes from crypto.getRandomValues, masks each byte, and discards any value that falls outside the valid alphabet range before re-drawing. This eliminates modulo bias — a common flaw in naive implementations where characters near the beginning of the alphabet appear slightly more often than others.
The default alphabet is the 64-symbol URL-safe set (A–Z, a–z, 0–9, _, -), and the default length is 21 characters, producing collision resistance comparable to a UUID v4 in roughly 60% fewer characters.
Nano ID vs. UUID v4
| UUID v4 | Nano ID (default) | |
|---|---|---|
| Length | 36 characters | 21 characters |
| Character set | hex + hyphens | 64 URL-safe chars |
| URL-safe | No (hyphens OK, but verbose) | Yes, no encoding needed |
| Collision resistance | ~2¹²² | ~2¹²⁶ |
| Randomness source | Depends on implementation | Web Crypto API |
Nano IDs are shorter and drop straight into URLs, filenames, and database keys without percent-encoding. UUIDs have the advantage of being universally recognisable and parseable by existing tooling that specifically expects the UUID format.
Customising the alphabet
Hex-style IDs: set the alphabet to 0123456789abcdef and length to 16 for compact hex identifiers — for example a3f90c1b7e2d8f45. Useful when downstream systems expect hex.
Numeric-only codes: set the alphabet to 0123456789 for short numeric codes — note that a 6-digit code from 10 symbols has far fewer possibilities than a 6-character ID from 64 symbols, so lengthen accordingly if collision matters.
Ambiguity-free: remove look-alike characters (0, O, I, l, 1) from the alphabet for codes that users may need to read and type back, such as short activation codes or vouchers.
Shorter IDs for low-volume apps: 12 characters from the 64-symbol alphabet is safe for most applications that will never generate more than a few million records. Test the collision odds against your expected ID count before going below 12.
Everything runs in your browser. The random bytes, your custom alphabet, and all generated IDs never leave your device.