The bit layout of a UUID
Every UUID spends 4 bits on the version and 2 on the variant. The other 122 belong to the layout that the version names, and the tables below come straight out of the code this site runs.
A UUID is 128 bits and only six of them mean the same thing in every version. This page maps the rest: which bit ranges belong to the clock, the node, the hash or the randomness, for every layout RFC 9562 defines.
Open the converter: byte arrayNothing you paste leaves the browser.
On this page (9)
The six bits every version shares#
Bits 48 to 51 hold the version: that is the 13th hex digit of the printed form, the first character of the third group. Bits 64 and 65 hold the variant, at the top of the 17th hex digit, which is the first character of the fourth group. A 10xx pattern there means RFC 9562, which is why so many identifiers show 8, 9, a or b in that position.
RFC 9562 § 4.2 · Version FieldThe version field
RFC 9562 § 4.1 · Variant FieldThe variant field, and the patterns that are not this standard
Version 4: randomness with two holes in it#
| Field | Bits | Width | Kind |
|---|---|---|---|
| random | 0-47 | 48 | random |
| version | 48-51 | 4 | version |
| random | 52-63 | 12 | random |
| variant | 64-65 | 2 | variant |
| random | 66-127 | 62 | random |
The two fixed fields split the random space into three runs. That is why a v4 has 122 bits of entropy rather than 128, and why the 13th and 17th characters of a v4 never look random.
Version 7: milliseconds first#
| Field | Bits | Width | Kind |
|---|---|---|---|
| unix_ts_ms | 0-47 | 48 | timestamp |
| version | 48-51 | 4 | version |
| rand_a | 52-63 | 12 | random |
| variant | 64-65 | 2 | variant |
| rand_b | 66-127 | 62 | random |
The 48-bit millisecond field sits at the front, so byte order and time order agree and the identifiers sort. rand_a is nominally random, but a generator is allowed to spend it on sub-millisecond precision or on a counter that keeps identifiers made in the same millisecond in order.
RFC 9562 § 5.7 · UUID Version 7The v7 layout in the standard
Version 1: the clock that does not sort#
| Field | Bits | Width | Kind |
|---|---|---|---|
| time_low | 0-31 | 32 | timestamp |
| time_mid | 32-47 | 16 | timestamp |
| version | 48-51 | 4 | version |
| time_high | 52-63 | 12 | timestamp |
| variant | 64-65 | 2 | variant |
| clock_seq | 66-79 | 14 | clock sequence |
| node | 80-127 | 48 | node |
The clock is split into low, mid and high, and the high part comes last. Sorting v1 identifiers as strings therefore sorts by the low bits of the clock, which is close to sorting by nothing. Version 6 fixes exactly this by putting the pieces back in order.
Version 6: the same clock, reordered#
| Field | Bits | Width | Kind |
|---|---|---|---|
| time_high | 0-31 | 32 | timestamp |
| time_mid | 32-47 | 16 | timestamp |
| version | 48-51 | 4 | version |
| time_low | 52-63 | 12 | timestamp |
| variant | 64-65 | 2 | variant |
| clock_seq | 66-79 | 14 | clock sequence |
| node | 80-127 | 48 | node |
Versions 3 and 5: a hash with the middle cut out#
| Field | Bits | Width | Kind |
|---|---|---|---|
| sha1_high | 0-47 | 48 | hash of the name |
| version | 48-51 | 4 | version |
| sha1_mid | 52-63 | 12 | hash of the name |
| variant | 64-65 | 2 | variant |
| sha1_low | 66-127 | 62 | hash of the name |
A v5 is a SHA-1 of the namespace and the name, truncated to 128 bits, with the version and variant bits overwritten. A v3 is the same with MD5. Six bits of the digest are lost, which is intentional and harmless: what remains is still a deterministic function of the input.
RFC 9562 § 6.5 · Name-Based UUID GenerationHow a name-based identifier is derived
Version 8: nothing but the six bits#
| Field | Bits | Width | Kind |
|---|---|---|---|
| custom_a | 0-47 | 48 | random |
| version | 48-51 | 4 | version |
| custom_b | 52-63 | 12 | random |
| variant | 64-65 | 2 | variant |
| custom_c | 66-127 | 62 | random |
Version 8 exists so that a custom layout can still be a valid UUID. The standard claims the version and variant bits and says nothing about the other 122, which makes v8 the right home for identifiers that embed a shard number, a tenant, or a different clock.
RFC 9562 § 5.8 · UUID Version 8The deliberately empty specification for v8
Questions people actually ask#
Which character of a UUID is the version?
The 13th hex digit, which is the first character of the third group. A v4 shows a 4 there and a v7 shows a 7.
Why does the fourth group almost always start with 8, 9, a or b?
Those are the values whose top two bits are 10, which is the variant that marks an RFC 9562 identifier.
How much entropy does a v4 actually have?
122 bits. The version and variant take six of the 128.
Related#
Browse the reference
Start here
Making and converting in bulk
Converting a UUID
Reading one
The versions, in order
In a database
ULID and the alternatives
Running the tool