UUID Versions Explained: v1, v3, v4, v5, and v7

May 27, 20266 min read

What Is a UUID?

A UUID (Universally Unique Identifier) is a 128-bit identifier that is unique across space and time without requiring a central coordinator. UUIDs appear as 36-character strings with hyphens:

550e8400-e29b-41d4-a716-446655440000

The format breaks down as 8-4-4-4-12 hexadecimal digits. The third group's first digit indicates the UUID version. RFC 4122 defines versions 1, 3, 4, and 5, while RFC 9562 adds version 7.

UUID v1: Time and Node Based

UUID v1 combines a 60-bit timestamp (100-nanosecond intervals since October 15, 1582) with the MAC address of the generating machine.

Strengths:

  • Sortable by generation time
  • No collision risk across machines with different MAC addresses

Weaknesses:

  • Exposes the machine's MAC address — a privacy concern
  • Predictable: knowing the timestamp and node reveals the UUID
  • Clock drift on a single machine can cause duplicates

Use v1 when you need traceability to a specific machine and timestamp, such as audit logging in controlled environments.

UUID v3: MD5 Namespace Hash

UUID v3 generates identifiers by hashing a namespace UUID and a name using MD5. The same namespace and name always produce the same UUID.

// Same inputs always yield the same v3 UUID
uuidv3('example.com', namespace.DNS) // → 9073926b-929f-31c2-abc9-fad77ae3e8eb

Strengths:

  • Deterministic: reproduce the same UUID from the same inputs
  • No need to store the mapping — recompute on the fly

Weaknesses:

  • MD5 is cryptographically broken
  • Collision risk if two different names hash to the same value
  • Not sortable by time

Use v3 for consistent naming in systems where you recreate identifiers from known inputs, like generating stable URIs from DNS names.

UUID v4: Random

UUID v4 uses random or pseudo-random bits for all 122 variable bits. This is the most widely used version.

// Each call produces a different random UUID
uuidv4() // → f47ac10b-58cc-4372-a567-0e02b2c3d479

Strengths:

  • Minimal collision risk: probability of a duplicate among 10³⁷ UUIDs is negligible
  • No coordination needed between systems
  • Simple to generate — no clock or network dependency

Weaknesses

  • Not sortable — random order harms database index performance
  • No embedded metadata

Use v4 as the default choice when you need simple, collision-free identifiers without sortability requirements.

UUID v5: SHA-1 Namespace Hash

UUID v5 works like v3 but uses SHA-1 instead of MD5. It is the recommended replacement for v3.

uuidv5('example.com', namespace.DNS) // → c4d7a8a5-71ad-5b36-9c8e-4e6a5d2f1b03

Strengths:

  • Same determinism as v3
  • SHA-1 provides stronger collision resistance than MD5

Weaknesses:

  • SHA-1 is deprecated for cryptographic purposes (though acceptable for UUID generation)
  • Still not time-sortable

Use v5 instead of v3 in all new systems that need deterministic UUIDs.

UUID v7: Time-Ordered Modern Standard

UUID v7 combines a 48-bit Unix millisecond timestamp with random bits. It combines the sortability of v1 with the simplicity of v4.

| 48-bit timestamp (ms) | 4-bit ver | 12-bit rand | 2-bit var | 62-bit rand |

Strengths:

  • Time-sortable: excellent for database indexing
  • No privacy leak — no MAC address embedded
  • Drop-in replacement for v4 in most systems

Weaknesses:

  • Newer standard — not yet supported everywhere
  • Millisecond precision means sub-millisecond ordering relies on random bits only

Use v7 for new projects that need sortability, especially in database-heavy applications.

UUID Version Comparison

Featurev1v3v4v5v7
GenerationTimestamp + MACMD5 hashRandomSHA-1 hashTimestamp + Random
SortableYesNoNoNoYes
DeterministicNoYesNoYesNo
Privacy-safeNoYesYesYesYes
Collision riskVery lowPossibleNegligibleVery lowNegligible
Best forAudit trailsLegacy deterministic IDsGeneral purposeDeterministic IDsModern databases

Which Version Should You Use?

  • Default choice? UUID v4 — battle-tested, zero coordination, widely supported
  • Database performance matters? UUID v7 — time-ordered, index-friendly
  • Need reproducible IDs? UUID v5 — deterministic from namespace + name
  • Legacy system requiring deterministic IDs? UUID v3 — same as v5 but with MD5

Try It Yourself

Generate UUIDs in any version instantly with our free UUID Generator. Compare v4 randomness and v7 sortability side by side — no signup required.