What Is a UUID? Versions, Format and Collision Odds

By 2 min read

A UUID (universally unique identifier) is a 128 bit value used as an ID that can be created anywhere without checking a central list. It is written as 32 hexadecimal digits in five groups, such as 3f2b8c1e-9a4d-4c7f-b2e1-6d5a8f0c9e47. The most common kind, version 4, is almost entirely random.

The format

8-4-4-4-12 hexadecimal digits, separated by hyphens:

xxxxxxxx-xxxx-Mxxx-Nxxx-xxxxxxxxxxxx

  • M is the version. In a version 4 UUID it is always 4.
  • N shows the variant. For standard UUIDs it is 8, 9, a or b.

Common versions

Version How it is made Typical use
1 Time and the machine's network address Older systems
4 Random Most general IDs
5 Hash of a name in a namespace Same input always gives the same ID
7 Time-ordered, with random bits Database keys that sort by creation time

The UUID generator creates version 4 UUIDs using a cryptographically secure random source, one per line or comma separated.

How unlikely is a collision?

A version 4 UUID has 122 random bits, giving about 5.3 × 10³⁶ possible values. You would need to generate around 2.7 billion billion (2.7 × 10¹⁸) UUIDs to reach a 50% chance of a single duplicate. For practical purposes, collisions do not happen if the random source is good.

UUID vs GUID

GUID (globally unique identifier) is Microsoft's name for the same thing. The formats are compatible.

When to use a UUID

  • Distributed systems: many servers can create IDs without coordinating.
  • Public IDs: they do not reveal how many records you have, unlike 1, 2, 3.
  • Offline creation: apps can create records before syncing.

Downsides

  • They are long and hard to read aloud.
  • Random version 4 UUIDs do not sort by time, which can slow some database indexes. Version 7 fixes this.

Not a secret

A UUID is an identifier, not a password. If you need something secret, such as an access token, use a value designed for security. The password generator creates random secrets with a chosen length and character set.

Questions and answers

Can two UUIDs be the same?

In theory, yes, but with version 4 the odds are so small that it does not happen in practice with a good random source.

Is a GUID the same as a UUID?

Yes. GUID is Microsoft’s name for a UUID, and the formats match.

More from the blog