UUID Versions Explained
Understand the differences between UUID versions, how UUID v1, v3, v4, v5 and v7 are generated, and when to use each version.
A UUID, or Universally Unique Identifier, is a 128-bit identifier designed to provide a very high probability of uniqueness without requiring a central authority to assign every value. UUIDs are widely used in web applications, APIs, databases, distributed systems, authentication systems and software development. Different UUID versions use different methods to generate those identifiers, so choosing a UUID version depends on whether an application needs randomness, reproducibility, time ordering or compatibility with an existing system.
The most commonly encountered UUID versions are UUID v1, v3, v4, v5 and the newer UUID v7. Although all of them produce identifiers with the same basic 128-bit size, the information encoded into the identifier and the generation algorithm can be very different.
What Is a UUID?
A UUID is a 128-bit value normally represented as 32 hexadecimal characters separated into five groups by hyphens. The familiar textual representation contains 36 characters including the hyphens.
550e8400-e29b-41d4-a716-446655440000The hexadecimal representation is only a textual form. Internally, a UUID contains 128 bits. Certain bits are reserved for identifying the UUID version and variant, while the remaining bits depend on the generation method used by that version.
| Property | Typical UUID |
|---|---|
| Size | 128 bits |
| Text length | 36 characters including hyphens |
| Hexadecimal digits | 32 |
| Common format | xxxxxxxx-xxxx-Mxxx-Nxxx-xxxxxxxxxxxx |
| Typical use | Unique object or record identification |
Why Do UUID Versions Exist?
UUID versions exist because there is no single ideal way to generate identifiers for every application. Some systems need random identifiers that do not expose information about when they were created. Others need deterministic identifiers that can be reproduced from the same input. Distributed systems may benefit from identifiers that contain a timestamp and sort approximately by creation time.
- UUID v1 uses time and a node identifier.
- UUID v3 uses an MD5-based hash of a namespace and name.
- UUID v4 uses random or pseudorandom data.
- UUID v5 uses a SHA-1-based hash of a namespace and name.
- UUID v7 uses a Unix timestamp combined with random data.
UUID Version Overview
| Version | Generation Method | Main Characteristic |
|---|---|---|
| UUID v1 | Timestamp and node information | Time-based |
| UUID v3 | MD5 namespace and name hash | Deterministic |
| UUID v4 | Random or pseudorandom data | Random |
| UUID v5 | SHA-1 namespace and name hash | Deterministic |
| UUID v7 | Unix timestamp and random data | Time-ordered |
UUID v1 Explained
UUID version 1 is a time-based UUID. It uses a timestamp derived from the UUID time representation together with a clock sequence and node-related information. Historically, the node field was commonly associated with a MAC address, although implementations can use other suitable node identifiers.
xxxxxxxx-xxxx-1xxx-xxxx-xxxxxxxxxxxxThe timestamp makes UUID v1 fundamentally different from UUID v4. It is not simply a random identifier. UUID v1 can provide useful ordering characteristics because identifiers generated at different times contain time-related information.
| Characteristic | UUID v1 |
|---|---|
| Generation | Time-based |
| Randomness | Not the primary mechanism |
| Timestamp | Included |
| Deterministic | No |
| Ordering | Generally time-related |
| Privacy considerations | Potentially reveals timing or node information |
When to Use UUID v1
UUID v1 can be useful in systems that need time-based identifiers and have existing compatibility requirements with version 1 UUIDs. However, for new applications, UUID v7 is often a more attractive time-ordered option because it was designed specifically around modern timestamp-based identifier requirements.
UUID v3 Explained
UUID version 3 generates a UUID deterministically from a namespace and a name using an MD5-based hashing process. If the same namespace and name are supplied to a conforming implementation, the resulting UUID is reproducible.
namespace + name
↓
MD5-based hash
↓
UUID v3The deterministic property is the most important feature of UUID v3. Instead of generating a new random value every time, an application can calculate the same UUID whenever it receives the same namespace and name combination.
| Characteristic | UUID v3 |
|---|---|
| Generation | Namespace and name hash |
| Hash | MD5 |
| Deterministic | Yes |
| Random | No |
| Same input | Produces the same UUID |
UUID v5 Explained
UUID version 5 is similar to UUID v3 because it also creates deterministic identifiers from a namespace and name. The main difference is the hashing algorithm: UUID v5 uses SHA-1 rather than MD5.
namespace + name
↓
SHA-1-based hash
↓
UUID v5UUID v5 is useful when an application needs stable identifiers derived from known names. For example, a system can assign a predictable UUID to a resource based on a namespace and a canonical name without storing a separate mapping between the name and generated identifier.
| Feature | UUID v3 | UUID v5 |
|---|---|---|
| Generation | Namespace + name | Namespace + name |
| Hash algorithm | MD5 | SHA-1 |
| Deterministic | Yes | Yes |
| Random | No | No |
| Same input | Same UUID | Same UUID |
UUID v4 Explained
UUID version 4 is the most widely used UUID version for general-purpose random identifiers. It is generated primarily from random or pseudorandom data, with specific bits reserved for the UUID version and variant.
xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxxUUID v4 does not intentionally encode a timestamp, namespace or application-specific name. This makes it a good default when an application simply needs an identifier that is extremely unlikely to collide and does not need to be naturally ordered.
| Characteristic | UUID v4 |
|---|---|
| Generation | Random or pseudorandom |
| Timestamp | Not encoded |
| Deterministic | No |
| Collision probability | Extremely low with proper randomness |
| Common use | Database records, API resources and application objects |
Why UUID v4 Is So Popular
UUID v4 is simple to understand and does not require coordination between systems. A service can generate an identifier locally without contacting a central ID server. This property is particularly useful in distributed applications where many services, devices or clients create records independently.
- Simple general-purpose identifier generation.
- No central ID allocation service is required.
- Does not intentionally expose creation time.
- Works well across distributed systems.
- Supported by most programming languages and databases.
UUID v7 Explained
UUID version 7 is a modern UUID format designed for identifiers that combine a Unix timestamp with randomly generated data. Unlike UUID v4, UUID v7 contains time information, which gives generated identifiers useful chronological ordering characteristics.
xxxxxxxx-xxxx-7xxx-yxxx-xxxxxxxxxxxxThe timestamp occupies the leading portion of the UUID, while the remaining bits provide randomness and uniqueness. This makes UUID v7 particularly interesting for databases and distributed systems where identifiers are frequently generated and chronological ordering is useful.
| Characteristic | UUID v7 |
|---|---|
| Generation | Unix timestamp + random data |
| Timestamp | Included |
| Randomness | Included |
| Deterministic | No |
| Time ordering | Yes, approximately |
| Modern database use | Well suited |
Why UUID v7 Is Useful for Databases
Random UUIDs such as UUID v4 can be less friendly to database indexes because newly inserted values are distributed throughout the identifier space rather than naturally progressing in time. UUID v7 places timestamp information near the beginning of the identifier, allowing identifiers generated later to generally sort after identifiers generated earlier.
This does not mean UUID v7 automatically solves every database performance problem. Database behavior depends on the storage engine, index implementation, insertion pattern and workload. However, time-ordered identifiers can be useful when a system frequently inserts records and benefits from identifiers that have temporal locality.
UUID v1 vs UUID v4 vs UUID v7
| Feature | UUID v1 | UUID v4 | UUID v7 |
|---|---|---|---|
| Primary basis | Time and node | Randomness | Timestamp and randomness |
| Contains time | Yes | No | Yes |
| Random data | Limited | Primary mechanism | Significant |
| Deterministic | No | No | No |
| Time sortable | Generally | No | Yes |
| Privacy considerations | Higher | Lower | Timestamp is visible |
| Good general default | Usually no | Yes | Often for new systems |
UUID v3 vs UUID v5
UUID v3 and UUID v5 solve a different problem from UUID v4 and UUID v7. They are designed for deterministic identifiers. If an application knows a namespace and a name, it can calculate an identifier without maintaining a separate database mapping.
| Feature | UUID v3 | UUID v5 |
|---|---|---|
| Namespace-based | Yes | Yes |
| Deterministic | Yes | Yes |
| Hash algorithm | MD5 | SHA-1 |
| Random generation | No | No |
| Typical choice | Legacy compatibility | Preferred deterministic option |
How UUID Versions Are Identified
The UUID version is encoded into the UUID itself. In the standard textual representation, the first hexadecimal character of the third group identifies the version. For example, a UUID containing 4 in this position is a version 4 UUID, while a 7 indicates version 7.
xxxxxxxx-xxxx-Mxxx-Nxxx-xxxxxxxxxxxx
↑
version| Version Marker | UUID Version |
|---|---|
| 1 | UUID v1 |
| 3 | UUID v3 |
| 4 | UUID v4 |
| 5 | UUID v5 |
| 7 | UUID v7 |
UUID Variant vs UUID Version
UUID version and UUID variant are related but different concepts. The version identifies the UUID generation scheme, while the variant identifies how the UUID layout and interpretation are defined. A valid UUID therefore contains information about both its version and variant.
This distinction matters when analyzing UUIDs programmatically. A UUID version detector can inspect the version field, but a complete UUID validator may also verify that the value follows the expected structural and variant rules.
Choosing the Right UUID Version
The best UUID version depends on what the identifier needs to accomplish. There is no universal version that is optimal for every application.
| Requirement | Recommended Version |
|---|---|
| Simple random identifier | UUID v4 |
| Time-ordered identifier | UUID v7 |
| Deterministic identifier | UUID v5 |
| Existing system requires legacy time-based UUID | UUID v1 |
| Existing system requires MD5-based UUID | UUID v3 |
UUID v4 or UUID v7?
For new applications, one of the most common decisions is whether to use UUID v4 or UUID v7. UUID v4 is a strong choice when the identifier only needs to be unique and should not intentionally contain creation-time information. UUID v7 is attractive when chronological ordering, timestamp information and database insertion behavior are important.
- Choose UUID v4 for simple random identifiers.
- Choose UUID v7 when time ordering is useful.
- Consider privacy requirements before using timestamp-based identifiers.
- Check database behavior before changing identifier formats.
- Use the UUID version consistently within a system unless interoperability requires otherwise.
Are UUIDs Truly Unique?
UUIDs are designed to make collisions extraordinarily unlikely when generated according to their specifications and with suitable randomness or hashing. They should not be interpreted as mathematically guaranteed unique values in every possible circumstance.
For UUID v4, the practical collision risk depends heavily on the quality of the random number generator. A properly implemented generator provides an enormous number of possible values. Weak or predictable randomness can significantly reduce the safety and uniqueness properties expected from UUID v4.
UUIDs in Distributed Systems
UUIDs are especially useful in distributed systems because independent services can generate identifiers without first asking a central database for the next numeric value. This reduces coordination requirements and makes it easier to create records across multiple machines or regions.
The trade-off is that UUIDs are larger than small integer identifiers and may have different indexing and storage characteristics. UUID v7 can be particularly useful when a distributed application wants decentralized generation together with time-related ordering.
UUIDs as Database Primary Keys
UUIDs can be used as database primary keys, but the choice should consider the database engine and workload. A UUID provides a globally usable identifier, while an auto-incrementing integer is smaller and naturally ordered. Random UUIDs can also produce different index access patterns from sequential numeric keys.
| Identifier | Advantages | Considerations |
|---|---|---|
| Integer ID | Small and naturally sequential | Requires centralized allocation within a database |
| UUID v4 | Distributed and random | Not naturally time ordered |
| UUID v7 | Distributed and time ordered | Larger than integer identifiers |
Common UUID Mistakes
UUIDs are simple to use once their purpose is understood, but several mistakes are common. The most important is choosing a version without considering what information the identifier needs to contain.
- Using UUID v4 when deterministic identifiers are required.
- Using UUID v3 or v5 when random identifiers are required.
- Choosing UUID v1 without considering metadata exposure.
- Assuming UUID v7 is always better than UUID v4.
- Using weak randomness to generate UUID v4 values.
- Treating UUID strings as secure secrets or authentication tokens.
- Changing UUID formats without considering database indexes and APIs.
UUIDs Are Not Authentication Secrets
A UUID can be difficult to guess, especially when generated randomly, but uniqueness and secrecy are different properties. Applications should not automatically treat a UUID as a password, cryptographic key or authorization credential. Security-sensitive tokens should use mechanisms specifically designed for authentication and authorization.
Best Practices for UUIDs
- Choose the UUID version according to the application's actual requirements.
- Use a standards-compliant UUID library instead of implementing generation manually.
- Use UUID v4 when a simple random identifier is sufficient.
- Consider UUID v7 for new systems that benefit from time-ordered identifiers.
- Use UUID v5 when deterministic namespace-based identifiers are required.
- Consider privacy implications of time-based UUID formats.
- Validate UUID input when receiving identifiers from external clients.
- Keep identifier formats consistent across APIs and database schemas.
- Do not use UUIDs as a replacement for dedicated cryptographic secrets.
Frequently Asked Questions
What is the most common UUID version?
UUID v4 is one of the most widely used UUID versions because it provides a simple random identifier suitable for many general-purpose applications. UUID v7 is increasingly useful for systems that also need time ordering.
What is the difference between UUID v4 and UUID v7?
UUID v4 is primarily random, while UUID v7 combines a Unix timestamp with random data. UUID v7 therefore provides useful chronological ordering characteristics that UUID v4 does not.
Are UUID v3 and UUID v5 random?
No. UUID v3 and UUID v5 are deterministic. They calculate an identifier from a namespace and name, so the same inputs produce the same UUID.
Which UUID version should I use for a database?
The correct choice depends on the workload and database. UUID v4 is a common general-purpose option, while UUID v7 can be attractive when time-ordered identifiers and distributed generation are useful.
Can UUID v1 reveal information?
Yes. UUID v1 is time-based and can contain node-related information depending on the implementation. This makes it important to consider privacy and information disclosure requirements.
Can I use a UUID as a password or secret token?
A UUID should not automatically be treated as a security credential. Use dedicated cryptographically secure mechanisms for passwords, session tokens, API secrets and other security-sensitive values.
How can I identify a UUID version?
The UUID version is encoded in the UUID. In the standard textual representation, the version appears in the first hexadecimal character of the third group. For example, a 4 indicates UUID v4 and a 7 indicates UUID v7.
Helpful UUID Tools
A UUID Generator creates UUID values for development and testing, a UUID Version Detector identifies the version encoded in an existing UUID, a UUID Validator checks whether a UUID has a valid structure, a UUID Bulk Generator creates multiple UUIDs at once, and a UUID Extractor finds UUID values inside larger text or documents.
Conclusion
UUID versions provide different ways to generate and use 128-bit identifiers. UUID v1 is time-based and can expose node-related information, UUID v3 creates deterministic identifiers using an MD5-based namespace and name hash, UUID v4 provides random identifiers, UUID v5 creates deterministic identifiers using SHA-1, and UUID v7 combines a Unix timestamp with random data for time-ordered identifiers.
For many general-purpose applications, UUID v4 remains a simple and practical choice. When chronological ordering is important, UUID v7 can provide useful advantages. When the same input must always produce the same identifier, UUID v5 is often the appropriate option. Understanding these differences makes it easier to select an identifier format that fits the application's database, API, distributed-system and privacy requirements.