NanoID Generator
Generate compact, URL-friendly unique IDs with configurable length and alphabet using unbiased randomness
Generate NanoIDs
Default 21 provides ~126 bits of entropy with URL-safe alphabet
Choose a character set or define your own
Must contain at least 2 unique characters
Generate multiple NanoIDs at once
What is NanoID?
NanoID is a compact, secure, URL-friendly unique identifier generator. It creates short string IDs using cryptographically strong random values, making it ideal for URLs, database keys, and any context where you need unique identifiers without the bulk of UUIDs.
How to Use
- Set the desired ID length (default 21 characters)
- Choose an alphabet or define a custom character set
- Set the quantity of IDs to generate
- Click "Generate" to create your NanoIDs
- Copy the result using the Copy button
NanoID vs UUID
While UUIDs are the standard for unique identifiers, NanoID offers several advantages for modern applications:
- Shorter: 21 chars vs 36 chars (40% more compact)
- URL-safe: Default alphabet uses only URL-safe characters
- Customizable: Choose your own alphabet and length
- Same security: 126 bits of entropy (comparable to UUID v4's 122 bits)
- No dependencies: Simple algorithm using Web Crypto API
Collision Probability
The collision probability depends on ID length and alphabet size. With the default settings (21 chars, 64-character alphabet), you get ~126 bits of entropy. To reach a 1% collision probability, you would need to generate approximately:
- 21 chars, URL-safe (64): ~1 billion IDs/second for 4 years
- 21 chars, alphanumeric (62): Similar to URL-safe
- 21 chars, hexadecimal (16): ~10 million IDs total for 1% risk
- 21 chars, numeric (10): ~2 million IDs total for 1% risk
Alphabet Choices
The alphabet determines which characters appear in generated IDs:
- URL-safe: A-Z, a-z, 0-9, hyphen, underscore — safe in URLs without encoding
- Alphanumeric: A-Z, a-z, 0-9 — no special characters, safe everywhere
- Hexadecimal: 0-9, a-f — useful when hex format is required
- Numeric: 0-9 only — for numeric-only systems
- Custom: Define your own character set for specific requirements
The Unbiased Mask Technique
A naive implementation using modulo (%) to map random bytes to alphabet characters introduces bias when the alphabet size doesn't evenly divide 256. NanoID solves this with a mask-and-reject approach: it creates a bitmask from the nearest power of 2 above the alphabet length, applies it to random bytes, and discards values that exceed the alphabet size. This guarantees uniform distribution.
Examples
# Default URL-safe, length 21
V1StGXR8_Z5jdHi6B-myT
# Alphanumeric, length 12
j3KxMqR7vNpL
# Hexadecimal, length 32
a1b2c3d4e5f6789012345678abcdef90
# Numeric, length 8
48291037 Frequently Asked Questions
What is a NanoID and how does it differ from a UUID?
NanoID is a compact, URL-friendly unique identifier generator. Unlike UUID's fixed 36-character hex format, NanoID allows configurable length (2–128 chars) and custom alphabets. A 21-character NanoID with the default URL-safe alphabet provides comparable collision resistance to UUID v4 while being 40% shorter.
How does NanoID avoid modulo bias?
NanoID uses an unbiased mask technique: it creates a bitmask based on the alphabet size (nearest power of 2), generates random bytes, applies the mask, and rejects values outside the alphabet range. This ensures every character has equal probability regardless of alphabet size.
What collision probability does a 21-character NanoID have?
With the default URL-safe alphabet (64 characters) and length 21, a NanoID has 126 bits of entropy — similar to UUID v4's 122 bits. You would need to generate about 1 billion IDs per second for 4 years to have a 1% collision probability.
Is NanoID generation cryptographically secure?
Yes. This tool uses the browser's crypto.getRandomValues() API, which provides cryptographically secure pseudo-random numbers. The random bytes are never exposed directly — they are masked and mapped to the configured alphabet.