Last Updated: 3/9/2026
Overview
Nano ID is a tiny, secure, URL-friendly unique string ID generator for JavaScript.
What is Nano ID?
Nano ID generates short, random, unique identifiers perfect for database IDs, URL slugs, or any scenario where you need collision-resistant unique strings.
import { nanoid } from 'nanoid'
const id = nanoid()
// => "V1StGXR8_Z5jdHi6B-myT"Key Benefits
Small Size
118 bytes (minified and brotlied) with zero dependencies. Nano ID is 4 times smaller than the uuid/v4 package (130 bytes vs 423 bytes).
Secure by Default
Uses hardware random generators through Node.js crypto module and Web Crypto API. No predictable patterns, uniform distribution across the alphabet.
Short IDs
Uses a larger alphabet than UUID (A-Za-z0-9_- = 64 characters). IDs are 21 characters instead of UUID’s 36, with similar collision probability.
URL-Friendly
Default alphabet is URL-safe. No special encoding needed when using IDs in URLs, filenames, or as HTML attributes.
Portable
Ported to over 20 programming languages. Use the same ID format across your entire stack.
How It Compares
Nano ID has similar collision probability to UUID v4:
For there to be a one in a billion chance of duplication, 103 trillion version 4 IDs must be generated.
But with significantly shorter IDs and smaller bundle size. See the detailed Comparison with UUID for more.
Quick Example
import { nanoid } from 'nanoid'
// Generate a standard ID (21 characters)
const userId = nanoid()
// => "V1StGXR8_Z5jdHi6B-myT"
// Generate a shorter ID (higher collision risk)
const shortId = nanoid(10)
// => "IRFa-VaY2b"
// Use a custom alphabet
import { customAlphabet } from 'nanoid'
const nanoid = customAlphabet('1234567890abcdef', 10)
const hexId = nanoid()
// => "4f90d13a42"When to Use Nano ID
✅ Great for:
- Database primary keys and foreign keys
- URL slugs and short links
- Session IDs and tokens
- File names and temporary identifiers
- Client-side ID generation
- Distributed systems (no coordination needed)
⚠️ Consider alternatives for:
- Cryptographic keys (use purpose-built crypto libraries)
- Sortable/sequential IDs (consider ULIDs or Snowflake IDs)
- Human-readable identifiers (consider readable word combinations)
Next Steps
- Install Nano ID - Choose your installation method
- Quick Start Guide - Get running in 2 minutes
- Core API - Learn all the options
Made by Evil Martians
Nano ID is created and maintained by Evil Martians , product consulting for developer tools.