UUID Versions

Learn about the different UUID versions and their specifications.

UUID Format

A UUID is a 128-bit value represented as a sequence of 32 hexadecimal digits, displayed in 5 groups separated by hyphens.

xxxxxxxx-xxxx-Mxxx-Nxxx-xxxxxxxxxxxx

Where M is the UUID version (1-8) and N is the UUID variant (typically 8, 9, A, or B for RFC 4122 UUIDs).

Version 1: Time-based UUIDs

Version 1 UUIDs are generated based on the current timestamp and MAC address (node ID) of the computer.

f81d4fae-7dec-11d0-a765-00a0c91e6bf6

Advantages:

  • Natural ordering based on time of creation
  • Good for chronological sorting
  • Contains embedded timestamp that can be extracted

Disadvantages:

  • Contains MAC address, which can be a privacy concern
  • Not guaranteed to be unique if clock goes backward
  • Complex timestamp format (100-ns intervals since 10/15/1582)

Version 4: Random UUIDs

Version 4 UUIDs are generated using random or pseudo-random numbers.

110ec58a-a0f2-4ac4-8ae3-4f4e424b5b6c

Advantages:

  • Simple generation without external dependencies
  • No privacy concerns (no identifying information)
  • Most widely supported in libraries and frameworks
  • Excellent for distributed systems with no coordination

Disadvantages:

  • No natural ordering
  • May cause database indexing performance issues
  • Very small but non-zero probability of collisions

Version 7: Time-ordered UUIDs

Version 7 UUIDs include a Unix timestamp (in milliseconds) in the most significant bits.

017f22e2-79b0-7cc3-98c4-dc0c0c07398f

Advantages:

  • Simple time-ordering for database indexing
  • Improved performance for time-series data
  • Modern standard (IETF draft)
  • More efficient than v1 UUIDs in many database systems
  • Uses standard Unix timestamp format

Disadvantages:

  • Newer standard with less widespread support
  • Millisecond precision (vs. 100ns for v1)
  • Less randomness than v4

Other UUID Versions

Version 3 (MD5 Name-based): Generated by hashing a namespace ID and name.

9125a8dc-52ee-3365-87fd-b7c8d9d61275

Version 5 (SHA-1 Name-based): Similar to v3 but uses SHA-1 for improved security.

74738ff5-5367-5958-9aee-98fffdcd1876

Versions 6 and 8 are also defined in draft specifications that address additional use cases and limitations.

UUID Version Selection Guide

Choosing the right UUID version depends on your specific requirements:

  • Use Version 1 when you need chronological sorting and can use the MAC address
  • Use Version 4 for general-purpose unique identifiers with no special requirements
  • Use Version 7 for modern database systems where you need both time ordering and better performance
  • Use Version 3/5 when you need deterministic IDs generated from names (e.g., for named resources)

Understanding UUID Versions and Their Applications

Universally Unique Identifiers (UUIDs) come in several versions, each designed for specific use cases. This guide explains the different UUID versions defined in RFC 4122 and subsequent specifications, helping developers choose the right UUID type for their application.

UUID Structure and Components

All UUIDs share a common structure: a 128-bit value represented as 32 hexadecimal digits, typically grouped in a 8-4-4-4-12 pattern. Within this structure, specific bits indicate:

  • The UUID version (13th digit): Indicates how the UUID was generated
  • The UUID variant (17th digit): Specifies the layout and interpretation of the UUID
  • The remaining digits contain version-specific data

Historical Development of UUID Versions

The evolution of UUID versions reflects changing needs in distributed computing:

  • The original UUID specification (RFC 4122, 2005) defined versions 1-5
  • Later drafts introduced versions 6-8 to address limitations in earlier versions
  • Each new version aimed to solve specific problems while maintaining backward compatibility

Version 1: Time-based UUIDs

Version 1 UUIDs were among the first defined and are generated using:

  • A timestamp with 100-nanosecond precision (first 60 bits)
  • A clock sequence to prevent duplicates when the clock is set backward (14 bits)
  • A node identifier, typically the MAC address of the generating computer (48 bits)

These UUIDs are excellent for time-ordered data but have privacy implications due to the embedded MAC address.

Version 4: Random UUIDs

Version 4 UUIDs are the most widely used due to their simplicity:

  • Generated using cryptographically strong random numbers
  • No machine-identifying information is included
  • Simple to generate in any environment without external dependencies
  • Extremely low collision probability (approximately 1 in 2^122)

These UUIDs are ideal for general-purpose unique identifiers but lack any meaningful ordering.

Version 7: Time-ordered UUIDs

Version 7 UUIDs are a modern approach that combines benefits of v1 and v4:

  • First 48 bits contain a Unix timestamp in milliseconds
  • Remaining bits are randomly generated
  • Provides natural sorting order while avoiding privacy concerns
  • Optimized for database indexing and performance

These UUIDs are increasingly recommended for new applications, especially database-centric systems.

Name-based UUID Versions (3 and 5)

These specialized UUIDs generate deterministic identifiers from names:

  • Version 3: Uses MD5 hashing of a namespace ID and name
  • Version 5: Uses SHA-1 hashing for improved security
  • Always produces the same UUID for the same namespace and name
  • Useful for named resources that need consistent identifiers

Implementation Considerations

When implementing UUIDs in your applications, consider:

  • Database performance impacts of different UUID versions
  • Library support for your chosen UUID version
  • Privacy requirements and concerns
  • Need for chronological sorting
  • Cross-platform compatibility