What is a UUID?

UUIDs explained: the 5-part structure, v1 vs v4 vs v7, uniqueness guarantees, and when to choose UUID over auto-increment.

5 min read·Updated June 2026

A UUID (Universally Unique Identifier) is a 128-bit label used to identify information in computer systems. Its design goal is that it can be generated independently — without a central authority — and still be unique across all space and time with overwhelming probability.

UUIDs are standardized in RFC 9562 and written as 32 hexadecimal characters separated by hyphens in the format xxxxxxxx-xxxx-Mxxx-Nxxx-xxxxxxxxxxxx, where M is the version digit and N encodes the variant.

Anatomy of a UUID

550e8400-e29b-41d4-a716-446655440000
time_low (32 bits)time_mid (16 bits)version + time_hi (16 bits)variant + clock_seq (16 bits)node (48 bits)

Total: 128 bits — 32 hex characters + 4 hyphens = 36 characters.

UUID versions

VersionHow generatedSortableUse when
v1Timestamp + MAC addressYes (roughly)You need time-ordered IDs and don't mind exposing MAC addresses
v3MD5 hash of a namespace + nameNoDeterministic UUIDs from a name (legacy)
v4122 bits of random dataNoGeneral purpose — the most widely used version today
v5SHA-1 hash of a namespace + nameNoDeterministic UUIDs from a name (preferred over v3)
v7Unix timestamp + random dataYes — lexicographicallyDatabase primary keys where chronological ordering matters

When in doubt, use v4 for general identifiers and v7 if you need UUIDs that sort correctly (e.g. as database primary keys with B-tree indexes).

UUID vs auto-increment IDs

UUID (v4)Auto-increment integer
Globally uniqueYesOnly within one table
Merge-safeYes — no conflicts when merging databasesNo — IDs collide
Predictable / guessableNo — opaque to outside usersYes — sequential
Index performanceSlower — random values cause B-tree fragmentationFaster — sequential
Storage16 bytes (binary) or 36 bytes (string)4–8 bytes
Expose record countNoYes — users can infer total records

UUID v7 largely eliminates the index performance issue because it is time-ordered, combining the global uniqueness of UUIDs with index performance close to auto-increment.

The nil and max UUIDs

Two special UUIDs are defined by the standard:

  • Nil UUID — all zeros: 00000000-0000-0000-0000-000000000000. Used as a "no value" sentinel, similar to null.
  • Max UUID — all fs: ffffffff-ffff-ffff-ffff-ffffffffffff. Useful as an upper bound in range queries.

Are UUIDs truly unique?

UUID v4 has 122 bits of randomness, giving approximately 5.3 × 1036 possible values. The probability of generating a duplicate when producing 1 billion UUIDs per second for 100 years is still negligible — far smaller than the probability of a hardware error occurring in the same period. In practice, UUID v4 collisions do not happen.

UUID v5 deterministically produces the same UUID for the same input, which is useful for stable, reproducible identifiers. It uses SHA-1 hashing internally, though the security concerns around SHA-1 collisions do not apply here since the goal is uniqueness, not collision resistance against adversaries.

Frequently asked questions