GUID V4 - Random-Based Identifier (Recommended)
GUID v4 is the most widely used random-based identifier. Learn about its structure, collision probability, advantages and why it is recommended for general-purpose applications.
GUID v4 and v7 are the two most important versions developers should know today. V4 is the long-standing default built on pure randomness, while v7 is the modern successor that adds a Unix Epoch timestamp prefix for time-based ordering. This page compares their design, strengths, trade-offs and helps you decide which to use.
GUID / UUID v4 was defined around 1997, standardized in RFC 4122 in July 2005 and carried forward into RFC 9562 in May 2024. It remains the most popular and widely deployed version.
GUID / UUID v7 was officially standardized in RFC 9562 in May 2024. It is a modern, actively recommended version designed to address v4's limitations around sortability and database performance.
The table below uses the same attributes shown in the full GUID / UUID version comparison, filtered to v4 and v7.
| Property | v4 | v7 |
|---|---|---|
| Type | Random | Time ordered + random |
| Appeared | 1997 | ~2022 |
| Deterministic? | No | No |
| Sortable? | No | Yes |
| Secure? | Yes | Yes |
| Typical Use | General purpose (Recommended) | Latest most modern |
| Standardized | RFC 4122 + RFC 9562 (July 2005 + May 2024) | RFC 9562 (May 2024) |
| Deprecated? | No | No |
| Notes | Pure randomness (122 random bits). Extremely low collision probability. | Combines millisecond timestamps with strong randomness. Ideal for distributed systems. |
V4 fills 122 of its 128 bits with cryptographically random data. The result is an identifier with no inherent order, no embedded metadata and maximum privacy.
V7 dedicates the first 48 bits to a Unix Epoch timestamp in milliseconds and fills the remaining bits (after version/variant) with randomness (or a counter). This means v7 GUIDs / UUIDs generated later are lexicographically greater, which databases and indexes can exploit.
Random v4 keys scatter inserts across B-tree pages, causing page splits and lower cache locality in many databases. V7's sequential-ish nature reduces these problems significantly and often approaches the insert performance of auto-increment integers.
For more detail, see our GUID / UUID Database Performance and Indexing guide.
V4 reveals nothing about when, where or by whom it was generated, making it safe for public-facing URLs and API keys where timing metadata must stay private.
V7 embeds an approximate creation timestamp (millisecond precision) in the first 48 bits. Anyone with access to the GUID can extract the creation time. If timestamp privacy is critical, v4 is the safer choice.
V4 has 122 random bits, giving roughly 5.3 × 10³⁶ possible unique values. To put this in perspective: even if you generated 1 billion GUIDs / UUIDs per second, non-stop, for 100 years, the probability of producing a single duplicate is still effectively zero.
V7 has 74 random bits per millisecond, giving roughly 1.9 × 10²² unique values per millisecond. Even if you generated 1 trillion GUIDs / UUIDs within the same millisecond, the probability of a collision would still be less than 1 in 18 million. Combined with the 48-bit timestamp (which provides uniqueness across different milliseconds), v7's total collision space is similarly vast.
In short: v4 has more randomness per individual ID, while v7 adds time-based separation on top of its randomness. Both versions have effectively zero collision risk in any practical scenario.
The most impactful advantage of v7 is its time-ordered structure. When used as a primary key, v7 GUIDs / UUIDs insert near the end of B-tree indexes rather than at random positions. This dramatically reduces page splits, write amplification and index bloat in PostgreSQL, MySQL, SQL Server and most other relational databases. Many teams that switched from v4 to v7 report measurable improvements in write throughput and reduced storage overhead.
V7 gives you approximate creation-time ordering without an extra created_at column. Sorting by the primary key yields a roughly chronological list, which simplifies pagination, event streaming, audit logs and "latest first" queries. With v4 you need a separate indexed timestamp column to get the same behavior.
The RFC 9562 standard (May 2024) explicitly introduces v7 as the preferred time-ordered UUID, superseding older approaches like v1 and v6. Language runtimes and libraries are rapidly adding native v7 support: Python 3.13+ (uuid.uuid7()), .NET 9+ (Guid.CreateVersion7()), Go's google/uuid v1.4+, Rust's uuid crate v1.3+, and Node.js uuid v9+.
Just like v4, v7 can be generated independently on any node without coordination, central authority or shared state. Migrating from v4 to v7 requires no infrastructure changes — only swapping the generation call.
The only meaningful cost of v7 is timestamp disclosure: the first 48 bits reveal when the GUID / UUID was created. For internal IDs (database PKs, message queues, microservice correlation IDs) this is rarely a concern. For truly public-facing tokens where timing must stay secret, v4 is still the right choice.
Both versions are 128-bit identifiers using the standard 8-4-4-4-12 canonical format (32 hex digits + 4 hyphens = 36 characters). They differ in how those 128 bits are allocated.
Field Name Bits Hex Description
─────────────────────────────────────────────────────────────────────────
random_low 32 8 32 random bits
random_mid 16 4 16 random bits
random_hi_and_version 16 4 12 random bits + 4-bit version (0100)
random_seq_hi_and_reserved 8 2 2-bit variant (10) + 6 random bits
random_seq_low 8 2 8 random bits
random_node 48 12 48 random bits
Field Name Bits Hex Digits Description
─────────────────────────────────────────────────────────────────────────
unix_ts_ms 48 12 Unix Epoch timestamp in milliseconds (big-endian)
ver 4 1 4-bit version field (0111 = 7 in hex)
rand_a 12 3 12 random bits
var 2 ~0.5 2-bit variant field (10 = RFC 4122 variant)
rand_b 62 ~15.5 62 random bits (or counter + random)
Canonical format: 8-4-4-4-12
Layout: xxxxxxxx-xxxx-Mxxx-Nxxx-xxxxxxxxxxxx
^ ^
| └─ N = Variant: typically 8, 9, a or b (RFC variant)
└────── M = Version: "4" for v4, "7" for v7
V4 example: 5c98eda8-b852-4eec-9960-ac2e29d734f4
V7 example: 018f3f5e-1c2d-7a9b-8f10-3c4d5e6f7a8b
Try our GUID Validator to validate, decode and visualize the bit-level structure of v4 and v7 GUIDs / UUIDs.
GUID / UUID v7 is emerging as the modern default for new applications. Its time-ordered design delivers real-world performance gains for databases, simplifies chronological queries and costs almost nothing in implementation complexity. V4 remains a solid, well-proven choice for scenarios where timestamp privacy matters or where ordering simply isn't needed.
For new projects, prefer v7 unless you have a specific reason to avoid revealing creation timestamps. For existing v4 systems, evaluate whether the performance and ordering benefits of v7 justify the switch for your workload.
These articles expand on related concepts, formats and practical considerations.