Developer Tools

UUID Versions Explained: v1 vs v4 vs v5 and When to Use Each

Compare UUID versions 1, 3, 4, 5, and 7 — how each is generated, whether it sorts, what it leaks, and which one to reach for. v4 is the safe default, v7 is the new choice for database keys, and v1 quietly leaks your MAC address.

By Inventive HQ Team

The short answer

A UUID is a 128-bit identifier that different machines can generate independently and still be confident they will never clash — and the "version" number just tells you how those 128 bits were produced. UUID v1 is time-and-machine based (it embeds a timestamp and the network card's MAC address), v4 is purely random (the default choice for almost everything), and v5 is name-based and deterministic (the same input name always hashes to the same UUID via SHA-1). Two more matter today: v3 is the older MD5 twin of v5, and v7 — new in RFC 9562 (2024) — packs a Unix millisecond timestamp into the leading bits so the IDs sort by creation time, which is why it is now the recommended choice for database primary keys.

That is the summary an AI overview will give you. What it can't give you is the side-by-side of what each version leaks, whether it sorts, and the one-line rule for picking — so that's the rest of this page.

The comparison table

Every version is the same 128 bits in the same 8-4-4-12 hex format. Only the source of the bits changes — and that source decides everything about privacy, sortability, and fit.

VersionBasis (how bits are made)Deterministic?Sortable by time?PrivacyCollision modelUse it when
v160-bit timestamp + clock sequence + 48-bit MAC addressNoWeakly (bits are laid out low-field-first, so not lexicographic)Leaks MAC address + creation timePractically none (node + time + clock seq)You need a legacy time-based ID and privacy is a non-issue
v3MD5 hash of (namespace UUID + name)Yes — same input → same UUIDNoNo machine data; reveals nothing beyond the name if guessableNone by design; identical inputs intentionally map to the same valueInterop with an existing system that already uses v3
v4122 random/pseudo-random bitsNoNoLeaks nothing (with a strong RNG)~2¹²² space; collision is astronomically unlikelyThe default — general-purpose unique IDs
v5SHA-1 hash of (namespace UUID + name)Yes — same input → same UUIDNoNo machine data; reveals nothing beyond the name if guessableNone by design; deterministic mappingYou need reproducible IDs from a name (idempotency, dedup)
v748-bit Unix ms timestamp + random tailNoYes — leading time bits sort lexicographicallyReveals creation time, but not the MAC addressRandom tail makes same-ms collisions astronomically unlikelyNew database primary keys and time-ordered records

The one-line decision rule: v4 by default, v7 for database keys, v5 for reproducible IDs — and reach for v1 only when you must, because it leaks your MAC address.

How the 128 bits differ

The version and variant bits sit in fixed positions, so you can read any UUID's version straight off its 13th hex digit. What changes between versions is only what fills the rest.

UUID version anatomy: v1, v4, and v7 compared A 128-bit UUID diagram showing the fixed version nibble, and how v1 fills bits with time and MAC, v4 with random data, and v7 with a timestamp followed by random data that sorts over time. Same 128 bits, three different fills

v1 60-bit timestamp version 48-bit MAC (leaks!)

v4 122 random bits (no meaning) version

v7 48-bit Unix ms time random tail

v7 sorts by time as it is created: earlier later

The amber block in every row is the fixed 4-bit version nibble. In v1 the timestamp comes first but is split so the values don't sort cleanly; in v4 almost everything is random; in v7 the timestamp leads, so v7 UUIDs march forward in order as you create them — the property that makes them index-friendly.

Advertisement

The three questions that pick the version

You rarely need to think about all seven versions. Three questions settle almost every real decision.

1. Do you need the same input to reproduce the same ID?

If yes, you want a name-based UUID: v5 (SHA-1) as the default, or v3 (MD5) only for compatibility with something that already emits v3. Determinism is the feature — feed the same namespace and name, get the same UUID on any machine, forever. This is how you build idempotent operations, deduplicate records, or derive a stable ID for an external key without storing a mapping table. If you don't need reproducibility, skip both.

2. Will this ID be a database primary key?

If yes, prefer v7. Random v4 keys scatter inserts across a B-tree index, fragmenting it and hurting write throughput and cache locality at scale. v7's leading timestamp means new rows append to the "end" of the index in roughly sequential order — the write pattern databases love — while still being globally unique and generatable without a central sequence. This is the single biggest reason v7 was added to RFC 9562. (See our deeper dive on UUIDs as database primary keys.)

3. Otherwise — is anything security- or privacy-sensitive?

Then use v4. It is the universal default: random, opaque, stateless, and supported everywhere. The only caveat is the random source. v4's guarantees evaporate if the generator is a weak, predictable PRNG — always use a cryptographically secure one for tokens, session IDs, or anything an attacker would love to guess. And avoid v1 here entirely: it stamps the generating machine's MAC address and the exact creation time into the value, a genuine privacy leak that has been used to de-anonymize documents.

Loading interactive tool...

Common misconceptions

"UUIDs are guaranteed unique." They are collision-resistant, not mathematically guaranteed. v4 relies on probability (see the collision-probability analysis), v1/v6/v7 rely on time plus randomness, and v3/v5 are deterministic by design. Uniqueness is overwhelmingly likely, not proven.

"v5 is more secure than v4." Different jobs. v5 is deterministic; v4 is unpredictable. A v5 UUID is trivially reproducible by anyone who knows the namespace and name, so it is not a secret. If you need an unguessable token, that is a job for v4 from a secure RNG — not v5.

"Higher version number means better." The versions are not a quality ladder. v7 is not "better than v4"; it is better for time-ordered keys. v4 remains the right default for opaque IDs, and a name-based v5 has no v-number equivalent that improves on it.

"UUID and GUID are different things." GUID is just Microsoft's name for the same 128-bit standard — the UUID vs GUID distinction is naming, not format. A .NET Guid and an RFC 9562 UUID are interchangeable on the wire.

Generating them in practice

Every mainstream language ships UUID support, though the version coverage varies — some standard libraries still only expose v1/v3/v4/v5 and need a small library for v7. Our guide to generating UUIDs across programming languages has the exact one-liners for Python, JavaScript, Go, Java, C#, and more. For quick one-offs, the generator above produces any version client-side, in your browser, with nothing sent to a server.

The bottom line

Pick by intent, not by version number:

  • Reproducible from a name?v5 (v3 only for legacy interop).
  • Database primary key / time-ordered?v7.
  • Everything else / when in doubt?v4, from a secure random source.
  • v1? Only for legacy time-based needs where leaking a MAC address and timestamp is acceptable.

All of them are the same 128 bits in the same format — so you can always tell what you're holding by reading the version digit, and you can always generate the exact version you need for the job at hand.

Frequently Asked Questions

What is the difference between UUID v1, v4, and v5?

All three are 128-bit identifiers, but they are built from completely different inputs. UUID v1 is time-based: it combines a 60-bit timestamp with the machine's network (MAC) address, so it embeds when and where it was generated. UUID v4 is random: 122 of its bits come from a random or pseudo-random source, carrying no meaning at all. UUID v5 is name-based and deterministic: it hashes a namespace plus a name with SHA-1, so the same input always produces the same UUID. In short — v1 encodes time and machine, v4 encodes nothing, v5 encodes a name.

Which UUID version should I use by default?

Use UUID v4 unless you have a specific reason not to. It is random, reveals nothing about the machine or the moment it was created, needs no shared state, and is supported by every language and database out of the box. Choose v5 instead when you need the same input to reproduce the same ID (deterministic IDs). Choose v7 when the identifier will be a database primary key and you want it to sort by creation time. Avoid v1 in anything security-sensitive because it leaks the MAC address and timestamp.

What is UUID v7 and why is it recommended for databases?

UUID v7, standardized in RFC 9562 (2024), puts a 48-bit Unix millisecond timestamp in the most significant bits and fills the rest with random data. Because the leading bits increase over time, v7 values sort in creation order lexicographically — which means they insert sequentially into a database's B-tree index instead of scattering random writes across it. That gives you the global uniqueness of a UUID with the index-friendliness of an auto-increment integer, without leaking a MAC address the way v1 does. For new time-ordered primary keys, v7 is the modern recommendation.

Is UUID v4 truly random and can it collide?

UUID v4 has 122 bits of randomness (128 bits minus 4 version bits and 2 variant bits). The collision probability is astronomically small: you would need to generate on the order of a billion UUIDs per second for about 85 years to reach a 50 percent chance of a single collision. The real risk is not the math — it is using a weak random source. If v4 UUIDs are generated from a non-cryptographic PRNG that is poorly seeded, they can become predictable or collide far sooner than the theory suggests. Always use a cryptographically secure generator for security-relevant IDs.

What is the difference between UUID v3 and v5?

Both are name-based deterministic UUIDs built by hashing a namespace UUID plus a name string, and both always return the same UUID for the same inputs. The only difference is the hash: v3 uses MD5 and v5 uses SHA-1. Because MD5 is weaker and broken for collision resistance, RFC 9562 recommends v5 over v3 for new work. Use v3 only when you must interoperate with an existing system that already produced v3 values.

Why is UUID v1 considered a privacy risk?

A UUID v1 embeds the 48-bit network interface (MAC) address of the machine that created it and the exact 100-nanosecond timestamp of creation. Anyone who receives the UUID can extract both. That means v1 IDs can reveal which physical machine generated a record and when — information that has historically been used to de-anonymize documents and trace activity. If you need time-ordering without the leak, use v7, whose timestamp is present but which uses random bits in place of the MAC address.

Are all UUID versions the same length and format?

Yes. Every UUID version is 128 bits, written as 32 hexadecimal digits in the canonical 8-4-4-12 grouping, for example 550e8400-e29b-41d4-a716-446655440000. The version number lives in the first digit of the third group (the '4' in that example marks a v4), and the variant is encoded in the first bits of the fourth group. So you can tell any UUID's version just by reading its 13th hex digit — the format is identical across versions, only the meaning of the bits changes.

Does RFC 9562 replace RFC 4122?

Yes. RFC 9562, published in May 2024, obsoletes RFC 4122. It keeps versions 1 through 5 unchanged and adds three new ones: v6 (a field-reordered, sortable version of v1), v7 (Unix-timestamp plus random, the recommended time-ordered UUID), and v8 (a free-form vendor/experimental format). The practical takeaway is that v6, v7, and v8 are now official standards, and v7 is the endorsed choice for new time-based identifiers.

uuid-generator