What is a UUID?

Universally Unique Identifiers, also called GUIDs, and how they work.

Overview

A UUID is a 128-bit label used to identify things in computer systems without a central authority handing out numbers. It is written as 32 hexadecimal digits in five groups separated by hyphens (8-4-4-4-12), 36 characters in all:

123e4567-e89b-12d3-a456-426614174000

UUIDs are defined by RFC 9562 (May 2024), which replaced RFC 4122 and added versions 6, 7 and 8 plus the max UUID. Because any machine can create one independently, UUIDs are ideal for distributed systems, offline clients, and merging data from separate databases.

The same number, many formats

FormatExample
Standard123e4567-e89b-12d3-a456-426614174000
GUID / registry{123E4567-E89B-12D3-A456-426614174000}
URNurn:uuid:123e4567-e89b-12d3-a456-426614174000
No hyphens123e4567e89b12d3a456426614174000
Decimal24249434048109030647017182301789831168

Paste any of them into the decoder to convert between formats.

How unique is unique?

Uniqueness is probabilistic. In a version 4 UUID, 6 of the 128 bits are fixed (version and variant), leaving 122 random bits: roughly 5.3 × 1036 values. Generating a billion UUIDs per second for about 85 years gives only a 50% chance of one duplicate. For real applications, accidental collisions are not a practical concern as long as the random source is cryptographically secure.

UUID vs GUID

They are the same thing. "GUID" is Microsoft's name (Guid.NewGuid() in .NET, NEWID() in SQL Server) and tends to be written uppercase. One subtlety: .NET stores the first three fields little-endian in memory, so the raw bytes differ from the RFC byte order even though the text is identical. Use the GUID generator for Microsoft-style output.

UUIDs as database keys

UUIDs let applications create IDs before inserting a row, which simplifies distributed writes, offline sync and merging data. The cost is size (16 bytes vs 4 or 8 for integers) and, for random v4, poor index locality. Version 7 fixes the locality problem because it starts with a timestamp. Store UUIDs in a native uuid column (PostgreSQL) or BINARY(16) (MySQL) rather than as 36-character strings.

Which version should I use?

  • v4: random, general purpose.
  • v7: time-ordered, best for database keys.
  • v5: deterministic IDs from a name.
  • v1 / v6: legacy time-based.

Details for every version: UUID versions explained.

Frequently asked questions

What does UUID stand for?

Universally Unique Identifier. Microsoft calls the same thing a GUID, a Globally Unique Identifier.

Are UUIDs really unique?

Not guaranteed, but collisions are astronomically unlikely. A random v4 UUID has 122 random bits, about 5.3 x 10^36 possible values. You would need to generate about 1 billion UUIDs per second for roughly 85 years to reach a 50% chance of a single duplicate.

What is the difference between a UUID and a GUID?

None in practice: they are the same 128-bit identifier. GUID is the Microsoft term and is often written in uppercase with braces.

Which UUID version should I use?

Use v4 for random identifiers and v7 for database primary keys. Use v5 when you need the same input to always give the same UUID.