UUID Versions Explained: v1, v4, v5, and v7 Compared

Understanding the different UUID versions, their use cases, and how to choose the right one.

basicsversionscomparison

UUID Versions

UUID (Universally Unique Identifier) has several versions, each with different properties.

Version Overview

VersionBased OnSortableUse Case
v1Timestamp + MACPartiallyLegacy systems
v4RandomNoGeneral purpose
v5Namespace + NameNoDeterministic IDs
v7Timestamp + RandomYesModern databases

UUID v4 (Random)

The most commonly used version. 122 random bits.

xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx
^ ^
| Variant (8, 9, a, or b)
Version (4)

Example: 550e8400-e29b-41d4-a716-446655440000

Pros:
  • Simple to generate
  • No coordination needed
  • Privacy (no embedded info)
Cons:
  • Not sortable
  • Poor database index performance

UUID v7 (Timestamp-based)

Newest version. Timestamp prefix + random suffix.

tttttttt-tttt-7xxx-yxxx-xxxxxxxxxxxx
^^^^^^^^ ^^^^
Unix timestamp (ms)

Example: 0188a5f5-c308-7b99-b5c0-7b5c1c1c1c1c

Pros:
  • Sortable by creation time
  • Better database indexing
  • Still globally unique
Cons:
  • Reveals creation time
  • Slightly newer (less library support)

When to Use What

Use v4 when:
  • You don't need sorting
  • Privacy is important
  • Simple random IDs are fine
Use v7 when:
  • Database performance matters
  • You need chronological ordering
  • Building time-series data

Collision Probability

UUID v4 has 2^122 possible values. The probability of collision:

  • After 1 billion UUIDs: ~0.00000000000000001%
  • You'd need 2.71 × 10^18 UUIDs for 50% collision chance
  • That's generating 1 billion UUIDs per second for 85 years

Frequently Asked Questions

Common questions about this topic

UUID v7 for new projects - it's sortable (better database performance) while maintaining uniqueness. Use v4 if you need maximum randomness or wider library support. Use v5 for deterministic IDs from names/URLs. Avoid v1 (exposes MAC address) unless required.

Theoretically yes, but practically no. UUID v4 has 2^122 possible values. You'd need to generate 1 billion UUIDs per second for 100 years to have a 50% chance of one collision. The probability is so low it's considered impossible in practice.

UUIDs are case-insensitive - 'A1B2...' equals 'a1b2...'. RFC 4122 recommends lowercase for generation but requires accepting either case. Most tools output lowercase. When comparing, normalize to one case. Databases may be case-sensitive, so be consistent.