Complete Guide to UUID Versions

Quick Answer

Which UUID version should you use?

  • UUID v7 - best default for new database-backed applications
  • UUID v4 - best for broad compatibility and simple random identifiers
  • UUID v5 - use when the same namespace + name must always produce the same UUID
  • UUID v1 - primarily for legacy compatibility
  • UUID v6 - time-ordered alternative for systems based on the UUID v1 model
  • UUID v8 - application-defined formats when you have a specific reason to customize the layout

UUID Version Summary

UUIDs (Universally Unique Identifiers) are standardized 128-bit identifiers defined by RFC 9562 (which obsoletes RFC 4122). Each UUID version was designed for different requirements, such as randomness, determinism, chronological ordering, or custom data layouts.

Although all UUIDs share the same 128-bit structure and text format, each version uses those bits differently for timestamps, randomness, hashes, node identifiers, or application-defined data. Choosing the right version matters more than it might seem: the wrong choice can leak information (like a device's MAC address or creation time), hurt database performance through fragmented indexes, or make it impossible to regenerate the same identifier deterministically when you need to. The table below is a quick-reference starting point - the sections further down explain the reasoning behind each version.


Version Primary Purpose Generation Method Sortable Deterministic Common Today
UUID v1 Legacy unique IDs Timestamp + Node ID ⭐⭐
UUID v3 Stable identifiers MD5 Hash ⭐⭐
UUID v4 Random identifiers Cryptographically secure random numbers ⭐⭐⭐⭐⭐
UUID v5 Stable identifiers SHA-1 Hash ⭐⭐⭐
UUID v6 Time-ordered Reordered timestamp + random/node ⭐⭐
UUID v7 Modern databases Unix timestamp + random ⭐⭐⭐⭐
UUID v8 Custom applications User-defined layout Depends Depends

Comparison

Beyond just "which version is best," the properties in this table decide why a version fits a given job. Randomness protects against guessability and information leakage; time-basis and sortability matter almost entirely for database write performance; and determinism is what lets you compute the same UUID twice from the same input, which is essential for de-duplication and idempotent systems. Use this table to weigh trade-offs side by side before picking a version for a new system.

Property UUID v1 UUID v3 UUID v4 UUID v5 UUID v6 UUID v7 UUID v8
RFC Standard
128-bit Identifier
Random Partial Partial Depends
Time-based Depends
Sortable Depends
Deterministic Depends
Database Friendly ⭐⭐ ⭐⭐ ⭐⭐ ⭐⭐ ⭐⭐⭐⭐ ⭐⭐⭐⭐⭐ Depends
Privacy Friendly ⭐⭐⭐⭐ ⭐⭐⭐⭐⭐ ⭐⭐⭐⭐ ⭐⭐ ⭐⭐⭐ Depends

Structure Comparison

Every UUID version uses the 128-bit UUID structure differently. Timestamp-based versions allocate bits to time information, hash-based versions use namespace-derived values, random versions use random data, and UUID v8 leaves much of the layout application-defined.. Timestamp-based versions trade some randomness for chronological order; hash-based versions trade randomness entirely for repeatability; and UUID v8 gives up a standard layout altogether in exchange for total flexibility. Understanding what data actually goes into a UUID helps explain why, for example, UUID v1 can leak hardware information while UUID v4 can't.

Version Timestamp Random Data Hash Namespace Node ID Custom Data
UUID v1
UUID v3 MD5
UUID v4
UUID v5 SHA-1
UUID v6 Partial Optional
UUID v7 Unix Time
UUID v8 Depends Depends Depends Depends Depends

When to Use Each Version

The "right" UUID version depends less on the technology and more on what your system actually needs from its identifiers. If you just need a unique value with no other requirements, UUID v4 is the safe default almost everyone reaches for. If those identifiers are also primary keys in a high-write database, the sort-order versions (UUID v7, or UUID v6 where broader compatibility is needed) will noticeably reduce index fragmentation. And if you need to derive the same identifier repeatedly from the same input - say, generating a stable ID for a URL or email address - only the deterministic hash-based versions (UUID v3/UUID v5) will do that.

Use Case Recommended Version
General-purpose applications UUID v4
New database applications UUID v7
Sequential inserts UUID v7 or UUID v6
Deterministic identifiers UUID v5
Legacy compatibility UUID v1
Custom implementation UUID v8

UUID v1

UUID v1 combines a timestamp with a node identifier, historically a MAC address. It was one of the four original versions defined back in RFC 4122 and remains common in older enterprise systems, directory services, and infrastructure that predates the newer time-ordered versions. Because the timestamp and node ID are baked directly into the identifier, a UUID v1 value can be parsed back to reveal roughly when - and sometimes on which machine - it was generated, which is a meaningful privacy trade-off for public-facing systems.

Advantages

  • Chronologically ordered
  • Very low collision probability
  • Supported by many older systems

Disadvantages

  • Can reveal creation time
  • May expose hardware information
  • Less privacy friendly

UUID v3

UUID v3 creates deterministic UUIDs by hashing a namespace and name using MD5. Feeding the same namespace/name pair into the algorithm will always produce the identical UUID, which makes it useful for generating stable IDs from existing values (like a domain name or file path) without needing to store a lookup table. Its main drawback is its reliance on MD5, a hashing algorithm considered cryptographically weak for security-sensitive purposes - for new deterministic UUIDs, UUID v5 is generally the safer choice.

Advantages

  • Same input always produces the same UUID
  • Useful for names and identifiers

Disadvantages

  • Uses MD5
  • Not random

UUID v4

UUID v4 is generated using cryptographically secure random numbers, with no timestamp, hash, or hardware data embedded anywhere in the value. Approximately 122 bits are random, giving an astronomically low chance of collisions - in practical terms, you could generate billions of UUID v4 values and still have a negligible chance of a duplicate. This is why it's the default choice across nearly every programming language's standard library and the most widely recognized UUID format in general use today.

Advantages

  • Most widely supported
  • Excellent privacy
  • Extremely low collision probability
  • Very easy to generate

Disadvantages

  • Not sortable
  • Random inserts can fragment database indexes

UUID v5

UUID v5 is deterministic like UUID v3 but uses SHA-1 instead of MD5, making it the more modern and generally preferred option when you need repeatable, name-based identifiers. It's frequently used to generate consistent IDs for resources identified by a URL, DNS name, or other namespaced string, so that the same input reliably maps to the same UUID across different systems or services without any coordination needed.

Advantages

  • Stable identifiers
  • Uses SHA-1 instead of MD5

Disadvantages

  • Not random
  • Not sortable

UUID v6

UUID v6 rearranges the UUID v1 timestamp fields so identifiers sort naturally in ascending order, addressing one of UUID v1's biggest practical weaknesses. It was introduced specifically as a bridge for systems that need time-ordered identifiers but also want to stay closer to the traditional UUID v1 field layout, rather than jumping straight to the newer UUID v7 format. It's a solid option where infrastructure already expects UUID v1-style structures but database sort performance still matters.

Advantages

  • Better for databases
  • Time ordered
  • Compatible with UUID infrastructure

Disadvantages

  • Less common
  • Timestamp still visible

UUID v7

UUID v7 combines a Unix-millisecond timestamp with additional bits used for randomness, counters, or sub-millisecond timestamp information. It is designed to improve database index locality compared with randomly generated UUIDs such as UUID v4 while preserving strong randomness where it counts. Because the timestamp sits in the most significant bits, UUID v7 values sort naturally by creation time, which keeps B-tree indexes compact and insert performance high - a major advantage over UUID v4 in write-heavy database workloads. This combination of ordering and randomness is why it's quickly becoming the recommended default for new applications.

Advantages

  • Naturally sortable
  • Database friendly
  • Good privacy (Does not expose a node/MAC identifier, but does expose creation time through its 48-bit Unix-millisecond timestamp)
  • Modern standard
  • Fast indexing

Disadvantages

  • Newer libraries may not yet support it

UUID v8

UUID v8 reserves the internal data layout for application-specific formats, effectively giving developers a standardized "wrapper" around a completely custom identifier scheme. This is useful when an organization already has its own internal ID format (for example, one combining a shard ID, timestamp, and sequence number) and wants that value to remain interoperable with systems and libraries expecting a valid, spec-compliant UUID.

Advantages

  • Extremely flexible
  • Allows custom identifier schemes

Disadvantages

  • No universal internal format
  • Limited interoperability

Popularity

Real-world adoption doesn't always track perfectly with technical merit - legacy systems keep older versions like UUID v1 and UUID v3 alive well past their prime, while UUID v4's simplicity has made it the long-standing default even in cases where UUID v7 would now perform better. As more databases and ORMs add native UUID v7 support, expect that share to keep shifting toward the newer, sortable versions.

Version Typical Usage
UUID v1 Legacy enterprise software
UUID v3 Older deterministic systems
UUID v4 Most existing applications
UUID v5 Namespace-based identifiers
UUID v6 Modern database systems
UUID v7 New applications and databases
UUID v8 Specialized systems

Which Version Should You Choose?

There's no single "best" UUID version - only the version that best matches your constraints. The table below maps common requirements to their strongest match, but as a general rule of thumb: default to UUID v4 unless you have a specific reason not to, switch to UUID v7 if your identifiers are database primary keys, and reach for UUID v5 only when you specifically need the same input to always produce the same output.

Requirement Best Choice
Maximum compatibility UUID v4
Best database performance UUID v7
Stable identifier from a name UUID v5
Legacy compatibility UUID v1
Experimental or custom format UUID v8

For most new software projects, UUID v7 is the recommended choice because it combines chronological ordering with strong randomness, making it ideal for modern databases and distributed systems. If broad compatibility is your highest priority, UUID v4 remains an excellent option.


UUID Standards and Version History

The UUID specification has evolved over time through publications by the Internet Engineering Task Force (IETF). Two RFCs define the standardized UUID versions used today, and understanding the shift between them helps explain why newer versions like UUID v6 and UUID v7 exist at all - they were direct responses to real limitations engineers ran into with the original four.

RFC Published Status UUID Versions Defined
RFC 4122 July 2005 Obsolete UUID v1, UUID v3, UUID v4, UUID v5
RFC 9562 May 2024 Current Standard UUID v1-v8

RFC 4122

RFC 4122 was the original UUID standard published in 2005. It standardized four UUID versions, establishing the timestamp-based, hash-based, and random generation approaches that later versions would build on:

Version Purpose
UUID v1 Time-based using a timestamp and node identifier
UUID v3 Deterministic using an MD5 hash
UUID v4 Randomly generated
UUID v5 Deterministic using a SHA-1 hash

For nearly twenty years, these four versions formed the basis of virtually all UUID implementations, and they're still fully valid and widely supported today - RFC 9562 didn't deprecate any of them, it simply added more options on top.


RFC 9562

In 2024, RFC 9562 replaced RFC 4122. It retained the existing UUID versions while introducing new versions designed for modern applications and databases, largely in response to the widespread adoption of UUIDs as database primary keys and the performance problems that random UUID v4 values caused for index locality.

RFC 9562 defines eight UUID versions:

Version Description
UUID v1 Time-based (updated guidance)
UUID v2 Reserved (historical DCE Security UUIDs; not standardized)
UUID v3 MD5 namespace hash
UUID v4 Random
UUID v5 SHA-1 namespace hash
UUID v6 Reordered timestamp for better database indexing
UUID v7 Unix timestamp combined with random data
UUID v8 Custom application-defined format

The most significant additions are UUID v6 and UUID v7, which improve insertion performance in databases by producing identifiers that naturally sort by creation time - directly addressing one of the most common complaints developers had about using UUID v4 as a primary key.


What About UUID v2?

UUID v2 was used by the Distributed Computing Environment (DCE) Security specification, an older framework for distributed computing that predates the modern UUID RFCs. Unlike the other UUID versions, it was never formally standardized by the IETF, and its intended use - embedding POSIX UID/GID values and a timestamp - never gained meaningful adoption outside of DCE environments.

RFC 9562 reserves Version 2 but does not define a generation algorithm for it. As a result, UUID v2 is rarely implemented and is generally not recommended for new software; if you encounter a "version 2" identifier in the wild, it's most likely a legacy or vendor-specific format rather than a standards-compliant UUID.


Which RFC Should You Follow?

For all new software, follow RFC 9562.

It is the current UUID specification and supersedes RFC 4122. Existing UUID v1, UUID v3, UUID v4, and UUID v5 identifiers remain fully valid under RFC 9562, so older systems continue to interoperate without modification - there's no migration required for identifiers already generated under the older standard.

Most new applications should consider UUID v7 as the preferred default because it combines chronological ordering with strong randomness while remaining fully compliant with RFC 9562.

Text Layouts

UUID v4 Text Layout

The text representation of a UUID is the familiar 36-character hyphenated string most developers recognize. While the overall shape (8-4-4-4-12 hex digits) is identical across versions, the version and variant nibbles embedded in specific positions are what let software identify which generation method produced a given UUID at a glance.

xxxxxxxx
-
xxxx
-
4 Version
xxx
-
y Variant
xxx
-
xxxxxxxxxxxx
Total: 36 characters
x = Random hexadecimal digit
4 = UUID version (0100)
y = Variant nibble (8, 9, A, or B)

UUID v7 Text Layout

xxxxxxxx Timestamp
-
xxxx Timestamp
-
7 Version
xxx Rand*
-
y Variant
xxx Rand*
-
xxxxxxxxxxxx Rand*
x = Timestamp or random bits
7 = UUID version (0111)
y = Variant nibble (8, 9, A, or B)
* = May instead contain a sub-millisecond timestamp and/or monotonic counter, depending on the implementation.

ULID Text Layout

xxxxxxxxxx Timestamp
xxxxxxxxxxxxxxxx Randomness
Total: 26 characters
x = Crockford Base32 characters
Timestamp: 10 characters
Randomness: 16

NanoID Text Layout

A-Za-z0-9_- 21 Random Characters
Alphabet: A-Z a-z 0-9 _ -
Length: 21 characters (default)
Bits per character: 6
Total entropy: 126 bits of entropy assuming uniform selection

Binary Layouts

Underneath the text format, every UUID is really just 128 raw bits - the hyphenated string is only a human-readable encoding. Looking at the binary layout makes it clear exactly how many bits are actually available for uniqueness once the fixed version and variant fields are subtracted out.

UUIDv4 Binary Layout

32 Random Bits
16 Random Bits
Version
0100b
12 Random Bits
Variant
10b
14 Random Bits
48 Random Bits
Total: 128 bits
Random: 122 bits
Reserved: 6 bits (Version + Variant)
Version:0100b (UUID version 4)
Variant:10b (RFC 9562 / RFC 4122 variant)

UUIDv7 Binary Layout

48-bit Timestamp Unix ms
0111 Version
12 bits rand_a*
10 Variant
62 bits rand_b*
Total: 128 bits
Timestamp: 48 bits
Version: 4 bits (0111)
Variant: 2 bits (10)
rand_a: 12 bits*
rand_b: 62 bits*

* RFC 9562 allows rand_a and rand_b to contain random bits, a monotonic counter, sub-millisecond timestamp bits, or a combination of these values. Many implementations simply use random data.

ULID Binary Layout

48 Timestamp Bits
80 Random Bits
Total: 128 bits
Timestamp: 48 bits (Unix time in milliseconds)
Randomness: 80 bits
Encoding: Crockford Base32

NanoID Binary Layout

126 Random Bits 21 × 6-bit characters
Total: 126 bits (default)
Random: 126 bits

Related Tools and Guides

Need some UUIDs for testing? Try our tools for generating UUID v4   UUID v7   ULID   NanoID and decoding validating.
For a detailed comparison of UUID versions, visit our Complete Guide to UUID Versions.