UUID Versions: When to Use Which
UUID Versions: When to Use Which
UUIDs (Universally Unique Identifiers) are 128-bit identifiers used everywhere: database primary keys, API resources, distributed systems, and session tokens.
The Versions
UUID v1 — Time-Based
Generated from timestamp + MAC address. Sortable by creation time but leaks the machine's MAC address.
Use when: you need time-ordering and don't care about privacy. Avoid when: the MAC address leak is a concern.UUID v4 — Random
Generated from cryptographically random bytes. The most commonly used version.
550e8400-e29b-41d4-a716-446655440000
^
4 = version 4
Use when: you need a unique ID with no other requirements.
Avoid when: you need database-friendly ordering.
UUID v7 — Time-Ordered Random (Recommended)
New in RFC 9562 (2024). Combines a Unix timestamp prefix with random bits. Sortable, database-friendly, and random enough.
018f1234-5678-7abc-8def-0123456789ab
^^^^^^^^^^^^^^^^
Unix timestamp (ms)
Use when: database primary keys (B-tree friendly), distributed systems, anything that benefits from time-ordering.
UUID v5 — Name-Based (SHA-1)
Deterministic: same namespace + name always produces the same UUID. Uses SHA-1 hashing.
Use when: you need reproducible IDs from known inputs (e.g., URL → UUID mapping).Database Performance
Random UUIDs (v4) fragment B-tree indexes because insertions happen at random positions. This causes:
UUID v7 solves this by being time-ordered — new inserts always go at the end of the index, just like auto-incrementing integers.
UUID vs Other ID Formats
| Format | Length | Sortable | URL-safe | Collision Risk |
|--------|--------|----------|----------|----------------|
| UUID v4 | 36 chars | No | No (hyphens) | ~Impossible |
| UUID v7 | 36 chars | Yes | No | ~Impossible |
| ULID | 26 chars | Yes | Yes | ~Impossible |
| nanoid | 21 chars | No | Yes | Configurable |
| CUID2 | 24 chars | Partially | Yes | ~Impossible |
Try It
Use our UUID Generator to generate v4 UUIDs with bulk generation, format options, and validation.
Conclusion
Use UUID v7 for database primary keys — it's time-ordered and B-tree friendly. Use UUID v4 when ordering doesn't matter. Use UUID v5 for deterministic mapping. Avoid v1 unless you specifically need MAC-based time UUIDs.