UUID Format — Understanding the 128-Bit Unique Identifier Structure
UUIDs follow a specific 8-4-4-4-12 hexadecimal format defined by RFC 4122. Here's what each section of a UUID means, the version and variant bits, and how to parse UUID fields.
A UUID (Universally Unique Identifier) is a 128-bit value formatted as 32 hexadecimal digits in five groups separated by hyphens. Every UUID follows the same format defined in RFC 4122, with specific bits indicating the version (1–8) and variant (RFC 4122 vs legacy systems).
Use the UUID Generator to generate valid UUID v4 identifiers.
UUID format breakdown
xxxxxxxx-xxxx-Mxxx-Nxxx-xxxxxxxxxxxx
│ │ │ │ └──────────────── 48 bits (node/random)
│ │ │ └──────────────────── 16 bits (clock seq / random, N = variant)
│ │ └───────────────────────── 16 bits (time_mid / random, M = version)
│ └────────────────────────────── 16 bits (time_mid)
└─────────────────────────────────────── 32 bits (time_low)
Example: f47ac10b-58cc-4372-a567-0e02b2c3d479
| Field | Value | Bits | Meaning |
|---|---|---|---|
| time_low | f47ac10b | 32 | Low 32 bits of timestamp (v1) or random (v4) |
| time_mid | 58cc | 16 | Middle 16 bits of timestamp (v1) or random (v4) |
| time_hi_and_version | 4372 | 16 | High 12 bits of timestamp (v1) or random (v4); 4 = version |
| clock_seq_hi_and_reserved | a5 | 8 | 2 variant bits + 6 clock seq bits or random |
| clock_seq_low | 67 | 8 | Clock sequence low bits (v1) or random (v4) |
| node | 0e02b2c3d479 | 48 | MAC address (v1) or random (v4) |
Version bits (M)
The 13th hex digit (first digit of the third group) indicates the UUID version:
f47ac10b-58cc-4372-a567-0e02b2c3d479
↑
4 = UUID version 4
Valid version values:
1— time-based (v1)2— DCE security (v2, rare)3— MD5 name-based (v3)4— random (v4)5— SHA-1 name-based (v5)6— reordered time (v6, draft)7— Unix timestamp (v7, RFC 9562)8— custom (v8, RFC 9562)
Variant bits (N)
The 17th hex digit (first digit of the fourth group) indicates the UUID variant:
f47ac10b-58cc-4372-a567-0e02b2c3d479
↑
a = 1010 binary → variant bits = 10 → RFC 4122
The variant field uses the high bits of the clock_seq_hi_and_reserved byte:
| High bits | Variant | Description |
|---|---|---|
0xxx | 0 | Reserved (NCS backward compatibility) |
10xx | 2 | RFC 4122 / Leach-Salz (standard) |
110x | 6 | Microsoft (legacy COM/DCOM) |
111x | 7 | Reserved |
For valid RFC 4122 UUIDs, the 17th digit must be 8, 9, a, or b (binary 10xx):
8=10009=1001a=1010b=1011
UUID representations
The same UUID in different formats:
Standard (with hyphens): f47ac10b-58cc-4372-a567-0e02b2c3d479
Compact (no hyphens): f47ac10b58cc4372a5670e02b2c3d479
Uppercase: F47AC10B-58CC-4372-A567-0E02B2C3D479
URN format: urn:uuid:f47ac10b-58cc-4372-a567-0e02b2c3d479
Binary (16 bytes): f4 7a c1 0b 58 cc 43 72 a5 67 0e 02 b2 c3 d4 79
Integer: 324605033424591895846014609927575858297
Parsing UUID fields in code
JavaScript
function parseUUID(uuid) {
const clean = uuid.replace(/-/g, '');
return {
timeLow: clean.slice(0, 8),
timeMid: clean.slice(8, 12),
timeHighAndVersion: clean.slice(12, 16),
clockSeqHiAndReserved: clean.slice(16, 18),
clockSeqLow: clean.slice(18, 20),
node: clean.slice(20, 32),
version: parseInt(clean[12], 16),
variant: getVariant(parseInt(clean[16], 16)),
};
}
function getVariant(nibble) {
if ((nibble & 0x8) === 0) return 'NCS'; // 0xxx
if ((nibble & 0xc) === 0x8) return 'RFC4122'; // 10xx
if ((nibble & 0xe) === 0xc) return 'Microsoft'; // 110x
return 'Reserved';
}
const parsed = parseUUID('f47ac10b-58cc-4372-a567-0e02b2c3d479');
console.log(parsed.version); // 4
console.log(parsed.variant); // "RFC4122"
Python
import uuid
u = uuid.UUID('f47ac10b-58cc-4372-a567-0e02b2c3d479')
print(u.version) # 4
print(u.variant) # UUID.RFC_4122
print(u.hex) # "f47ac10b58cc4372a5670e02b2c3d479"
print(u.bytes) # b'\xf4z\xc1\x0bX\xccCr\xa5g\x0e\x02\xb2\xc3\xd4y'
print(u.int) # 324605033424591895846014609927575858297
print(u.urn) # "urn:uuid:f47ac10b-58cc-4372-a567-0e02b2c3d479"
# Compare UUIDs:
u1 = uuid.UUID('f47ac10b-58cc-4372-a567-0e02b2c3d479')
u2 = uuid.UUID('f47ac10b-58cc-4372-a567-0e02b2c3d479')
print(u1 == u2) # True
# UUID from integer:
u = uuid.UUID(int=324605033424591895846014609927575858297)
print(str(u)) # "f47ac10b-58cc-4372-a567-0e02b2c3d479"
UUID validation
// Validate any RFC 4122 UUID:
const UUID_REGEX = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
// Validate UUID v4 specifically:
const UUID_V4_REGEX = /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
function isValidUUID(str) {
return UUID_REGEX.test(str);
}
function isUUIDv4(str) {
return UUID_V4_REGEX.test(str);
}
// Edge cases:
isValidUUID('F47AC10B-58CC-4372-A567-0E02B2C3D479'); // true (uppercase)
isValidUUID('f47ac10b58cc4372a5670e02b2c3d479'); // false (no hyphens)
isValidUUID('00000000-0000-0000-0000-000000000000'); // true (nil UUID)
The nil UUID
The nil UUID is all zeros:
00000000-0000-0000-0000-000000000000
Used to represent “no UUID” or an unset UUID value. Similar to null or 0 for integer IDs. Databases that use UUID primary keys can store the nil UUID as a sentinel value.
Storage formats
String (varchar): 36 characters including hyphens. Human-readable, searchable, portable. Most common for debugging and logging.
Compact string: 32 characters, no hyphens. Slightly smaller, still portable.
Binary (16 bytes): Most space-efficient. Native UUID type in PostgreSQL and MySQL 8. Not human-readable but faster for comparisons and indexing.
-- PostgreSQL: native UUID type (16 bytes)
id UUID DEFAULT gen_random_uuid()
-- MySQL: binary for performance
id BINARY(16) DEFAULT (UUID_TO_BIN(UUID()))
-- Display binary as UUID string:
SELECT BIN_TO_UUID(id) FROM users;
Related tools
- UUID Generator — generate UUID v4 values
- UUID v4 Generator — UUID v4 explained
- NanoID vs UUID — comparing ID formats
Related posts
- UUID v4 vs v7 for Databases: The Benchmark You Need — UUID v4 fragments your primary key index. UUID v7 fixes it with millisecond-orde…
- CUID2 — Collision-Resistant IDs Better Than UUID v4 — CUID2 generates secure, URL-safe, database-friendly IDs with better collision re…
- NanoID vs UUID — Which Unique ID Generator Should You Use? — NanoID generates shorter, URL-safe unique IDs using a custom alphabet. UUID v4 i…
- ULID Generator — Universally Unique Lexicographically Sortable Identifiers — ULID is a 26-character sortable unique identifier that embeds a millisecond time…
- UUID Generator Online — Generate UUID v4 and v7 Instantly — A UUID is a 128-bit identifier formatted as 32 hex digits in 5 groups. UUID v4 u…
Related tool
Generate UUID v4 and v7 identifiers in bulk.
Written by Mian Ali Khalid. Part of the Dev Productivity pillar.