What is a UUID?
The Complete Developer Guide
Everything you need to know about Universally Unique Identifiers — format, versions, bit structure, collision probability, and when to use each version in 2026.
In This Guide
Section 1
UUID Definition
A UUID (Universally Unique Identifier) is a 128-bit label used to uniquely identify information in computer systems. The defining property of a UUID is that it can be generated by any computer, independently, without coordinating with a central authority, and still be practically guaranteed never to duplicate an identifier generated anywhere else in the world.
The standard is formally defined in two RFCs. RFC 4122 (published July 2005) introduced the original four versions: v1, v3, v4, and v5. RFC 9562 (published May 2024) superseded RFC 4122 and added versions v6, v7, and v8 along with the Nil and Max special-purpose UUIDs.
You will often see UUID used interchangeably with GUID (Globally Unique Identifier), which is Microsoft’s term for its implementation. The underlying standard is identical; some Microsoft implementations differ in byte-order representation for certain fields.
Why “Universally Unique”?
Unlike a sequential database ID that requires a central counter, a UUID is designed so that any two systems can independently generate an identifier without any communication between them and still be confident the IDs will not collide. This decentralization is what makes UUIDs essential in distributed systems, microservices, and offline-first applications.
Section 2
UUID Format and Anatomy
A UUID is represented as 32 lowercase hexadecimal digits arranged in five groups separated by hyphens, following an 8-4-4-4-12 pattern. The total length is always 36 characters including hyphens, or 32 characters without.
Version and Variant Bits
Two specific character positions in every UUID carry structural meaning regardless of version:
- Position 13 (character at index 14 in the full string) — the version digit. A UUID v4 always has 4 here; a v7 always has 7. This is how you identify a UUID’s version at a glance.
- Position 17 (character at index 19 in the full string) — the variant digit. For all RFC 4122/9562-compliant UUIDs, this is always 8, 9, a, or b. This confirms the UUID follows the standard rather than older or proprietary UUID formats.
Bit Layout of a UUID v4
time_low
time_mid
ver
random
var
random
Validation Regex
A simple regular expression for validating any RFC-compliant UUID (versions 1–8):
The [1-8] anchors the version digit to currently-defined versions. The [89ab] anchors the variant to the RFC 4122/9562 range.
Section 3
All 8 UUID Versions Explained
RFC 4122 defined four versions in 2005. RFC 9562 added three more in May 2024. Here is what each version does, how it generates its bits, and when to use it.
| Version | Algorithm | Deterministic | Time-Sortable | RFC | 2026 Status |
|---|---|---|---|---|---|
| v1 | 60-bit timestamp (100ns since Oct 1582) + MAC address + clock sequence | No | Partially | 4122 | Use with caution |
| v3 | MD5 hash of namespace UUID + name string | Yes | No | 4122 | Prefer v5 |
| v4 | 122 cryptographically random bits | No | No | 4122 | Recommended |
| v5 | SHA-1 hash of namespace UUID + name string | Yes | No | 4122 | Recommended |
| v6 | Reordered v1 timestamp (sortable) + MAC/random node | No | Yes | 9562 | v1 migration |
| v7 | 48-bit Unix millisecond timestamp + 74 random bits | No | Yes | 9562 | Recommended 2026 |
| v8 | Fully custom layout defined by implementation | Depends | Depends | 9562 | Experimental |
| Nil | All 128 bits set to zero | Yes | — | 9562 | Special value |
| Max | All 128 bits set to one (all F) | Yes | — | 9562 | Special value |
UUID v1 — Timestamp + MAC
UUID v1 uses a 60-bit timestamp counting 100-nanosecond intervals since October 15, 1582 (the Gregorian calendar reform date). The timestamp is combined with a 14-bit clock sequence (to handle sub-100ns generation rates or clock adjustments) and a 48-bit node value derived from the generating machine’s MAC address.
Privacy risk in user-facing applications
Because v1 embeds the MAC address of the generating machine, any party who receives a v1 UUID can potentially trace it back to the machine that created it. Do not use v1 in user-facing systems where you need to protect the generating machine’s identity.
UUID v3 and v5 — Name-Based (Deterministic)
v3 and v5 both generate UUIDs deterministically from a namespace UUID and a name string. Given the same namespace and name, they always produce the same UUID — making them useful for deduplication and content-addressable IDs. v3 uses MD5; v5 uses SHA-1. Always prefer v5: MD5 is cryptographically broken, and v5 produces more collision-resistant output.
Four standard namespaces are defined in RFC 4122: DNS (6ba7b810-9dad-11d1-80b4-00c04fd430c8), URL, OID, and X.500 DN. You can also define your own namespace UUID for your application domain.
UUID v4 — Random (General Purpose)
UUID v4 is the most widely used version. It fills 122 bits with cryptographically random data (the remaining 6 bits are fixed for version and variant markers). With 2¹²² possible values — roughly 5.3 undecillion — collisions are astronomically unlikely at any real-world scale.
Use v4 for: API resource identifiers, session tokens, object names, file names, and any ID where you specifically do not want to encode creation time.
UUID v6 — Time-Ordered v1 Replacement
UUID v6 reorganizes the v1 timestamp fields so the most significant bits come first, making v6 UUIDs sort correctly by generation time. It is field-compatible with v1 (the timestamp fields can be extracted using the same logic), making it a natural migration path for systems already using v1.
UUID v7 — Unix Timestamp (2026 Default for Primary Keys)
UUID v7 encodes a 48-bit Unix timestamp in milliseconds in the most significant bits, followed by 74 bits of random data. This design makes v7 UUIDs monotonically increasing within each millisecond and time-sortable across machines without coordination.
Why v7 is the recommended choice for database primary keys in 2026
B-tree indexes (used by PostgreSQL, MySQL, SQLite, and most other relational databases) perform best when new values are inserted in roughly ascending order. Fully random v4 UUIDs cause page splits and index fragmentation at scale. UUID v7’s time-prefixed structure eliminates this problem while retaining 74 bits of randomness — more than sufficient for collision safety. PostgreSQL 18 ships native uuidv7() support, and frameworks including Laravel 11+ and Rails 8+ now default to v7.
UUID v8 — Custom Layout
UUID v8 is a wildcard version: RFC 9562 defines only the version (bits 48–51) and variant (bits 64–65) fields. All other 122 bits are implementation-defined. Use v8 when you need UUID-shaped identifiers that embed application-specific structured data — for example, a shard ID, tenant ID, or feature flags packed into the bit fields. It is experimental for most use cases.
Nil and Max UUIDs
The Nil UUID (00000000-0000-0000-0000-000000000000) has all 128 bits set to zero. The Max UUID (ffffffff-ffff-ffff-ffff-ffffffffffff) has all 128 bits set to one. Both are defined in RFC 9562 as sentinels — Nil to represent “no UUID” or an unset field, Max to represent a boundary or wildcard value (for example, the upper bound in a range query).
Section 4
Which UUID Version Should You Use?
| Situation | Recommended Version | Reason |
|---|---|---|
| Database primary key (new project, 2026) | v7 | Time-sortable, B-tree friendly, 74-bit random node. PostgreSQL 18 native. |
| API resource ID, opaque token, general ID | v4 | Fully random, no time leakage, universally supported. |
| Password-reset link, CSRF token, short-lived secret | v4 (or dedicated secret generator) | No timestamp exposure. Note: UUID alone is not a cryptographic secret — use purpose-built secret generation for high-security tokens. |
| Content-addressable or deduplicated ID from a known name | v5 | Deterministic SHA-1 hash of namespace + name. Same input always yields same UUID. |
| Migrating from v1 without changing field widths | v6 | Field-compatible v1 replacement with time-sortable bit order. |
| Legacy system already using v1 | v1 | Keep for compatibility if MAC leak risk is acceptable and system is not user-facing. |
| Placeholder / “no ID set” sentinel | Nil | All zeros, recognized by all UUID-aware systems as the null/unset value. |
| Custom structured identifier (shard ID embedded, etc.) | v8 | All non-version/variant bits are yours to define. |
Do not use any UUID version as a standalone secret
UUIDs are designed for uniqueness, not unguessability. A UUID alone should never be your only authentication factor, password, or high-value API key. For security-critical secrets, use a CSPRNG with sufficient entropy and appropriate access controls.
Section 5
UUID Collision Probability
A UUID v4 has 122 bits of actual randomness (6 bits are fixed for version and variant markers). That gives 2¹²² possible values:
To put that in perspective: if every person on Earth (8 billion people) generated 600 million UUIDs each, the probability of even a single collision anywhere in that entire set would still only be approximately 50%. At the scale of any real application — even large distributed systems generating millions of IDs per day — treat v4 collisions as a non-event.
The precise formula for the probability p of at least one collision when generating n UUIDs from a space of N values is given by the birthday problem approximation:
For a 1-in-a-billion collision probability with UUID v4, you would need to generate approximately 2.6 × 10¹⁷ UUIDs — a number no practical system approaches.
Has a UUID collision ever actually occurred in production?
There are no credible documented cases of a random UUID v4 collision in production caused by the randomness algorithm itself. The far more common source of “UUID collision” bugs is incorrect implementation — reusing a UUID from a test, serializing/deserializing incorrectly, or using a non-CSPRNG source for the random bits.
Section 6
UUID History and RFC Timeline
UUIDs did not originate with the IETF. They were first developed in the context of the Apollo Network Computing System in the late 1980s, then adopted and extended by the Open Software Foundation (OSF) for the Distributed Computing Environment (DCE) in 1990.
Origins in Distributed Computing
Apollo Computer’s NCS introduced unique identifiers for distributed RPC systems. OSF adopted and formalized the concept for DCE, defining the time-based algorithm that became UUID v1.
First Formal Standard
ISO/IEC 11578:1996 and ITU-T X.667 published the first formal international UUID standards, covering the time-based and random algorithms.
IETF Standardizes UUID
RFC 4122, authored by Paul Leach, Michael Mealling, and Rich Salz, became the definitive Internet standard for UUIDs. It formally defined versions 1, 3, 4, and 5. This document remained the authoritative reference for 19 years.
New Versions Drafted
As cloud-native, distributed, and time-series workloads grew, the community recognized the need for time-sortable UUIDs that avoided the B-tree fragmentation problems of v4. The IETF UUIDv6 working group drafted v6, v7, and v8.
RFC 9562 Supersedes RFC 4122
RFC 9562 formally obsoleted RFC 4122 and introduced UUID v6, v7, and v8, plus the Nil and Max special values. PostgreSQL 18, Laravel 11, Rails 8, and major UUID libraries rapidly added native support for v7.
Section 7
Real-World UUID Use Cases
UUIDs appear across virtually every layer of modern software. Here are the most common applications and the version typically used for each.
| Use Case | Version | Why |
|---|---|---|
| Relational database primary keys (PostgreSQL, MySQL) | v7 | Sequential-enough for B-tree index locality; no auto-increment coordination needed across replicas or shards. |
| REST/GraphQL API resource identifiers | v4 | Opaque — does not expose creation time or count of resources to clients. |
| File and object storage naming (S3, GCS) | v4 | Unique, URL-safe (when hyphens are removed or kept), no central counter needed. |
| Message queue deduplication IDs | v4 or v7 | v4 for opaque dedup keys; v7 where time-ordering aids message replay analysis. |
| Session and request tracing IDs | v7 | Timestamp prefix enables log sorting and time-range queries without a separate timestamp field. |
| Event sourcing / event IDs | v7 | Events sort naturally by ID, enabling efficient range queries over event streams. |
| Content-addressable cache keys (CDN, Redis) | v5 | Deterministic: same URL or content hash always maps to the same UUID cache key. |
| Idempotency keys in payment systems | v4 | Random, client-generated, no information disclosure, simple to generate client-side. |
| Device and hardware identifiers (BLE, IoT) | v4 or v1 | v4 for generated device IDs; v1 historically used where MAC-based traceability was acceptable. |
| Minecraft player and entity UUIDs | v4 | Java Edition uses the standard UUID format for player and entity identification; username-to-UUID mapping uses a v3-like deterministic hash via the Mojang API. |
Section 8
Frequently Asked Questions
Ready to Generate a UUID?
Use our free browser-based generator for all 8 versions — v4, v7, v1, v3, v5, v6, v8, Nil, and Max. Nothing is sent to a server.
Generate UUID Now