What Is a UUID? Versions, Uniqueness and When to Use Them
Updated October 22, 2026
A UUID is an ID that you can create anywhere, at any time, without asking a central server, and still be almost certain that it is unique. This guide explains how they work.
What a UUID looks like
A UUID is 128 bits written as 32 hexadecimal digits in five groups: 8-4-4-4-12, for example 018f3c2e-7b1a-7c4d-9a2b-3f5e6d7c8b9a. One digit shows the version and another the variant, so a program can tell what kind it is.
The versions in short
| Version | Based on | Best for |
|---|---|---|
| 1 | Time and the computer's network address | Legacy systems |
| 4 | Random numbers | General purpose IDs |
| 5 | A SHA-1 hash of a name | The same ID for the same input |
| 7 | Unix time plus random numbers | Database keys that sort by creation time |
Can two UUIDs be the same?
A version 4 UUID has 122 random bits, which is about 5.3 × 10^36 possibilities. If you generated a billion UUIDs every second, it would take around 85 years before a collision had a 50% chance. In practice you can treat them as unique.
UUIDs or numbers as database IDs?
| Auto-increment number | UUID | |
|---|---|---|
| Size | 4 or 8 bytes | 16 bytes |
| Create without the database | No | Yes |
| Safe to show in a web address | Guessable (/orders/1001) | Hard to guess |
| Merging data from several systems | IDs can clash | No clashes |
| Index speed | Fast, in order | v4 is scattered; v7 is in order |
Which version should you pick?
- Version 4 when you need a simple, unpredictable ID.
- Version 7 for new database primary keys, because it keeps new rows in order and the index compact.
- Do not use a UUID as a secret or a password. It is made to be unique, not unguessable by design.
Frequently asked questions
What is the difference between a UUID and a GUID?
None in practice. GUID is the name used in Microsoft products for the same 128-bit identifier.