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 full form of UUID is simply “Universally Unique Identifier” — there is no deeper acronym behind it. The defining property of a UUID is that it can be generated by any computer, independently, without coordinating with a central authority, with a very low probability of collision when an appropriate generation method is used. UUIDs are designed for uniqueness, but uniqueness is not an absolute mathematical guarantee.
In simple words: a UUID is a long, standardized ID such as 550e8400-e29b-41d4-a716-446655440000. An app can attach it to a user record, order, file, or event so that the record has its own identifier even across separate systems. A UUID does not prove who owns the record or whether it exists.
The modern standard is RFC 9562 (May 2024), which superseded RFC 4122 (July 2005). RFC 4122 documented versions 1, 3, 4, and 5; the DCE Security version 2 is also described in RFC 9562. RFC 9562 additionally specifies versions 6, 7, and 8, plus the special Nil and Max UUIDs.
You will often see UUID used interchangeably with GUID (Globally Unique Identifier), which is Microsoft’s term for its implementation. Both names commonly refer to the same 128-bit identifier format; some Microsoft APIs differ in the binary byte order of certain fields.
Why “Universally Unique”?
Unlike a sequential database ID that may require a central counter, a UUID is designed so that any two systems can independently generate an identifier without any communication between them while keeping collision risk very low when generation is implemented correctly. This decentralization is what makes UUIDs essential in distributed systems, microservices, and offline-first applications.
Section 2
UUID Format and Anatomy
A UUID is commonly displayed as 32 hexadecimal digits (uppercase or lowercase) arranged in five groups separated by hyphens, following an 8-4-4-4-12 pattern. The usual text representation is 36 characters including hyphens, or 32 characters without.
How Long Is a UUID?
A UUID is 36 characters long when written in its standard hyphenated form (8-4-4-4-12 with hyphens), or 32 characters if the hyphens are stripped out. In raw binary storage, a UUID takes up exactly 16 bytes (128 bits) — the hyphens and hex-character formatting only exist for human readability, not for the underlying data.
Version and Variant Bits
In UUID versions 1–8 using the standard RFC variant, two character positions carry structural meaning in the hyphenated text representation (Nil and Max are special exceptions):
- Position 15 (zero-based index 14 in the hyphenated 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 20 (zero-based index 19 in the hyphenated string) — the variant digit. For the standard RFC variant of UUID versions 1–8, this is 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
random
random
ver
random
var
random
Validation Regex
A simple regular expression for checking the canonical hyphenated text form of the standard RFC variant in versions 1–8 (excluding the special Nil and Max UUIDs, and without verifying how an ID was generated):
The [1-8] anchors the version digit to currently-defined versions. The [89ab] anchors the variant to the RFC 4122/9562 range. For an existing UUID, use our UUID Decoder & Inspector to inspect its version, variant, and any supported embedded timestamp.
Section 3
All 8 UUID Versions Explained
RFC 4122 documented versions 1, 3, 4, and 5; version 2 is associated with DCE Security. RFC 9562 added versions 6, 7, and 8 in May 2024. Here is what each numbered version does, alongside the special Nil and Max values.
| Version | Algorithm | Deterministic | Time-Sortable | RFC | 2026 Status |
|---|---|---|---|---|---|
| v1 | 60-bit timestamp (100ns since Oct 1582) + node ID + clock sequence | No | Partially | 4122 | Use with caution |
| v2 | DCE Security variant using local identifier and domain information | No | No | DCE / 9562 | Rare / legacy |
| 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 bits for randomness and/or monotonic sequencing | No | Yes | 9562 | Recommended 2026 |
| v8 | Fully custom layout defined by implementation | Depends | Depends | 9562 | Application-specific |
| 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. It also contains a 14-bit clock sequence and a 48-bit node identifier, which may be based on a machine MAC address or a privacy-preserving random value.
Privacy risk in user-facing applications
Some v1 generators embed a machine MAC address, which can expose identifying information. Other generators use random node identifiers. Check the implementation before publishing v1 UUIDs; consider v4 or v7 when host privacy matters.
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 stable name-based identifiers and name-based deduplication. True content addressing generally requires hashing the content itself. v3 uses MD5; v5 uses SHA-1. For new name-based designs, v5 is generally preferable to v3; neither should be used as a substitute for a password hashing or authentication algorithm.
Four well-known name-based UUID 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.
Want to create a repeatable name-based identifier? Try our free online UUID v5 generator. Choose a standard or custom namespace, enter a name, and generate the same UUID v5 whenever you use the same inputs.
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, object names, file names, and other opaque identifiers where you do not want to encode creation time. For session authentication tokens, use a dedicated secure-token mechanism instead.
UUID v6 — Time-Ordered v1 Replacement
UUID v6 reorganizes the v1 timestamp fields so timestamp bits appear in a more sortable order. v6 can be helpful when migrating time-based v1 systems, but timestamp extraction requires the v6 layout rather than treating it as an unchanged v1 value.
UUID v7 — Unix Timestamp (2026 Default for Primary Keys)
UUID v7 encodes a 48-bit Unix timestamp in milliseconds in the most significant bits. The remaining 74 variable bits can include randomness, a counter, or sub-millisecond timestamp precision, depending on the generator. Values are generally time-sortable by millisecond, but strict ordering within the same millisecond is not automatic unless the generator implements a suitable monotonicity method.
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 can improve insertion locality and reduce index fragmentation, though performance depends on your database, workload, and implementation. PostgreSQL 18 provides native uuidv7() generation.
UUID v8 — Custom Layout
UUID v8 is an application-specific version: RFC 9562 defines only the version (bits 48–51) and variant (bits 64–65) fields. The remaining 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. Its meaning depends on the application-defined format, so other systems may not be able to interpret its fields.
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 by timestamp, often better B-tree locality; remaining 74 bits depend on generation method. 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 | Dedicated secret generator | Prefer a dedicated cryptographically secure secret-token generator; a UUID should not be used as a password-reset or CSRF secret by default. |
| 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 primarily for uniqueness, not as an authentication mechanism. A UUID should not be used as a standalone authentication credential, 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: a roughly 50% collision probability is reached only after generating about 2.7 × 1018 randomly generated v4 UUIDs under the ideal independent-uniform model. 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 about 1.0 × 1014 UUIDs — a number no practical system approaches.
Has a UUID collision ever actually occurred in production?
Collision reports should be investigated rather than dismissed: mathematical collisions are possible, but duplicates can also come from faulty implementations — 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. |
| Stable namespace-and-name cache keys (CDN, Redis) | v5 | Deterministic: the same chosen namespace and exact name produce the same UUID. Hash raw content separately when true content addressing is required. |
| 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
References
Official UUID Specifications
For the authoritative format and version rules, see the RFC 9562 UUID specification. For database UUID functions, see PostgreSQL 18 UUID documentation.
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