A UUID (Universally Unique Identifier) is a 128-bit number usually written as a 36-character string of hex digits and hyphens. It answers one question: how do I give every row, request or message a unique ID without asking a central server for permission first? This guide explains the format, walks through the versions that matter in 2026, and tells you when a UUID is the right answer and when it is a performance trap.
Anatomy of a UUID
A canonical UUID has five hyphen-separated groups in an 8-4-4-4-12 layout. In 123e4567-e89b-12d3-a456-426614174000 the 13th character (2, the first digit of the third group) is the version nibble, and the first character of the fourth group (a) is the variant nibble that marks it as RFC 4122. Recognizing these two nibbles means you can identify the version of any UUID at a glance, which usually matters more than the version itself.
The versions, compared
| Version | Source of uniqueness | Use it for |
|---|---|---|
| v1 | Timestamp + MAC address | Legacy systems; avoid for user-facing IDs (leaks time and hardware) |
| v3 / v5 | Name-based hash (MD5 / SHA-1) | Stable IDs derived deterministically from a name |
| v4 | 122 bits of randomness | The default everywhere; database keys, request IDs |
| v6 / v7 | Timestamp + random tail | Time-ordered IDs that stay friendly to indexes |
Versions 2 and 8 are rare: v2 is a DCE-security variant built on v1, and v8 is a free-form 128 bits for custom schemes.
Version 4: the dependable default
Version 4 fixes the version nibble to 4 and the variant nibble to 2 (binary 10), then fills the remaining 122 bits from a cryptographically secure random source. Because the generation is stateless, any machine can mint UUIDs without coordination — that is the entire point. The collision math is worth knowing exactly once: with 122 random bits, the birthday-bound probability of any collision after n draws is roughly P(n) close to (n squared) over (2 to the 123). Generate 1 billion UUIDs and the odds of a single collision are about 1 in 10 to the 19th — far smaller than your hardware failing mid-write.
Version 7: the relational-database fix
Version 7 fronts the UUID with a 48-bit Unix timestamp in milliseconds followed by random bits. Because every new value is greater than the last, inserts land at the tail of a tree index instead of scattering across it. On a clustered index over 10 million rows, that difference is large: v4 inserts can trigger page splits across the whole tree, while v7 appends near the newest leaf and keeps the index compact. If your database generates its own IDs, prefer v7 when you must store UUIDs at scale.
When a UUID is not what you need
- Tiny lookup tables. An 8-byte bigint identity column beats 16 bytes of UUID in storage, index size and copy cost.
- Ordering concerns. Plain v4 sorts randomly. Use v7 when insertion order should match ID order.
- Enumerate-safe IDs. A v1 UUID leaks the MAC address and creation time of its host. Use v4 or v7 instead for anything user-visible.
- Deterministic keys. If the same logical entity must always map to the same ID, a name-based v5 hash is what you want, not a random UUID that differs on every call.
UUID vs hashing vs random numbers
The three tools are not interchangeable. A hash such as SHA-256 is deterministic — the same input always yields the same fixed-size output, which makes it ideal for cache keys and deduplication. The Hash Generator produces those fingerprints in SHA-1, SHA-256, MD5 and more. A UUID is a structure: 128 bits with version and variant semantics, generated so uniqueness is effectively guaranteed. A plain random number is a much smaller space — 32 or 64 bits — and only fits when collisions are acceptable or the range is tiny, which the Random Number Generator covers without any of UUID's uniqueness claims.
Generate and format them properly
The UUID Generator produces valid v4 and v7 identifiers in lowercase, uppercase, and with or without hyphens, plus the compact 32-character form used in some storage engines. For any situation that needs a deterministic identifier — a deduplication key, a content hash — reach for the Hash Generator instead, and for arbitrary small ranges use the Random Number Generator. Each tool is the right one for a different definition of "unique."
Frequently asked questions
Will I ever hit a UUID collision in practice? Not through randomness. With a billion v4 tokens the collision odds are on the order of 1 in 10 to the 19th, which is vastly lower than the failure rate of the storage underneath you.
Should I store UUIDs as text or binary? As binary if the database supports it — a UUID stored as 16 raw bytes is half the size of the 32-character hex string and avoids parsing overhead. Keep the text form only in logs and APIs.
What is the difference between a UUID and a GUID? In practice, none. GUID is Microsoft's name for the same RFC 4122 format; the two are interchangeable in interoperability layers, with only minor byte-order caveats in the older v1 encoding.