Guides

What is a UUID? GUIDs, Versions & When to Use Them

CodeUtilityKit Team··Updated Jul 5, 2026·8 min read

A UUID (Universally Unique Identifier) is a 128-bit value used to uniquely identify information in computer systems. Its defining feature is that anyone can generate one, on any machine, at any time, without coordinating with a central authority — yet the chance of two people ever producing the same UUID is so small it can be treated as zero.

What is a UUID?

A UUID is a 128-bit number, usually written as 32 hexadecimal digits split into five groups by hyphens, like this:

f47ac10b-58cc-4372-a567-0e02b2c3d479

The groups follow an 8-4-4-4-12 pattern. That standard textual form is what you will see in databases, API responses, and log files. Despite looking like a random jumble, the layout is precisely defined by the UUID specification (RFC 4122).

You will also hear the term GUID (Globally Unique Identifier). GUID is simply Microsoft's name for the same thing — for all practical purposes, UUID and GUID are interchangeable.

Why do UUIDs matter?

In a single database, you can use an auto-incrementing integer (1, 2, 3, …) as a unique key. But that breaks down as soon as multiple systems need to create records independently — two servers would both assign ID 100 and collide. UUIDs solve this:

  • No central authority. Any node can mint an ID on its own.
  • Collision-resistant. The address space is so vast (2^122 random values for v4) that duplicates are effectively impossible.
  • Generated anywhere. You can create the ID in the browser, in the app, or in the database — before the record is even saved.

How UUIDs achieve uniqueness

The most common type, version 4, is built almost entirely from random numbers — 122 bits of randomness. The sheer size of that space is what guarantees uniqueness. To put it in perspective, you would need to generate roughly a billion UUIDs per second for about 85 years before the odds of a single collision reached even 50%.

Other versions achieve uniqueness differently — some mix in a timestamp and machine identifier, others derive the value from a name using a hash function.

UUID versions compared

Version Based on Deterministic? Typical use
v1 Timestamp + MAC address No Time-ordered IDs
v3 MD5 hash of a name Yes Legacy name-based IDs
v4 Random data No General-purpose unique IDs
v5 SHA-1 hash of a name Yes Deterministic name-based IDs

Version 4 is the one you will use most often — reach for it whenever you simply need a unique identifier. Version 5 is the choice when you want the same input to always map to the same UUID, such as deriving a stable ID from a URL or username.

When should you use a UUID?

  • Distributed systems where multiple services create records independently.
  • Client-generated IDs, so the app can assign an identifier before talking to the server.
  • Public identifiers where you do not want to expose a guessable, sequential number.
  • Merging data from multiple sources without key conflicts.

The main trade-off: because random UUIDs are not sequential, using them as a primary key can fragment database indexes and slightly slow inserts compared with integers. For most applications this is a non-issue, but at very high write volumes it is worth considering.

UUID vs Nano ID

If a full 36-character UUID feels heavy — for example, in a URL — a Nano ID is a compact, URL-safe alternative with comparable collision resistance in far fewer characters. UUIDs win on standardization and universal tooling; Nano IDs win on brevity.

What does a UUID look like up close?

Not every character in a UUID is random. Two positions are reserved to describe the UUID itself:

f47ac10b-58cc-4372-a567-0e02b2c3d479
               ^    ^
               |    variant
               version

The first digit of the third group encodes the version (a 4 here means version 4), and the first digit of the fourth group encodes the variant. The rest is the actual identifier data. That is how a program can look at any UUID and know how it was generated.

UUIDs in databases: the performance angle

Random version 4 UUIDs make excellent unique keys, but because they are not sequential, inserting them can scatter writes across a database index and cause fragmentation. Two common responses:

  • Use UUIDs as a public identifier while keeping a sequential integer as the internal primary key.
  • Use a time-ordered UUID (version 7, a newer addition) that sorts by creation time while staying unique.

For most applications the overhead is negligible, but it is worth knowing at very high write volumes.

Real-world uses of UUIDs

  • Distributed systems — services that create records without coordinating.
  • Idempotency keys — safely retrying an API request without duplicating it.
  • File and upload names — avoiding collisions when many users upload at once.
  • Session and request IDs — tracing a single request through many services.

How to generate UUIDs online

Conclusion

A UUID is a beautifully simple solution to a hard problem: giving everything a unique name without anyone keeping a master list. Use version 4 for general-purpose IDs, version 5 when you need determinism, and remember that UUID and GUID mean the same thing. When you need one, a browser-based generator will hand you as many as you want in a click.

Try the tools

Frequently Asked Questions

What is the difference between a UUID and a GUID?

There is no practical difference. GUID (Globally Unique Identifier) is Microsoft's name for the same 128-bit UUID standard. The terms are used interchangeably.

Can two UUIDs ever be the same?

In theory yes, in practice effectively never. A version 4 UUID has 122 random bits, so you would need to generate billions of UUIDs per second for many years before a collision became likely.

What is the difference between UUID v4 and v5?

Version 4 UUIDs are random, ideal when you just need a unique value. Version 5 UUIDs are derived from a namespace and a name using hashing, so the same input always produces the same UUID — useful for deterministic IDs.

Should I use a UUID as a database primary key?

UUIDs are great for distributed systems and when you need to generate IDs before saving. The trade-off is that random UUIDs can hurt index performance versus sequential integers, so weigh uniqueness needs against write patterns.

What is a Nano ID and how is it different?

Nano ID is a smaller, URL-friendly alternative to UUID. It offers similar collision resistance with a shorter, more compact string, which is handy for public-facing IDs in links.

CU

CodeUtilityKit Team builds free, privacy-first developer tools that run entirely in your browser. Every guide is written and reviewed by developers who use these tools daily. Last reviewed Jul 5, 2026.