Understanding UUID Version 4
UUID version 4 is defined in RFC-4122 and is the most commonly used UUID type. It relies on random or pseudo-random numbers for generation, providing excellent uniqueness without requiring coordination between systems.
UUID v4 Format
xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx
Example: 550e8400-e29b-41d4-a716-446655440000
^ ^
| └── Variant (8, 9, a, or b)
└── Version (always 4)
All UUID Versions Compared
| Version |
Name |
Generation Method |
Use Case |
| v1 |
Time-based |
Timestamp + MAC address |
When you need time ordering |
| v2 |
DCE Security |
Timestamp + MAC + UID/GID |
DCE environments (rare) |
| v3 |
MD5 Hash |
Namespace + name (MD5) |
Deterministic from input |
| v4 |
Random |
Cryptographic random |
General purpose (most common) |
| v5 |
SHA-1 Hash |
Namespace + name (SHA-1) |
Deterministic from input |
| v7 |
Time-ordered |
Timestamp + random |
Database indexing, sorting |
Why Choose UUID v4?
- Universal support - works in every language and platform
- Privacy - doesn't expose MAC address or timestamp
- Simple generation - no coordination needed between systems
- Cryptographically secure - unpredictable values
- Proven reliability - decades of production use
UUID v4 vs UUID v7
UUID v7 is a newer standard that provides time-ordered UUIDs. Choose based on your needs:
- Use v4 when order doesn't matter and you want maximum compatibility
- Use v7 when you need chronological ordering or better database index performance
Frequently Asked Questions
What is UUID version 4?
UUID version 4 (UUIDv4) is defined in RFC-4122 and uses random or pseudo-random numbers for generation. It contains 122 bits of randomness with 6 bits reserved for version (4) and variant information. It's the most commonly used UUID version.
What are the different UUID versions?
There are 5 main UUID versions: v1 (time-based with MAC address), v2 (DCE Security), v3 (MD5 hash), v4 (random), and v5 (SHA-1 hash). Version 4 is the most popular for general use. Version 7 is a newer time-ordered UUID gaining adoption.
How can I identify a UUID v4?
UUID v4 can be identified by the version digit in position 13 (after the second hyphen). For v4, this digit is always '4'. The format is: xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx where y is 8, 9, a, or b.
Should I use UUID v4 or v7?
Use UUID v4 for general purposes where ordering doesn't matter - it's universally supported and provides excellent randomness. Use UUID v7 when you need time-ordered UUIDs, better database indexing performance, or chronological sorting.