Random NanoID Generator
Generate cryptographically secure NanoIDs with custom alphabet, length, and batch size. Collision probability analysis included.
About
NanoID is a compact, URL-safe, cryptographically strong identifier format. A standard UUID v4 occupies 36 characters to encode 122 bits of entropy. A default NanoID packs comparable collision resistance into 21 characters by using a 64-symbol alphabet (A - Z, a - z, 0 - 9, _, -), yielding 126 bits of entropy. Misconfiguring the alphabet size or ID length is the primary source of collision risk in distributed systems. Dropping to a 10-character hex ID, for example, reduces entropy to roughly 40 bits - a collision becomes probable after only ~1.05 million records. This generator uses the browser crypto.getRandomValues() CSPRNG and applies mask-based rejection sampling to eliminate modulo bias across arbitrary alphabet sizes.
The collision probability panel below computes the exact Birthday Paradox estimate for your configuration. Note: the tool assumes uniform random distribution. If you supply an alphabet with duplicate characters, effective entropy decreases and the estimate becomes optimistic. For database primary keys, maintain at least 100 bits of entropy. For short-lived session tokens, 64 bits may suffice.
Formulas
The core entropy per character is derived from the alphabet size A:
Total entropy for an ID of length L:
Collision probability after generating n IDs is approximated by the Birthday Paradox:
The mask for rejection sampling is the smallest bitmask m satisfying:
A random byte is bitwise ANDed with m. If the result โฅ A, the byte is discarded and a new one is drawn. This eliminates modulo bias entirely.
Where: A = alphabet size (number of unique characters), L = ID length, n = number of IDs generated, H = entropy in bits, p = collision probability, m = bitmask for rejection sampling.
Reference Data
| Alphabet Name | Characters | Size | Bits per Char | Default Length | Total Entropy (bits) | Use Case |
|---|---|---|---|---|---|---|
| Default NanoID | A-Za-z0-9_- | 64 | 6.00 | 21 | 126 | General purpose, URL-safe |
| Hexadecimal | 0-9a-f | 16 | 4.00 | 32 | 128 | Hash-like tokens |
| Decimal | 0-9 | 10 | 3.32 | 21 | 69.7 | Numeric codes, PINs |
| Lowercase Alpha | a-z | 26 | 4.70 | 21 | 98.7 | Human-readable slugs |
| Uppercase Alpha | A-Z | 26 | 4.70 | 21 | 98.7 | License keys, serial numbers |
| Alphanumeric | A-Za-z0-9 | 62 | 5.95 | 22 | 131 | Database keys |
| Base32 (Crockford) | 0-9A-HJKMNP-TV-Z | 32 | 5.00 | 26 | 130 | Unambiguous human input |
| No Look-Alike | 2-9A-HJ-NP-Za-km-z | 57 | 5.83 | 22 | 128 | Printed codes (no 0/O/l/1) |
| URL-Safe Base64 | A-Za-z0-9-_ | 64 | 6.00 | 21 | 126 | JWT-compatible tokens |
| Binary | 01 | 2 | 1.00 | 128 | 128 | Bit strings, testing |
| Octal | 0-7 | 8 | 3.00 | 43 | 129 | File permissions, legacy |
| UUID-Compatible | 0-9a-f + hyphens | 16 | 4.00 | 32 | 128 | Drop-in UUID replacement |
| Emoji Set | Selected emoji | 256 | 8.00 | 16 | 128 | Fun identifiers, demos |