Skip to main content

UUID Versions

A detailed guide to all UUID versions and their use cases.

v4

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
Best for: General purpose, security tokens, when ordering doesn't matter
v7

Version 7 (Unix Epoch)

RECOMMENDED

New 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
Best for: Database primary keys, logs, time-ordered events
v1

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
v3
v5

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"
Best for: When you need the same UUID for the same input (idempotency)

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