UUID Format Explained (8-4-4-4-12)
Understand the UUID string format: 32 hex digits in 8-4-4-4-12 grouping, 128 bits total. Learn what each section encodes and how to read version and variant.
Detailed Explanation
A UUID (Universally Unique Identifier) is a 128-bit value typically represented as 32 hexadecimal digits separated by four hyphens in the pattern 8-4-4-4-12: xxxxxxxx-xxxx-Mxxx-Nxxx-xxxxxxxxxxxx.
Anatomy of the string format:
550e8400-e29b-41d4-a716-446655440000
| | | | | | | | | |
| 8 | | 4| | 4| | 4| | 12 |
| | | | | | | | | |
time_lo mid ver var node/random
+hi +seq
- Group 1 (8 hex = 32 bits): In v1, this is
time_low. In v7, it is the high 32 bits of the timestamp. In v4, it is random. - Group 2 (4 hex = 16 bits): In v1, this is
time_mid. In v7, it is the low 16 bits of the timestamp. In v4, it is random. - Group 3 (4 hex = 16 bits): The first digit (
M) is the version number. The remaining 12 bits vary by version. - Group 4 (4 hex = 16 bits): The first digit (
N) encodes the variant in its high bits. For standard UUIDs, the first hex digit is8,9,a, orb(binary starts with10). The remaining bits are clock sequence or random. - Group 5 (12 hex = 48 bits): In v1, this is the node ID (MAC address). In v4 and v7, it is random data.
How to read the version: Look at the first character of the third group. A 4 means v4, a 7 means v7, a 1 means v1, and so on.
How to read the variant: Look at the first character of the fourth group. If it is 8, 9, a, or b, the UUID follows the RFC 4122/9562 variant. Values 0-7 indicate the legacy NCS variant, and c-f indicate the legacy Microsoft variant.
Case sensitivity: UUIDs are case-insensitive per the RFC. Both 550E8400-E29B-41D4-A716-446655440000 and 550e8400-e29b-41d4-a716-446655440000 represent the same UUID. Most implementations output lowercase, and RFC 9562 recommends lowercase for new implementations.
Alternative representations:
- Without hyphens:
550e8400e29b41d4a716446655440000(32 chars) - URN format:
urn:uuid:550e8400-e29b-41d4-a716-446655440000 - Binary: 16 raw bytes (most compact, used in databases)
- Base64: 22 characters (e.g.,
VQ6EAOKbQdSnFkRmVUQAAA==)
Use Case
Understanding the UUID format is essential for debugging distributed systems: by reading the version digit and variant bits, you can quickly determine how a UUID was generated and what information it encodes.