Reference

UUID Versions Explained: v1 vs v4 vs v7 (Which Should You Use?)

๐Ÿ“… September 2026โฑ๏ธ 6 min read
"UUID" isn't one format โ€” it's a family of formats that all look similar (32 hex digits, five groups) but are generated completely differently. Picking the wrong version can leak information or hurt database performance. Here's what each version actually does.

UUID Structure, Quickly

Every UUID is a 128-bit number, conventionally displayed as 32 hexadecimal characters in the pattern xxxxxxxx-xxxx-Mxxx-Nxxx-xxxxxxxxxxxx. The M digit tells you the version (1, 3, 4, 5, or 7), and the first bits of N tell you the "variant" (almost always the standard RFC 4122 variant). You don't need to memorize this โ€” just know that the version digit is what determines how the ID was actually generated, and that changes what it's safe to use for.

The Versions That Matter

UUID v1 Timestamp + MAC

Generated from the current timestamp (100-nanosecond precision) plus the network card's MAC address, plus a small random "clock sequence" to avoid collisions if the clock moves backward. This makes v1 IDs sortable by creation time and traceable to a specific machine โ€” which is exactly the problem: it leaks your server's MAC address and the precise moment the ID was created. Rarely a good choice for anything public-facing today.

UUID v4 Pure Random

122 bits of cryptographically secure randomness (the remaining 6 bits are fixed to mark the version/variant). No timestamp, no MAC address, no pattern to reverse-engineer. This is the default most languages and frameworks use when you call uuid() without arguments โ€” crypto.randomUUID() in JavaScript, uuid4() in Python, gen_random_uuid() in Postgres. Use it whenever you just need a safe, private, collision-resistant ID and don't care about sort order.

UUID v7 Timestamp-Ordered, Random Tail

The newest version (standardized in 2024). The first 48 bits are a millisecond Unix timestamp, and the rest is random. This gives you the privacy of v4 (no MAC address, no way to reconstruct exact nanosecond timing) combined with the practical benefit of v1: IDs sort roughly in creation order. That matters a lot for database performance โ€” inserting monotonically-increasing keys into a B-tree index avoids the page-splitting and fragmentation that fully random v4 keys cause at scale. If you're choosing a UUID format for a new high-write-volume table today, v7 is usually the better call.

UUID v3 / v5 Name-Based, Deterministic

These hash a namespace + a name (v3 uses MD5, v5 uses SHA-1) to produce the same UUID every time for the same input. Useful when you need a stable, reproducible ID derived from something else โ€” e.g. generating a consistent UUID from a URL or email address without a database lookup. Not random, and not meant to be.

Quick Comparison

VersionSortable by time?Leaks info?Best for
v1YesMAC address + exact timestampLegacy systems only
v4NoNothingGeneral-purpose IDs, tokens, public-facing keys
v7Yes (coarse, ms)Approximate creation time onlyDatabase primary keys at scale
v3/v5NoNothing (but deterministic)Reproducible IDs from a known input
๐Ÿ’ก Rule of thumb

If you're not sure which to pick: use v4. It's the safe, general-purpose default supported everywhere. Only reach for v7 once you've confirmed insert performance on a UUID-keyed table is actually a bottleneck, and only reach for v1 if you're integrating with a legacy system that specifically requires it.

Generate UUID v4 Now

Bulk-generate up to 50 random UUID v4 identifiers, free and instant, entirely in your browser.

Open UUID Generator โ†’

Frequently Asked Questions

Can two UUID v4s ever collide?
Mathematically possible but practically irrelevant: with 122 random bits, you'd need to generate roughly 2.7 quintillion UUIDs before the probability of a single collision reaches 50%. No real-world system generates anywhere near that volume.
Is UUID v7 supported in Postgres and MySQL yet?
Postgres added native uuidv7() support in version 18. For earlier Postgres and for MySQL, you can generate v7 UUIDs in application code (most UUID libraries added v7 support in 2024โ€“2025) and store them as a standard UUID/CHAR(36) column.
Should I use UUID or an auto-increment integer for my primary key?
Auto-increment integers are smaller and faster to index, but they leak row counts and require a central sequence, which doesn't work well across distributed writers. UUIDs (especially v7) let any client or server generate a valid, collision-free ID independently โ€” the right trade-off for distributed systems, offline-first apps, or public APIs where you don't want to expose "customer #1,204".