UUID Universal Unique Identifier Explained
The calculator for this page is switched off while it is checked. The formula is below, and the worked example in the article shows how to use it by hand.
A UUID (Universally Unique Identifier) is a 128-bit number used to uniquely identify information in computer systems. This calculator generates a random UUID (version 4) and shows its structure, helping you understand how these identifiers are constructed and why they are practically unique.
Formula
The calculator produces a version 4 UUID, which is defined by RFC 4122. The format is 32 hexadecimal digits grouped as 8-4-4-4-12, for example f47ac10b-58cc-4372-a567-0e02b2c3d479. The version digit (the first character of the third group) is always 4, and the variant digits (the first character of the fourth group) are one of 8, 9, a, or b. All other bits are randomly generated.
The formula for a version 4 UUID is:
UUID = 4 × 16^31 + random bits (with fixed version/variant bits)
where:
- Timestamp (ms) – optional input used as a seed for the random number generator (not part of the UUID itself).
- Random bits – 122 bits of randomness (the remaining 6 bits are fixed for version and variant).
Worked Example
Using the default input (timestamp = 0), the calculator generates a random UUID. For instance, it might produce:
4f7b3a2e-9c81-4d2a-bf4c-1a2b3c4d5e6f
Breaking it down:
- First group:
4f7b3a2e(8 hex digits) - Second group:
9c81(4 hex digits) - Third group:
4d2a– starts with4, confirming version 4. - Fourth group:
bf4c– starts withb, confirming the variant. - Fifth group:
1a2b3c4d5e6f(12 hex digits)
The exact output will differ each time because it is random, but the structure and the version/variant digits remain consistent.
What is a UUID?
A UUID is a standardized identifier that does not require a central registration authority. It is widely used in software development for database keys, distributed systems, and file identifiers. The key property is uniqueness: the probability of two randomly generated UUIDs colliding is astronomically small, around 1 in 2^122.
There are several versions of UUIDs, each with a different generation method:
- Version 1 – based on the current timestamp and the MAC address of the generating machine.
- Version 3 – based on an MD5 hash of a namespace and a name.
- Version 4 – completely random (this calculator).
- Version 5 – based on a SHA-1 hash of a namespace and a name.
Version 4 is the most common because it requires no coordination and is simple to generate.
How to Choose a UUID Version
Selecting the right UUID version depends on your use case:
- Version 4 (random) – best for most applications where identifiers are created independently and collision is virtually impossible. It is the default choice for modern systems.
- Version 1 (time-based) – useful when you need to sort by creation time, but it leaks the MAC address, which can be a privacy concern.
- Version 3 or 5 (name-based) – ideal when you need the same UUID for the same input (e.g., deterministic mapping of a username). Version 5 is preferred over version 3 because SHA-1 is more secure than MD5.
For most new projects, version 4 is recommended. If you need determinism, use version 5 with a proper namespace.
Common Problems and Misconceptions
One common misconception is that UUIDs are guaranteed to be unique. In practice, they are not mathematically guaranteed, but the probability of collision is so low that they are treated as unique. For example, to have a 50% chance of a collision, you would need to generate about 2^61 UUIDs (roughly 2.3 quintillion).
Another issue is that UUIDs are often stored as strings, which take more space than integers. In databases, using a UUID as a primary key can lead to index fragmentation because they are not sequential. Solutions include using UUIDs as binary (16 bytes) or using a separate auto-increment integer key.
Also, some systems use UUIDs in URLs, but they are not URL-safe by default. You can use a base64 or hex encoding to make them URL-friendly.
UUID vs. Other Identifiers
UUIDs are not the only type of identifier. Here is a comparison with common alternatives:
- Auto-increment integers – simple and small, but require a central authority (the database) and can be predictable.
- GUID (Globally Unique Identifier) – Microsoft’s implementation of UUID, essentially the same thing.
- ULID (Universally Unique Lexicographically Sortable Identifier) – a 128-bit identifier that is sortable by time, combining a timestamp and randomness.
- NanoID – a shorter, URL-safe identifier (often 21 characters) that uses a larger alphabet, making it more compact than a UUID.
UUIDs offer a balance of uniqueness, standardization, and ease of generation without coordination, which is why they remain popular.
Safety and Privacy Considerations
Version 4 UUIDs are safe to expose publicly because they contain no information about the generator. However, version 1 UUIDs include the MAC address, which can be used to identify the machine that created them. If privacy is a concern, avoid version 1 or strip the MAC address (some implementations allow this).
Also, when using UUIDs in security contexts (e.g., session tokens), ensure they are generated with a cryptographically secure random number generator. This calculator uses a simple seed for demonstration; in production, always use a secure source of randomness.
Frequently Asked Questions
What does UUID stand for?
UUID stands for Universally Unique Identifier. It is a 128-bit number used to identify information in computer systems, standardized by the Open Software Foundation (OSF) and later by RFC 4122.
Is a UUID the same as a GUID?
Yes, GUID (Globally Unique Identifier) is Microsoft’s implementation of the UUID standard. They are interchangeable in most contexts, though GUID sometimes refers to specific variants used in Windows.
Can two UUIDs be the same?
Technically yes, but the probability is negligible. With version 4 (random) UUIDs, the chance of collision is about 1 in 2^122, which is effectively zero for any realistic number of generated UUIDs.
How long is a UUID?
A UUID is 128 bits long, typically represented as 32 hexadecimal digits in the format 8-4-4-4-12, such as 123e4567-e89b-12d3-a456-426614174000.
Why do UUIDs have hyphens?
The hyphens are for readability and are part of the canonical textual representation defined by RFC 4122. They separate the fields: time-low, time-mid, time-high-and-version, clock-seq-and-variant, and node.
Can I use a UUID as a primary key in a database?
Yes, but be aware of performance implications. UUIDs are larger than integers and can cause index fragmentation. Using binary storage (16 bytes) or a sequential UUID variant (like version 7) can mitigate these issues.
Related
Formula used
in t | Timestamp (ms) | - | 0 | 0 out uuid | Generated UUID | - | generate_uuid(t) | 0
Each line is one input (in, sel, list) or one result (out: label, unit, formula, decimals). How the calculators work
Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.