Why Nano ID?
UUID is 36 characters with hyphens. Nano ID is 21 characters without hyphens. For modern web applications, that difference compounds:
- URLs: Shorter IDs = shorter URLs = better for sharing, easier to type, better for QR codes.
- Databases: 21-character strings are smaller than 36-character UUIDs, reducing index size and improving cache hits.
- APIs: Less data transmitted per request. Across millions of requests, this adds up.
- Frontend: Shorter IDs in state objects, LocalStorage, URLs — less memory and storage.
Nano ID vs UUID
| Property | UUID v4 | UUID v7 | Nano ID |
|---|---|---|---|
| Format | 8-4-4-4-12 hex | 8-4-4-4-12 hex | 21 URL-safe chars |
| Length | 36 characters | 36 characters | 21 characters |
| Entropy | 122 bits | 80 bits | 126 bits |
| Sortable | No | Yes | No |
| Alphabet | 0-9, a-f (hex) | 0-9, a-f (hex) | 0-9, a-z, A-Z, -, _ (base62) |
| RFC 4122 Compliant | Yes | Yes | No (proprietary) |
Use Cases
URL Slugs & Sharing
Instead of: example.com/documents/550e8400-e29b-41d4-a716-446655440000
You get: example.com/documents/V-st_DuCn2b1vQwxmzA89
Shorter URLs rank slightly better in search, are easier to share, and look cleaner in user-facing links.
Database Primary Keys
Nano ID works as a primary key like UUID. VARCHAR(21) vs VARCHAR(36) saves space. In databases with billions of rows, that difference is significant.
API Request Tracking
Include Nano IDs in request headers and logs. You get the same tracking benefits as UUID but with shorter identifiers in logs and monitoring dashboards.
Short Codes & Invites
Stripe, Vercel, and other modern APIs use Nano IDs (or similar) for customer-facing identifiers. They're short enough to type, long enough to be unique, and no special characters.
Frontend State & URLs
Temporary IDs for UI components, route parameters, temporary tokens — Nano ID keeps everything compact.
Nano ID Alphabet
Nano ID uses this 64-character alphabet by default:
V-st_DuCn2b1vQwxmzA89EFfghjkqyrN0OPp3KIiLaRTc4ZJdGs56
It's URL-safe (no / or + like Base64) and doesn't include confusing characters (no 0 vs O, no 1 vs l, no - vs _). This matters when sharing IDs verbally or in printed documents.
Collision Probability
With 126 bits of entropy, Nano ID has even lower collision risk than UUID v4 (122 bits). Birthday paradox: you need ~2^63 IDs before a 50% collision chance. That's 9.2 quintillion IDs. If you generate 1 billion per second, it's still 290 million years.
When NOT to Use Nano ID
- Regulated systems: Industries requiring RFC 4122 UUID compliance (healthcare, finance) may mandate UUID.
- Enterprise/legacy: Systems expecting 36-character hex UUIDs specifically.
- Sortable IDs: If you need timestamp-based sorting, use UUID v7 instead.
- Cryptographic purposes: Neither Nano ID nor UUID v4 should be used for security tokens — use crypto.getRandomValues().
Implementation Notes
Nano ID is popular in JavaScript but exists in other languages too:
- JavaScript/Node:
npm install nanoid— official, well-maintained. - Python:
pip install nanoid— community port. - Go:
github.com/matoous/go-nanoid— popular Go port. - Rust:
nanoidcrate — official Rust port. - Java: Several community ports available.