What is UUID v4?
UUID version 4 is a random-based 128-bit identifier (36-char string) from RFC 4122. It consists of:
- Random values: 122 bits of random data
- Version bits: 4 bits indicating version 4 (0100)
- Variant bits: 2 bits indicating RFC 4122 variant (10)
Format example: f47ac10b-58cc-4372-a567-0e02b2c3d479
How UUID v4 works
- Generate 122 bits of cryptographically strong random data
- Set version bits to 0100 (version 4)
- Set variant bits to 10 (RFC 4122 standard)
- Assemble as 32 hex digits with hyphens: 8-4-4-4-12 format
Advantages & Considerations
Advantages | Considerations |
---|---|
|
|
UUID v4 Structure
Bits | Content |
---|---|
0-47 | Random data |
48-51 | Version (0100 for v4) |
52-63 | Random data |
64-65 | Variant (10 for RFC4122) |
66-127 | Random data |
UUID v4 vs. other versions
Version | Based on | Use case | Privacy |
---|---|---|---|
UUID v1 | Time + MAC | Time-ordered IDs | ⚠️ Reveals MAC |
UUID v3 | Namespace + MD5 | Deterministic IDs | ✅ Private |
UUID v4 | Random | Secure random IDs | ✅ Private |
UUID v5 | Namespace + SHA-1 | Deterministic IDs | ✅ Private |
UUID v6 | Time (reordered) | Sortable IDs | ⚠️ Reveals MAC |
UUID v7 | Time + random | Sortable IDs | ✅ Private |
Common Use Cases
- Database keys: Distributed applications
- Security tokens: Authentication systems
- One-time identifiers: Temporary access
- Multi-tenant systems: Preventing collisions
- Content identifiers: Document management
- API request IDs: Request tracking
Frequently Asked Questions
Is UUID v4 cryptographically secure?
Yes. UUID v4 relies on cryptographically strong random number generators, making it suitable for security-sensitive applications.
Can UUID v4 values collide?
Theoretically yes, but practically no. With 122 random bits, the probability of collision is astronomically small, even with billions of generated UUIDs.
Can I extract creation time from UUID v4?
No. Unlike time-based UUIDs (v1, v6, v7), UUID v4 contains only random data with no timestamp component.
Are UUID v4 values sortable by creation time?
No. UUID v4 values are random and have no relationship to their creation time. For sortable IDs, consider UUIDs v1, v6, or v7.
Do UUID v4 values expose any system information?
No. UUID v4 consists entirely of random data with version and variant bits, providing full privacy with no system information leakage.