Understanding UUID v4: When and Why to Use Random Identifiers
Everything you need to know about UUID v4 — how they work, why they are practically unique, and best practices for using them in databases and APIs.
UUIDs (Universally Unique Identifiers) are 128-bit numbers used to identify resources without requiring a central authority. UUID v4, which uses random numbers, is by far the most popular version in modern software.
Anatomy of a UUID v4
A UUID v4 looks like this: 550e8400-e29b-41d4-a716-446655440000
It consists of 32 hexadecimal characters in 5 groups separated by hyphens: 8-4-4-4-12. Two specific bits indicate the version (4) and variant (RFC 4122):
- The 13th character is always
4(version) - The 17th character is always
8,9,a, orb(variant)
How Unique Are They Really?
UUID v4 has 122 random bits, giving 5.3 × 10³⁶ possible values. To have a 50% chance of a collision, you would need to generate approximately 2.71 × 10¹⁸ UUIDs — that's 2.71 quintillion.
To put it in perspective: if you generated 1 billion UUIDs per second, it would take about 85 years to reach a 50% collision probability.
UUID v4 vs. Alternatives
- UUID v1 — Based on timestamp + MAC address. Reveals machine identity and creation time.
- UUID v7 — Time-ordered UUIDs (new standard). Better for database indexing than v4.
- ULID — Lexicographically sortable, compatible with UUID format.
- nanoid — Shorter URL-friendly IDs. Not UUID-compatible but more compact.
When to Use UUID v4
- Distributed systems — No central ID authority needed
- API resource identifiers — Prevent ID enumeration attacks
- Database primary keys — Works across multiple servers/regions
- Idempotency keys — Prevent duplicate API operations
When NOT to Use UUID v4
- High-performance indexed columns — Random UUIDs cause B-tree fragmentation. Consider UUID v7 or ULID instead.
- User-facing identifiers — UUIDs are long and hard to communicate verbally.
- When ordering matters — UUID v4s are not time-ordered. Use UUID v7 or ULID.
Generate UUIDs Now
Use our UUID v4 Generator to generate cryptographically random UUIDs in bulk — entirely in your browser.