UUID Guide: Understanding v1, v4, and v5 Versions

Updated March 2026 · 7 min read

Universally Unique Identifiers (UUIDs) are 128-bit values used to identify resources without a central authority. They are used everywhere: database primary keys, API request IDs, session tokens, distributed systems, and message queues. Understanding UUID versions helps you pick the right one for your use case.

UUID Format

A UUID is displayed as 32 hexadecimal digits in five groups separated by hyphens, following the pattern 8-4-4-4-12:

550e8400-e29b-41d4-a716-446655440000
|        |    |    |    |
|        |    |    |    +-- Node (48 bits)
|        |    |    +------- Clock seq (16 bits)
|        |    +------------ Version (4 bits) + Time high
|        +----------------- Time mid (16 bits)
+-------------------------- Time low (32 bits)

The version number is encoded in the 13th hex digit (the first digit of the third group). For example, 550e8400-e29b-41d4-a716-446655440000 is a version 4 UUID.

UUID Versions Compared

VersionBased OnDeterministic?Best For
v1Timestamp + MAC addressNoTime-ordered IDs, distributed systems
v3Namespace + Name (MD5)YesReproducible IDs from known inputs
v4RandomNoGeneral purpose, most common choice
v5Namespace + Name (SHA-1)YesReproducible IDs (preferred over v3)

UUID v1: Timestamp-Based

Version 1 UUIDs combine the current timestamp (100-nanosecond intervals since October 15, 1582) with the MAC address of the generating machine.

// Example v1 UUID:
6ba7b810-9dad-11d1-80b4-00c04fd430c8
                ^--- version digit = 1

Pros: Naturally sorted by creation time, useful for time-series data and distributed logging.

Cons: Leaks the MAC address and creation timestamp, which can be a privacy concern. Two IDs generated at the same time on the same machine may collide without a clock sequence.

When to use: Time-ordered database indexes, event sourcing, audit logs where temporal ordering matters.

UUID v4: Random

Version 4 is the most widely used UUID version. It generates 122 random bits (the remaining 6 bits encode the version and variant).

// Example v4 UUIDs:
f47ac10b-58cc-4372-a567-0e02b2c3d479
9b1deb4d-3b7d-4bad-9bdd-2b0d7b3dcb6d
                ^--- version digit = 4

Collision probability: With 122 bits of randomness, you would need to generate approximately 2.7 quintillion UUIDs to have a 50% chance of a single collision. In practice, collisions are virtually impossible.

When to use: Primary keys, API request IDs, session identifiers, anywhere you need a unique ID without coordination.

UUID v5: Name-Based (SHA-1)

Version 5 generates a deterministic UUID from a namespace and a name using SHA-1 hashing. The same namespace + name always produces the same UUID.

// Namespace: DNS (6ba7b810-9dad-11d1-80b4-00c04fd430c8)
// Name: "devtoolkit.ink"
// Result: always the same UUID

// Standard namespaces:
DNS:  6ba7b810-9dad-11d1-80b4-00c04fd430c8
URL:  6ba7b811-9dad-11d1-80b4-00c04fd430c8
OID:  6ba7b812-9dad-11d1-80b4-00c04fd430c8
X500: 6ba7b814-9dad-11d1-80b4-00c04fd430c8

When to use: When you need the same identifier for the same input across different systems without coordination. Useful for content-addressable storage, URL shorteners, and deduplication.

UUID v7: The New Standard (RFC 9562)

UUID v7 was introduced in RFC 9562 (2024) and is gaining rapid adoption. It combines a Unix timestamp in milliseconds with random bits, giving you time-ordered UUIDs without leaking MAC addresses:

// UUID v7 structure:
018f26a0-c7b0-7xxx-xxxx-xxxxxxxxxxxx
|              |^--- version 7
+--------------+--- millisecond timestamp

UUID v7 is becoming the recommended choice for database primary keys because it provides natural ordering (great for B-tree indexes) without the privacy concerns of v1.

Generating UUIDs in Code

# Python
import uuid
uuid.uuid4()              # Random (v4)
uuid.uuid1()              # Timestamp (v1)
uuid.uuid5(uuid.NAMESPACE_DNS, "devtoolkit.ink")  # Name-based (v5)

// JavaScript (Web Crypto API)
crypto.randomUUID()       // v4 (modern browsers)

// Node.js
const { randomUUID } = require('crypto');
randomUUID();             // v4

// Go
import "github.com/google/uuid"
uuid.New()                // v4

// Bash
uuidgen                   # Usually v4 (platform-dependent)

UUID vs. Other ID Formats

FormatLengthSortable?Notes
UUID v436 charsNoStandard, widely supported
UUID v736 charsYesTime-ordered, new standard
ULID26 charsYesCompact, Crockford Base32
nanoid21 charsNoURL-safe, compact
CUID224 charsYesCollision-resistant
Auto-incrementVariesYesLeaks count, single-DB only

Best Practices

FAQ

Is UUID the same as GUID?

Yes. GUID (Globally Unique Identifier) is Microsoft's term for UUID. They follow the same format and standards.

Can UUID v4 collisions actually happen?

Theoretically yes, but the probability is astronomically low. Generating 1 billion UUIDs per second for 86 years gives roughly a 50% chance of one collision. For practical purposes, collisions do not happen.

Should I use UUIDs as primary keys in my database?

UUID v4 works but can fragment B-tree indexes due to random ordering. UUID v7 or ULID are better choices for primary keys because they are time-ordered. Alternatively, use auto-increment IDs internally and expose UUIDs externally.

Try UUID Generator Now →

DevToolKit — 42+ Free Online Developer Tools