UUID · 122

UUID v4

122 random bits — the default choice for identifiers that need no ordering.

Key facts

Random bits122
Fixed bits4 version + 2 variant
SourceCryptographic RNG expected
OrderingNone
Collision boundBirthday bound near 2^61 values
StandardRFC 9562

Why 122 bits is enough

Four bits are fixed for the version and two for the variant, leaving 122 random bits. To reach a 50% chance of any collision you would need on the order of 2^61 identifiers. At a billion UUIDs per second that is still centuries of generation, so v4 is safe for distributed systems without coordination.

The indexing cost

Random values scatter across a B-tree index, which causes page splits and cache misses at high insert rates. That is the main reason time-ordered v7 exists. For low-volume tables v4 is fine; for append-heavy tables v7 usually wins on write performance.

Frequently asked questions

Can two v4 UUIDs collide?

Mathematically yes, practically no at any realistic scale. The probability is far below hardware failure rates.

Does v4 leak a timestamp?

No. It contains no time, host or sequence information.

Is v4 a good primary key?

It is correct but not index-friendly. Prefer v7 or a sequential key when insert volume is high.

New tools, straight to your inbox

One short email when we add tools worth using. No spam, unsubscribe anytime.