UUID has been the default unique identifier for 30 years. It works. But two challengers have real arguments: NanoID is shorter, and ULID is sortable. Do either of them replace UUID? Depends on your problem.
I have used all three in production. Each has a sweet spot. None of them is universally best.
The Three Contenders
**UUID v4** — 128 bits, 36 characters with hyphens. Example: f47ac10b-58cc-4372-a567-0e02b2c3d479. The industry standard. Every database, every language, every tool supports it.
**NanoID** — 21 characters by default, URL-safe alphabet. Example: V1StGXR8_Z5jdHi6B-myT. Created by Andrey Sitnik in 2017. Smaller, faster to generate, designed for URLs.
**ULID** — 128 bits, 26 characters, time-ordered. Example: 01ARZ3NDEKTSV4RRFFQ69G5FAV. The first 48 bits are a timestamp (milliseconds since Unix epoch), the rest is random. Sortable, compact, URL-safe.
Size Comparison
| Format | Bits | Characters | Example | |--------|------|------------|---------| | UUID v4 | 128 | 36 | f47ac10b-58cc-4372-a567-0e02b2c3d479 | | NanoID | 126 | 21 | V1StGXR8_Z5jdHi6B-myT | | ULID | 128 | 26 | 01ARZ3NDEKTSV4RRFFQ69G5FAV |
NanoID and ULID are shorter in the URL. That matters for public-facing IDs in URLs — shorter URLs are easier to share, paste, and read.
Sortability: The ULID Advantage
UUID v4 is random. It does not sort. This is the UUID's biggest weakness as a database key, as we cover in UUIDs as primary keys.
ULID sorts chronologically. The timestamp prefix means new ULIDs always sort after old ones. This gives you the merge-safety of UUIDs with the index-friendliness of auto-increment integers. If you are choosing a primary key for a high-insert table, ULID is a strong alternative to UUID.
NanoID does not sort. It is purely random, like UUID v4, but shorter.
Collision Risk
All three have negligible collision risk for practical use. But the math differs:
**UUID v4**: 2^-61 probability of collision after generating 103 trillion UUIDs (birthday paradox at 50% collision). You will never hit this.
**NanoID (21 chars, default alphabet)**: Collision probability depends on the alphabet size and length. At 21 characters with 64-character alphabet, you get 126 bits of entropy. Comparable to UUID.
**ULID**: 80 bits of randomness (the timestamp is fixed for a given millisecond). Within the same millisecond, collision probability is 2^-40 at 2^40 ULIDs generated in that millisecond. In practice, you will not generate that many in a millisecond.
Ecosystem Support
This is where UUID wins decisively.
- **Databases**: Postgres has a native uuid type. SQL Server has UNIQUEIDENTIFIER. MySQL has UUID(). No database has a native NanoID or ULID type. You store them as strings or bytes. - **ORMs**: Every ORM supports UUID. NanoID and ULID require custom type handlers. - **Languages**: Every language has a UUID library in the standard library or one package away. NanoID and ULID need third-party packages. - **Tools**: Every logging, monitoring, and tracing tool understands UUIDs. NanoID and ULID are less recognized.
When To Use Each
**Use UUID when:** - You need maximum compatibility - You are in a Microsoft ecosystem (GUID) - You need v5 deterministic generation (namespace + name) - Your team already knows UUID and does not want to learn something new
**Use NanoID when:** - You need short IDs in URLs - You want to reduce payload size in API responses - You do not need sortability or database native type support - You are generating IDs client-side in JavaScript
**Use ULID when:** - You need a sortable primary key that is also globally unique - You want the merge-safety of UUIDs with the index performance of sequential IDs - You are building a new system and can choose your ID format from scratch - You need IDs that sort correctly as strings (lexicographic order matches chronological order)
Code Comparison
javascript // UUID const { randomUUID } = require('crypto'); const id = randomUUID(); // f47ac10b-58cc-4372-a567-0e02b2c3d479
// NanoID const { nanoid } = require('nanoid'); const id = nanoid(); // V1StGXR8_Z5jdHi6B-myT
// ULID const { ulid } = require('ulid'); const id = ulid(); // 01ARZ3NDEKTSV4RRFFQ69G5FAV
## The Verdict
For a new project in 2026, ULID is the strongest default for database primary keys. It gives you sortability, compactness, and global uniqueness. UUID remains the safest choice for compatibility. NanoID is the best pick for short public-facing IDs where you do not need database native type support.
Generate UUIDs at our UUID generator. For the version breakdown, read UUID v1 vs v4 vs v5. For database key considerations, see UUIDs as primary keys.