Complete Guide to UUID Versions

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, they differ in how the 122 available data bits are generated.


Version Primary Purpose Generation Method Sortable Deterministic Common Today
UUIDv1 Legacy unique IDs Timestamp + Node ID ⭐⭐
UUIDv3 Stable identifiers MD5 Hash ⭐⭐
UUIDv4 Random identifiers Cryptographically secure random numbers ⭐⭐⭐⭐⭐
UUIDv5 Stable identifiers SHA-1 Hash ⭐⭐⭐
UUIDv6 Time-ordered Reordered timestamp + random/node ⭐⭐
UUIDv7 Modern databases Unix timestamp + random ⭐⭐⭐⭐
UUIDv8 Custom applications User-defined layout Depends Depends

Comparison

Property UUIDv1 UUIDv3 UUIDv4 UUIDv5 UUIDv6 UUIDv7 UUIDv8
RFC Standard
128-bit Identifier
Random Partial Partial Depends
Time-based Depends
Sortable Depends
Deterministic Depends
Database Friendly ⭐⭐ ⭐⭐ ⭐⭐ ⭐⭐ ⭐⭐⭐⭐ ⭐⭐⭐⭐⭐ Depends
Privacy Friendly ⭐⭐⭐⭐ ⭐⭐⭐⭐⭐ ⭐⭐⭐⭐ ⭐⭐ ⭐⭐⭐⭐⭐ Depends

Structure Comparison

Version Timestamp Random Data Hash Namespace Node ID Custom Data
UUIDv1
UUIDv3 MD5
UUIDv4
UUIDv5 SHA-1
UUIDv6 Partial Optional
UUIDv7 Unix Time
UUIDv8 Depends Depends Depends Depends Depends

When to Use Each Version

Use Case Recommended Version
General-purpose applications UUIDv4
New database applications UUIDv7
Sequential inserts UUIDv7 or UUIDv6
Deterministic identifiers UUIDv5
Legacy compatibility UUIDv1
Custom implementation UUIDv8

UUIDv1

UUIDv1 combines a timestamp with a node identifier, historically a MAC address.

Advantages

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

Disadvantages

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

UUIDv3

UUIDv3 creates deterministic UUIDs by hashing a namespace and name using MD5.

Advantages

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

Disadvantages

  • Uses MD5
  • Not random

UUIDv4

UUIDv4 is generated using cryptographically secure random numbers.

Approximately 122 bits are random, giving an astronomically low chance of collisions.

Advantages

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

Disadvantages

  • Not sortable
  • Random inserts can fragment database indexes

UUIDv5

UUIDv5 is deterministic like UUIDv3 but uses SHA-1 instead of MD5.

Advantages

  • Stable identifiers
  • Better hash algorithm than UUIDv3

Disadvantages

  • Not random
  • Not sortable

UUIDv6

UUIDv6 rearranges the UUIDv1 timestamp fields so identifiers sort naturally.

Advantages

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

Disadvantages

  • Less common
  • Timestamp still visible

UUIDv7

UUIDv7 combines a Unix timestamp with random bits.

It is designed specifically to solve the database performance issues of UUIDv4 while preserving strong randomness.

Advantages

  • Naturally sortable
  • Database friendly
  • Excellent privacy
  • Modern standard
  • Fast indexing

Disadvantages

  • Newer libraries may not yet support it

UUIDv8

UUIDv8 reserves the internal data layout for application-specific formats.

Advantages

  • Extremely flexible
  • Allows custom identifier schemes

Disadvantages

  • No universal internal format
  • Limited interoperability

Popularity

Version Typical Usage
UUIDv1 Legacy enterprise software
UUIDv3 Older deterministic systems
UUIDv4 Most existing applications
UUIDv5 Namespace-based identifiers
UUIDv6 Modern database systems
UUIDv7 New applications and databases
UUIDv8 Specialized systems

Which Version Should You Choose?

Requirement Best Choice
Maximum compatibility UUIDv4
Best database performance UUIDv7
Stable identifier from a name UUIDv5
Legacy compatibility UUIDv1
Experimental or custom format UUIDv8

For most new software projects, UUIDv7 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, UUIDv4 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.

RFC Published Status UUID Versions Defined
RFC 4122 July 2005 Obsolete UUIDv1, UUIDv3, UUIDv4, UUIDv5
RFC 9562 May 2024 Current Standard UUIDv1–v8

RFC 4122

RFC 4122 was the original UUID standard published in 2005. It standardized four UUID versions:

Version Purpose
UUIDv1 Time-based using a timestamp and node identifier
UUIDv3 Deterministic using an MD5 hash
UUIDv4 Randomly generated
UUIDv5 Deterministic using a SHA-1 hash

For nearly twenty years, these four versions formed the basis of virtually all UUID implementations.


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.

RFC 9562 defines eight UUID versions:

Version Description
UUIDv1 Time-based (updated guidance)
UUIDv2 Reserved (historical DCE Security UUIDs; not standardized)
UUIDv3 MD5 namespace hash
UUIDv4 Random
UUIDv5 SHA-1 namespace hash
UUIDv6 Reordered timestamp for better database indexing
UUIDv7 Unix timestamp combined with random data
UUIDv8 Custom application-defined format

The most significant additions are UUIDv6 and UUIDv7, which improve insertion performance in databases by producing identifiers that naturally sort by creation time.


What About UUIDv2?

UUIDv2 was used by the Distributed Computing Environment (DCE) Security specification. Unlike the other UUID versions, it was never formally standardized by the IETF.

RFC 9562 reserves Version 2 but does not define a generation algorithm for it. As a result, UUIDv2 is rarely implemented and is generally not recommended for new software.


Which RFC Should You Follow?

For all new software, follow RFC 9562.

It is the current UUID specification and supersedes RFC 4122. Existing UUIDv1, UUIDv3, UUIDv4, and UUIDv5 identifiers remain fully valid under RFC 9562, so older systems continue to interoperate without modification.

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

Text Layouts

UUIDv4 Text Layout

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)

UUIDv7 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

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)

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 random bits

Binary Layouts

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

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)

NanoID Binary Layout

126 Random Bits 21 × 6-bit characters
Total: 126 bits (default)
Random: 126 bits
Reserved: None
Version: None
Variant: None