NanoID Generator

Generate Multiple NanoIDs

What is NanoID?

NanoID is a tiny, secure, URL-friendly unique string ID generator. It’s similar to UUID v4 but is much more compact while still maintaining excellent uniqueness guarantees. NanoIDs are typically 21 characters long by default (though this is configurable) and use a URL-friendly character set.

Benefits of NanoIDs:

  • Compact: Only 21 characters in default configuration (vs 36 for UUID)
  • URL-safe: Uses URL-friendly characters (A-Za-z0-9_-)
  • Secure: Uses a cryptographically strong random generator
  • Universal: Implemented in over 20 programming languages
  • Customizable: Size and alphabet can be configured for specific needs

Why 21 Characters? (Entropy & Collision Safety)

A standard NanoID uses a 64-character URL-safe alphabet (A–Z, a–z, 0–9, _, -), packing 6 bits of cryptographic randomness per character:

  • 21 characters × 6 bits = 126 bits of entropy — slightly stronger than UUIDv4’s 122 random bits, while being 42% shorter (21 chars vs. 36 chars)!
  • At 1,000 IDs generated per hour, it would take ~149 billion years to have a 1% probability of a single collision (about 1.3 × 1018 IDs).
  • The IDs on this page are generated server-side by the TymBits backend with the nanoid library, which draws on the operating system’s cryptographically secure random generator rather than Math.random(), so they are unguessable and safe for public URLs, share links, and invite codes.

NanoID vs. UUIDv4 vs. XID

Dimension NanoID (21 chars) UUIDv4 (36 chars) XID (20 chars)
Random entropy 126 bits 122 bits Non-random (timestamp + node + counter)
URL-safe (no escaping) Yes (A-Za-z0-9_-) Yes (with hyphens) Yes (0-9a-v, lowercase only)
Time-sortable? No (purely random) No (purely random) Yes (1-second chronological order)
Customizable alphabet/length Yes (e.g., no lookalike chars 0OIl) Fixed RFC 9562 format Fixed 12-byte format
Best for Short public URLs, slugs, invite tokens, frontend IDs Legacy DBs with native UUID column High-write DB primary keys & distributed logs

FAQs

Is NanoID safer or faster than UUIDv4? A 21-character NanoID provides 126 bits of randomness (vs. 122 bits in UUIDv4), is 42% shorter in URLs and JSON payloads, and has a tiny JavaScript footprint (118 bytes minified and brotli-compressed, per the nanoid README). Note that the default alphabet includes - and _, so double-clicking an ID may select only part of it; use a custom alphabet without them if that matters.
Should I use NanoID as a PostgreSQL or MySQL B-Tree primary key? Because NanoIDs are completely random, very high-write relational tables can experience B-Tree page splits (see Database Indexing). A popular pattern is to keep an internal sequential or time-sortable key (like XID or UUIDv7) for storage and expose a NanoID as the public-facing URL identifier.
What characters can appear in a standard NanoID? The default alphabet contains 64 URL-safe characters: uppercase A–Z, lowercase a–z, digits 0–9, underscore _, and hyphen -. No URL percent-encoding is ever needed.

More Free Developer Tools