What Is a UUID? Versions, Formats and When to Use One
You open a database table and see an ID like 550e8400-e29b-41d4-a716-446655440000. It looks random and unusually long. That string is a UUID.
So, what is a UUID, and why do so many applications use one? UUIDs help identify records, files, users and other objects without requiring a central system to assign every ID. They are especially useful in distributed applications where multiple systems need to create identifiers independently.
This guide explains the UUID meaning, format, versions and collision probability. You will also learn how to generate and validate UUIDs, compare them with auto-increment IDs, and choose the right identifier for your project.
UUID Meaning and Basics
What Does UUID Stand For?
UUID stands for Universally Unique Identifier. It is a 128-bit value used to identify data, records or objects.
The idea is straightforward: different systems can generate UUIDs independently, with an extremely low probability of producing the same value when the generation methods are implemented correctly. Unlike auto-increment IDs, UUIDs do not require a central database to assign the next number.
The UUID specification is defined in RFC 9562, published in 2024. It updates the earlier RFC 4122 and describes UUID formats, versions and their intended behavior.
UUID Explained in Plain Terms
Think of a UUID as a long, distinctive label.
Imagine two applications operating in different countries. Both need to create a new customer record while temporarily disconnected from each other. With auto-increment IDs, coordinating unique numbers across both systems can be complicated.
With UUIDs, each application can generate an identifier independently. When the records are synchronized later, the chance of an accidental duplicate is extremely small when suitable generation methods are used.
This makes UUIDs useful for distributed databases, cloud applications, microservices and offline-first software.
UUID vs GUID
GUID stands for Globally Unique Identifier. Microsoft commonly uses this term, while UUID is the name used in the broader standard and many programming environments.
In practice, the terms usually refer to the same type of 128-bit identifier. However, some platforms have their own implementation details, APIs or formatting conventions.
You will commonly encounter UUIDs in web development, Linux tools and databases, while GUID is especially familiar in Windows and .NET development.
UUID Format and Length
UUID Format
A conventional UUID is represented by 32 hexadecimal digits separated into five groups. The group pattern is 8-4-4-4-12.
For example:
550e8400-e29b-41d4-a716-446655440000
Each hexadecimal digit represents four bits and can be a number from 0 to 9 or a letter from a to f. Uppercase letters are also accepted in conventional UUID text representations, although lowercase is common.
The hyphens make the value easier to read. They do not add any information to the underlying 128-bit identifier.
UUID Length
A UUID contains 128 bits, equivalent to 16 bytes.
| Representation | Length |
|---|---|
| Binary value | 16 bytes |
| Hexadecimal text without hyphens | 32 characters |
| Conventional text with hyphens | 36 characters |
This distinction matters when designing a database. A native UUID column or a compact 16-byte binary representation can use less storage than a 36-character text representation, depending on the database and encoding.
However, storage is only one consideration. Indexing, database compatibility, query performance and application requirements also matter.
Reading the Version and Variant
Some bits in a UUID identify its format version and variant.
In the example below, the version is 4:
550e8400-e29b-41d4-a716-446655440000
^
The version is represented by the first hexadecimal digit of the third group.
For UUIDs using the standard RFC variant, the first hexadecimal digit of the fourth group is 8, 9, a or b. This reflects the relevant variant bits.
These details help software interpret a UUID’s structure. A format check alone, however, cannot establish that a UUID was generated correctly or that a database record associated with it exists.
UUID Versions Compared
Different UUID versions use different methods to create identifiers. Choosing the right version depends on whether you need random IDs, time ordering or repeatable identifiers.
UUID v1
UUID version 1 is based on a timestamp and a node identifier. The node identifier may be derived from a network interface’s MAC address or generated using an alternative method.
UUID v1 values can reveal information about when they were created. Depending on how the node identifier is generated, they may also expose information about the originating system.
These properties can create privacy concerns. UUID v1 can still be appropriate for legacy applications, but its time and node information should be considered before using it in new systems.
UUID v4
UUID version 4 is based on random or pseudorandom values generated according to the UUID specification. Version and variant bits are reserved, leaving 122 bits for random data.
For many applications, v4 is a straightforward choice because it does not encode a timestamp or hardware identifier in the way v1 does.
UUID v4 is widely supported and suitable for database records, application objects and distributed systems. Use an implementation that relies on a suitable cryptographically secure random source when generating v4 UUIDs.
Although the probability of a collision is extremely small, a UUID is not a substitute for database uniqueness constraints or access-control checks.
UUID v7
UUID version 7 is defined in RFC 9562. Its leading 48 bits contain a Unix timestamp measured in milliseconds. The remaining fields include random data and may include additional bits used by implementations to improve uniqueness or ordering.
Because the timestamp appears at the beginning, UUID v7 values are generally sortable by creation time when compared in their standard representation.
This can be useful for database keys and event records. Time-oriented ordering may improve index locality compared with randomly distributed v4 values.
However, UUID v7 does not guarantee that every generated identifier will be strictly ordered by creation time across all systems. Clock differences, multiple generators and implementation details can affect ordering. Database performance improvements are also workload-dependent and should be tested.
UUID v1 vs v4 vs v7
| Feature | UUID v1 | UUID v4 | UUID v7 |
|---|---|---|---|
| Main basis | Timestamp and node identifier | Random data | Timestamp and random or additional data |
| Contains a timestamp | Yes | No | Yes |
| Time-sortable | Not in the usual text order | No | Yes, generally |
| May expose node information | Depending on implementation | No node identifier is encoded as in v1 | No node identifier is encoded as in v1 |
| Common use | Legacy systems | General-purpose IDs | Time-ordered database and event IDs |
For general-purpose identifiers, v4 is a practical default. If time-based sorting is valuable, consider v7. If you are maintaining an older system that uses v1, assess its privacy and compatibility requirements before changing versions.
Other UUID Versions
UUID versions 3, 5, 6 and 8 provide additional options.
- UUID v3: Generates a deterministic UUID from a namespace and a name using MD5.
- UUID v5: Generates a deterministic UUID from a namespace and a name using SHA-1.
- UUID v6: Reorders timestamp fields from the v1 design to make UUIDs more suitable for time-based sorting.
- UUID v8: Provides a format for custom UUID layouts, subject to the specification’s requirements.
Versions 3 and 5 are useful when the same namespace and name must produce the same identifier consistently. They are not intended to provide cryptographic secrecy.
Version 6 can be useful when working with time-ordered identifiers and systems designed around the v1 family. Version 8 is intended for specialized applications that need a custom UUID layout.
How to Generate and Validate a UUID
How to Generate a UUID
Most mainstream programming languages and development environments provide UUID-generation functions or libraries.
JavaScript
In browsers that support the Web Crypto API, crypto.randomUUID() generates a v4 UUID. It is generally available in secure contexts, such as HTTPS pages, with some browser-specific exceptions.
const id = crypto.randomUUID(); console.log(id); // Example output: // 3b241101-e2bb-4255-8caf-4136c566a962
The example output is illustrative; your generated UUID will normally be different.
Python
Python’s built-in uuid module can generate a v4 UUID:
import uuid identifier = uuid.uuid4() print(identifier)
The result is a UUID object. Printing it displays the conventional hyphenated representation.
Linux and macOS terminal
Many Linux and macOS systems provide a uuidgen command:
uuidgen
The output is a UUID, although the exact version and available options can depend on the operating system and implementation.
PostgreSQL
PostgreSQL supports gen_random_uuid() in current releases:
SELECT gen_random_uuid();
This function generates a version 4 UUID. Check your database version and documentation if you are using an older installation or a different database engine.
Not every language or library supports UUID v7 natively. If you need v7, choose an implementation that explicitly supports RFC 9562 and verify its compatibility with your runtime.
UUID Generator and Validator Tools
A UUID generator creates one or more identifiers. A UUID validator checks whether a supplied string follows the expected UUID format and, when configured to do so, whether it matches a particular version.
Validation can involve checking:
- The expected group lengths and hexadecimal characters.
- The required hyphens in the conventional representation.
- The version and variant bits, where relevant.
- Any application-specific restrictions.
A regular expression can help check the textual format, but it should not be treated as a complete validation system for every UUID version.
If you use an online UUID tool, consider whether the data you enter is sensitive. You can usually generate ordinary UUIDs locally without sending anything to an external website.
Security note: A UUID is an identifier, not an authorization mechanism. Even if a UUID is difficult to guess, your application must still check whether the requester has permission to access the associated resource. For passwords, API secrets or authentication tokens, use a purpose-built secure token-generation method.
UUID Collision Probability
Can Two UUIDs Be the Same?
Yes. A UUID collision is possible in principle, but collisions between properly generated UUID v4 values are extraordinarily unlikely at ordinary application scales.
UUID v4 reserves six of its 128 bits for the version and variant, leaving 122 random bits. This gives:
2122 ≈ 5.3 × 1036
possible random combinations.
The probability of at least one collision increases as more UUIDs are generated. This is known as the birthday problem.
For UUID v4, generating approximately 2.7 × 1018 identifiers gives a roughly 50% chance of at least one collision, assuming independent, uniformly distributed random values.
That is an enormous number of identifiers. At a hypothetical rate of one billion UUIDs per second, reaching that number would take roughly 86 years. This is a mathematical illustration, not a prediction of what a real system will experience.
What Can Cause UUID Collisions?
A collision can occur even when the theoretical probability is very low. Practical risks include:
- Poor random-number generation.
- Incorrect custom UUID implementations.
- Reusing random seeds or state inappropriately.
- Software bugs that accidentally reuse previously generated IDs.
Cloned virtual machines or improperly restored application environments can also cause problems if random-number generation is mishandled.
Use a reputable UUID library and a suitable random source. For database records, enforce uniqueness with a primary key or unique constraint so that an unexpected duplicate is detected rather than silently accepted.
UUID vs ID: Which Should You Use?
UUID vs Auto-Increment ID
An auto-increment ID is a number assigned sequentially by a database or another coordinating system. A UUID is a 128-bit identifier that can be generated independently.
Neither option is universally better. The right choice depends on the database, application architecture, scale and operational requirements.
| Feature | Auto-increment ID | UUID |
|---|---|---|
| Typical size | 4 or 8 bytes for common integer types | 16 bytes in binary form |
| Readability | Usually easy to read | Longer and harder to read |
| Generation | Usually coordinated by a database or sequence | Can be generated independently |
| Guessability | Sequential values are easy to predict | Random v4 values are difficult to predict, but are not access control |
| Combining records from separate systems | May require ID remapping | Often easier when independently generated |
| Index behavior | Sequential inserts can have good locality | v4 is random; v7 can provide time-oriented locality |
| Storage and index overhead | Often lower | Often higher |
The storage figures are typical examples, not universal limits. For example, an integer may use four or eight bytes, while a UUID stored as text needs more space than its 16-byte binary representation.
UUID Use Cases
UUIDs are especially useful in the following situations:
- Distributed systems and microservices: Multiple services can create identifiers without sharing a single counter.
- Public URLs and APIs: UUIDs avoid exposing simple sequential numbering, although they do not replace authentication or authorization.
- Offline-first applications: A device can create records while disconnected and synchronize them later.
- Merging databases: Independently generated IDs can reduce conflicts when combining data from different systems.
- Event tracking and file references: UUIDs provide distinctive labels for events, files and application objects.
- Time-oriented records: UUID v7 can help when identifiers should sort approximately by creation time.
When to Skip a UUID
A simple integer may be a better choice when one database controls record creation and compact, readable identifiers are important.
Integers generally require less storage than UUIDs and can be convenient for indexes, joins and logs. For systems with high write volumes, the effect of each identifier type on index locality and performance should be measured.
You can also use a combination: keep an internal integer primary key while exposing a separate UUID as a public identifier. This design is useful in some applications, although it introduces another field to maintain.
Remember that an obscure or unpredictable ID does not protect data by itself. Your application must verify permissions for every request, regardless of whether the identifier is an integer or a UUID.
Conclusion
A UUID is a 128-bit identifier commonly written as 32 hexadecimal digits in an 8-4-4-4-12 pattern. It allows applications to create identifiers independently, which makes UUIDs useful for distributed systems, offline applications and database integrations.
UUID v4 is a practical choice for general-purpose random identifiers. UUID v7 adds timestamp-based ordering that may help with database indexes and time-oriented records. UUID v1 and other versions have different characteristics, so consider their behavior before choosing one.
Collisions are extremely unlikely when UUIDs are generated correctly, but database uniqueness constraints still provide a valuable safeguard. Likewise, UUIDs should never replace proper authorization or secure token-generation practices.
Choose a UUID when independent generation or easier data merging is important. Choose an integer when compact storage, readability and simple sequential IDs better suit your application. The right identifier is the one that fits your system’s actual requirements.
Frequently asked questions
What is a UUID?
A UUID is a 128-bit Universally Unique Identifier used to label records, objects and other data. It can be generated independently by different systems, with a very low probability of duplication when appropriate generation methods are used.
What does UUID stand for?
UUID stands for Universally Unique Identifier.
Is a UUID the same as a GUID?
In most everyday programming contexts, yes. UUID is the standardized term, while GUID is commonly used in Microsoft technologies. Particular implementations may have their own conventions.
Which UUID version should I use?
UUID v4 is a practical general-purpose option for random identifiers. UUID v7 is worth considering when time-oriented sorting and database index locality matter. The best choice depends on your application and implementation requirements.
How long is a UUID?
A UUID contains 128 bits, or 16 bytes. Its conventional hexadecimal text representation is 36 characters long, including hyphens, or 32 characters without them.
Can two UUIDs be the same?
Yes, a collision is possible. For properly generated UUID v4 values, the probability is extremely small at ordinary scales. Database uniqueness constraints remain useful as a safeguard.
Is a UUID secure?
UUIDs can be useful identifiers, but they are not automatically secure secrets. Use a cryptographically secure random source for v4 generation, and never rely on an identifier alone to control access to private information.
Can I use a UUID as a database primary key?
Yes. Many databases support UUID primary keys. Consider storage, indexing, application compatibility and insert performance before choosing a UUID over an integer key.
What is the difference between UUID v4 and v7?
UUID v4 uses random data, while UUID v7 includes a Unix timestamp in its leading bits along with other fields. As a result, v7 is generally sortable by creation time, whereas v4 does not provide time ordering.
How can I validate a UUID?
Check the string’s hexadecimal characters, group lengths, hyphen placement and, where necessary, its version and variant bits. Use a maintained library when you need version-aware validation rather than relying only on a regular expression.