UUID Versions Explained — When to Use v4 vs v7

Published 2026-05-28

Your database needs unique IDs across distributed services that never coordinate. Auto-increment won't work. You need UUIDs — but which version?

There are five UUID versions in common use, and they solve different problems. Picking the wrong one can leak hardware addresses, fragment your database indexes, or produce collisions where you expected uniqueness. This guide breaks down every version so you can choose with confidence.

Generate UUIDs free →

UUID versions compared

This table is the quick reference. Details on each version follow below.

VersionHow generatedSortableWhen to useCollision risk
v1MAC address + timestampYes (by time)Legacy systems needing time orderingLow, but leaks MAC address
v3MD5 hash of namespace + nameNoDeterministic IDs from names (legacy)None (deterministic)
v4Random (122 random bits)NoGeneral purpose, most common~1 in 2.7 quintillion per pair
v5SHA-1 hash of namespace + nameNoDeterministic IDs (preferred over v3)None (deterministic)
v7Unix timestamp (ms) + randomYes (by time)New systems needing sortable IDsVery low

v1: timestamp + MAC address

Version 1 UUIDs embed the current timestamp and the generating machine's MAC address. This makes them naturally sortable by creation time, which was useful for certain legacy databases. The downside is that the MAC address is encoded right in the UUID, which means anyone who reads the ID can identify the hardware that created it. For internal systems behind a firewall this may not matter, but for public-facing IDs it's an unnecessary information leak. v1 has largely been superseded by v7, which provides the same time-sortability without exposing hardware details.

v3 and v5: deterministic, name-based

Versions 3 and 5 are deterministic: given the same namespace and name, they always produce the same UUID. v3 uses MD5 internally; v5 uses SHA-1. In practice, prefer v5 over v3 because SHA-1 is a stronger hash function (though neither is used here for cryptographic security — it's about reducing collision probability in the hash output).

Use name-based UUIDs when you need a stable, reproducible identifier derived from a human-readable string. For example, you might generate a v5 UUID from a URL so that the same URL always maps to the same UUID across different systems, without those systems needing to coordinate or share a database. This is useful for deduplication, content addressing, and idempotent API designs.

v4: random

Version 4 is the workhorse. It's 122 bits of randomness (the remaining 6 bits encode the version and variant), which means the probability of two randomly generated v4 UUIDs colliding is astronomically small. You'd need to generate about 2.7 quintillion UUIDs before you hit a 50% chance of a single collision. For virtually all practical purposes, v4 UUIDs are unique.

The trade-off is that v4 UUIDs are not sortable. If you insert them as primary keys in a B-tree-indexed database (which includes most relational databases), each new insert lands at a random position in the index. This causes page splits and fragmentation over time, which degrades write performance on large tables. For small-to-medium tables this is negligible; for tables with hundreds of millions of rows, it can matter.

v7: timestamp + random (the modern choice)

Version 7 is the newest addition, defined in RFC 9562. It embeds a Unix timestamp in milliseconds in the most significant bits, followed by random data. This gives you time-sortability (newer UUIDs sort after older ones) without leaking hardware information like v1 does. Because the timestamp occupies the high-order bits, v7 UUIDs inserted into a B-tree index land roughly in order, avoiding the fragmentation problem that plagues v4 in write-heavy databases.

If you're starting a new project and need both uniqueness and sortability, v7 is the right default.

UUID vs. auto-increment IDs

The choice between UUIDs and auto-incrementing integers depends on your architecture. Here's how they compare.

FeatureUUIDAuto-Increment
Uniqueness scopeGlobally unique — no coordination neededUnique within a single table/database
Database performancev4 causes B-tree fragmentation; v7 avoids itSequential inserts, optimal for B-tree indexes
URL safetySafe in URLs without encodingSafe, but sequential IDs are predictable
Information leakagev4/v5/v7 reveal nothing; v1 leaks MACReveals row count and creation order
Distributed generationAny node generates IDs independentlyRequires a central counter or coordination
Storage size16 bytes (128 bits)4 bytes (int) or 8 bytes (bigint)

Auto-increment is simpler and smaller. UUIDs are essential when you have multiple services, databases, or clients generating IDs independently — which is most distributed architectures. The storage overhead (16 bytes vs. 4 or 8) is real but rarely the bottleneck. The bigger concern is index fragmentation with v4, which is why v7 exists.

A common hybrid approach: use UUIDs as public-facing identifiers (API responses, URLs) and auto-increment integers as internal primary keys, with a unique index on the UUID column. This gives you the best of both worlds — fast sequential inserts and globally unique external IDs. You can Base64-encode UUIDs to shorten them in URLs if length is a concern.

Practical recommendations

For a deeper look at the tools adjacent to UUID generation — hashing, encoding, and other developer utilities — explore the rest of the ToolRack.


Built with vanilla HTML/JS. No frameworks, no backend, loads instantly.

Related tools

Joe — Software engineer with 20+ years of experience. Built ToolRack to provide fast, private tools without the bloat.