UUID vs NanoID vs ULID
Four flavors of unique ID, four different tradeoffs. Pick the one that matches your indexing, URL, and sort requirements.
550e8400-e29b-41d4-a716-446655440000 0192f8c1-9c88-7f3a-9e7e-45b1a8c7d0d1
V1StGXR8_Z5jdHi6B-myT 01HN2PX7JGK5R2YQ9VQAHZX6EK
Four Flavors of Unique ID
UUID v4 (random)
122 bits of randomness, 36-character string. Ubiquitous, well-supported in every language and database. Downsides: non-sortable, large (16 bytes binary / 36 bytes string), and fragments B-tree indexes because random values scatter inserts across pages.
UUID v7 (time-ordered)
Combines a millisecond timestamp with randomness in a UUID-compatible layout. Monotonically increasing within the same millisecond, so inserts cluster at the end of the index — kinder to Postgres and MySQL B-trees than v4. Standardized in RFC 9562 (2024).
NanoID
21-character URL-safe string, 126 bits of entropy — about the same collision resistance as UUID v4 in less space. Great for public URLs (shorter than UUID) but non-sortable like v4.
ULID
26-character Crockford Base32 string with a 48-bit millisecond timestamp prefix and 80 random bits. Lexicographically sortable, URL-safe, slightly shorter than UUID. Great for logs and event IDs.
Which to Pick
- Primary keys in a RDBMS: UUID v7 (or ULID stored as 16-byte binary)
- Public URLs: NanoID (short) or ULID (sortable)
- Legacy compatibility: UUID v4 — everyone speaks it
- Distributed logs / events: ULID or UUID v7
- Short share codes: NanoID with a custom alphabet and length
Try It
Encode or decode a UUID to compact Base64 with our free UUID ↔ Base64 converter.
Index locality
Time-ordered IDs (v7, ULID) are kinder to B-tree indexes.
Collision odds tiny
All four have >120 bits of entropy — collisions are effectively impossible.
Sortability
ULID and UUID v7 sort by creation time out of the box.