What is UUID?

A UUID (Universally Unique Identifier) is a 128-bit label used to uniquely identify information in computer systems. Formatted as 32 hexadecimal digits in five groups separated by hyphens (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx), a UUID is designed to be unique across space and time without a central registration authority.

UUID versions differ in how the 128 bits are generated. UUID v1 embeds a timestamp and the generating machine's MAC address, making UUIDs sortable by creation time but leaking hardware information. UUID v3 and v5 are name-based — they deterministically hash a namespace UUID and a name string (using MD5 for v3, SHA-1 for v5), so the same input always produces the same UUID. UUID v4 generates all 122 significant bits randomly, making collisions astronomically unlikely (the probability of a collision is negligible until you have generated approximately 2.7 × 10^18 UUIDs). UUID v7, proposed in 2022 (RFC 9562), uses a millisecond Unix timestamp in the most significant bits followed by random bits, making v7 UUIDs both random and lexicographically sortable by creation time — ideal for database primary keys.

The probability of a UUID v4 collision when generating 1 billion UUIDs per second for 100 years is roughly 50% at 10^15 UUIDs — effectively zero for any practical application.

UUIDs are used as database primary keys (replacing sequential integers to avoid enumeration, allow distributed generation, and merge databases without ID conflicts), correlation IDs in distributed tracing, idempotency keys in payment APIs, session identifiers, and file names. The lack of a central authority means any node can generate a UUID independently with essentially no collision risk.

UUID v7 is increasingly preferred over v4 for database keys because its sortable prefix makes B-tree index insertions sequential rather than random, dramatically improving write performance and cache locality for large tables.

quickhelp.dev's UUID Generator generates v4 and v7 UUIDs instantly and explains the structure of each.

See also

We use cookies to serve ads and measure traffic. Cookie policy · Privacy policy