NanoID is a tiny (130 bytes), URL-safe unique ID generator. It's shorter than UUID, with over 24,000 GitHub stars and used by millions of developers.
| Feature | NanoID | UUID v4 |
|---|---|---|
| Length | 21 chars (default) | 36 chars (with hyphens) |
| Library Size | 130 bytes | Several KB |
| URL Safe | ✅ Yes | Needs encoding |
| Speed | Fast | Slower |
| Customizable | ✅ Length + charset | ❌ Fixed format |
NanoID uses crypto.getRandomValues() (cryptographically secure). With default config (64 chars × 21 length), at 1000 IDs/second it takes ~149 trillion years for 1% collision probability.
NanoID is perfect for database primary keys, short link IDs, file names, session identifiers, tracking codes, order numbers, and any scenario requiring unique identifiers. Its URL-safe nature makes it ideal for web development.