UUID Format & Size Explained
Every UUID is exactly 128 bits, but it can be written, stored, and transmitted in several different ways. Here's what each part means.
Anatomy of the string format
3fa85f64-5717-4562-b3fc-2c963f66afa6 \______/ \__/ \__/ \__/ \________/ 8 hex 4 hex 4 hex 4 hex 12 hex = 32 hex digits + 4 dashes = 36 characters
32 hexadecimal digits encode 128 bits (4 bits per hex digit × 32 = 128). The dashes are purely visual separators defined by the standard - they carry no information.
Storage size
| Representation | Size | Notes |
|---|---|---|
| Raw binary (16 bytes) | 128 bits / 16 bytes | Most space-efficient - used internally by databases (e.g. MySQL's BINARY(16), PostgreSQL's uuid type) |
| Canonical string (36 chars) | 36 bytes as ASCII / UTF-8 | e.g. 3fa85f64-5717-4562-b3fc-2c963f66afa6 - what you'll see in JSON, logs, URLs |
| No-dash string (32 chars) | 32 bytes | Same data, slightly more compact, less common |
| Braced (38 chars) | 38 bytes | {3fa85f64-5717-4562-b3fc-2c963f66afa6} - Windows/COM convention |
Storing UUIDs as their 36-character string form in a database uses more than double the space of storing the raw 16 bytes, and string comparison is slower than fixed-width binary comparison. For high-volume tables, store as binary where possible - see the MySQL UUID page for a worked example with UUID_TO_BIN().
What the version and variant bits look like
Two specific positions in the string are reserved, regardless of version:
- The first character of the third group is always the version number (
1–8). - The first character of the fourth group is always
8,9,a, orb- encoding the "variant," which marks this as an RFC-compliant UUID.
The odds of a collision
For UUID v4, 122 bits are random. Using the birthday-problem approximation, the number of UUIDs you'd need to generate for a 50% chance of at least one collision is roughly:
~2.71 × 10^18 (2.71 quintillion) UUIDs
To put that in perspective: generating 1 billion UUID v4 values per second, it would take about 85 years to reach a 50% chance of a single collision. For UUID v7, only 74 bits are random (the rest is timestamp), which still gives roughly 1-in-9.4-sextillion odds within the same millisecond - more than sufficient for virtually any real-world system.
Nil and max UUIDs
Two special values are reserved by the standard:
- Nil UUID:
00000000-0000-0000-0000-000000000000- all bits zero, used to represent "no value." - Max UUID:
ffffffff-ffff-ffff-ffff-ffffffffffff- all bits one, used as a sentinel upper bound.
Try generating any of these formats with the UUID/GUID generator above.