Understanding UUIDs
A UUID (Universally Unique Identifier) is a 128-bit identifier used to uniquely identify resources across distributed systems.
UUID Structure
UUIDs are represented as 32 hexadecimal digits in five hyphen-separated groups following the 8-4-4-4-12 format, totaling 36 characters.
UUID Structure
32 bits: Low field of the timestamp
1 0 d d 3 8 e a
0001 0000 1101 1101 0011 1000 1110 101016 bits: Middle field of the timestamp
9 1 7 c
1001 0001 0111 110016 bits: 4 bits version + 12 bits high field of timestamp
4 c b e
0100 1100 1011 111016 bits: 2 bits variant + 14 bits clock sequence to help avoid duplicates
a 7 d b
1010 0111 1101 101148 bits: Node identifier
2 5 0 2 2 8 6 9 f 8 4 b
0010 0101 0000 0010 0010 1000 0110 1001 1111 1000 0100 1011Example UUID
550e8400-e29b-41d4-a716-446655440000 ↑ ↑ │ └─ Variant bits (first 2 bits of clock sequence) └────── Version (first 4 bits of time high)
Breaking it down:
- Time Low (8 hex digits):
550e8400 - Time Mid (4 hex digits):
e29b - Time High and Version (4 hex digits):
41d4- Version:
4(first 4 bits / first hex character) - Time High:
1d4(remaining 12 bits / 3 hex characters)
- Version:
- Clock Sequence (4 hex digits):
a716- Variant: First 2 bits of
a(binary:1010, MSB0=1, MSB1=0) - RFC 9562 variant - Clock Sequence:
716(remaining 14 bits)
- Variant: First 2 bits of
- Node (12 hex digits):
446655440000
Understanding Variant Bits
The variant uses the first 2 bits (MSB0, MSB1) of the clock sequence field:
| Bits | Hex | Variant | Description |
|---|---|---|---|
0xxx | 0-7 | NCS Reserved | Network Computing System (NCS) backward compatibility, includes Nil UUID |
10xx | 8-9, A-B | RFC 9562 | The variant specified in this document (most common) |
110x | C-D | Microsoft Reserved | Microsoft Corporation backward compatibility |
111x | E-F | Future Reserved | Reserved for future definition, includes Max UUID |
UUID Versions
At a Glance
| Version | Time-Ordered | Deterministic | Privacy-Safe | DB Performance | Recommendation |
|---|---|---|---|---|---|
| 4 | ✗ | ✗ | ✓ | ✗ | Default choice |
| 5 | ✗ | ✓ SHA-1 | ✓ | ✗ | Name mapping |
| 6 | ✓ Gregorian (1582) | ✗ | ✗ MAC address | ✓ | v1 migration |
| 7 | ✓ Unix (1970) | ✗ | ⚠ Timing exposure | ✓✓ | Recommended if timing exposure is acceptable |
| 8 | Up to implementation | Custom use | |||
| Legacy versions | |||||
| 1 | ✓ Gregorian (1582) | ✗ | ✗ MAC address | ⚠ | Legacy (use v6) |
| 2 | ✗ | ✗ | ✗ | ✗ | Legacy DCE |
| 3 | ✗ | ✓ MD5 | ✓ | ✗ | Legacy (use v5) |
Legend: ✓ = Yes | ✗ = No | ⚠ = Depends/Varies
Time-Based Versions
v1 - Original time-based UUID
- 60-bit timestamp (100-nanosecond precision, epoch starts 1582-10-15)
- Includes MAC address (privacy concern)
- Use: Legacy systems only
v6 - Improved time-based UUID
- Same timestamp as v1, reordered for better database sortability
- Still includes MAC address
- Use: Migrating from v1
v7 - Modern time-based UUID
- 48-bit Unix timestamp (millisecond precision, epoch starts 1970-01-01)
- No MAC address (privacy-safe)
- Excellent database index performance
- Recommended for new time-ordered applications
Random Version
v4 - Random UUID
- 122 bits of cryptographically secure random data
- No time-ordering, no embedded information
- Default choice for most applications
Name-Based Versions
v3 - MD5 name-based
- Deterministic: same namespace + name = same UUID
- Less secure (MD5 vulnerabilities)
- Use: Legacy only (prefer v5)
v5 - SHA-1 name-based
- Deterministic: same namespace + name = same UUID
- Predefined namespaces: DNS, URL, OID, X.500
- Use: Consistent identifiers from names
v8 - Custom name-based
- Use modern hash algorithms (SHA-256, SHA-512)
- Or custom algorithms
- Use: Modern name-based UUIDs
Legacy Versions
v2 - DCE Security
- Rarely used in modern applications
Technical Specifications
| Version | Timestamp | Algorithm | Random Bits |
|---|---|---|---|
| v1 | 60b (100ns, 1582) | Timestamp + MAC | 0 |
| v2 | — | DCE Security | — |
| v3 | — | MD5(namespace + name) | 0 |
| v4 | — | CSPRNG | 122 |
| v5 | — | SHA-1(namespace + name) | 0 |
| v6 | 60b (100ns, 1582) | Timestamp + MAC (reordered) | 0 |
| v7 | 48b Unix (ms, 1970) | Timestamp + random | 74 |
| v8 | Custom | Implementation-defined | 0–122 |