UUID Versions
A detailed guide to all UUID versions and their use cases.
Version 4 (Random)
Completely random UUID. Most commonly used version.
Pros
- • Simplest implementation
- • Cryptographically secure
- • Reveals no information
- • Most commonly used
Cons
- • Not sortable
- • DB index fragmentation
Version 7 (Unix Epoch)
RECOMMENDEDNew standard with Unix timestamp. Sortable and database-friendly.
Pros
- • Chronologically sortable
- • Excellent for DB indexing
- • Contains timestamp
- • New standard (RFC 9562)
Cons
- • Reveals approximate time
- • Newer, less support
Version 1 (Time-based)
Generated using timestamp and MAC address. Ideal for distributed systems.
Pros
- • Hardware-level uniqueness
- • Contains timestamp
Cons
- • Reveals MAC address
- • Privacy concern
- • Not for security
Version 3 (MD5 Hash) & Version 5 (SHA-1 Hash)
Hash-based versions - generate deterministic UUID from namespace and name. V3 uses MD5, V5 uses SHA-1 (more secure).
Usage Example
namespace: "6ba7b810-9dad-11d1-80b4-00c04fd430c8" (DNS)
name: "example.com"
→ UUID v5: "cfbff0d1-9375-5685-968c-48ce8b15ae17"
Version Comparison
| Version | Source | Sortable | Secure | Use Case |
|---|---|---|---|---|
| v1 | Time + MAC | ~ | ✗ | Distributed systems |
| v3 | MD5 hash | ✗ | ~ | Deterministic IDs |
| v4 | Random | ✗ | ✓ | General purpose |
| v5 | SHA-1 hash | ✗ | ✓ | Deterministic IDs |
| v7 | Unix time + random | ✓ | ✓ | DB primary keys |