$devtoolkit.sh/glossary/what-is-uuid

What is a UUID? — Universally Unique Identifier Explained

Definition

A UUID (Universally Unique Identifier) is a 128-bit identifier standardized by RFC 4122 that is designed to be unique across time and space without requiring a central authority. UUIDs are represented as 32 hexadecimal characters in 5 groups separated by hyphens: xxxxxxxx-xxxx-Mxxx-Nxxx-xxxxxxxxxxxx. The M digit encodes the version and N encodes the variant. UUIDs are widely used as primary keys in distributed databases, identifiers in APIs, and unique names for resources across systems that cannot coordinate ID generation.

How It Works

Different UUID versions use different strategies for generating unique values. UUID v1 uses the current timestamp and the MAC address of the generating machine — unique but reveals hardware identity and is not random. UUID v4 uses 122 bits of cryptographically random data — the most common version, suitable for most use cases. UUID v5 and v3 use a namespace and a name hashed with SHA-1 or MD5 respectively — deterministic, useful for generating consistent IDs for known entities. UUID v7 (RFC 9562) encodes a millisecond timestamp in the leading bits followed by random data, making UUIDs sortable by creation time while remaining random.

Common Use Cases

  • Database primary keys that can be generated client-side without coordination
  • Public-facing API identifiers that do not reveal internal sequence numbers
  • Generating unique file names for uploaded assets
  • Idempotency keys for API requests to prevent duplicate processing
  • Correlation IDs for distributed tracing across microservices

Example

UUID v4 (random):
f47ac10b-58cc-4372-a567-0e02b2c3d479

UUID v7 (time-sortable):
018e2507-f21e-7abc-9def-123456789abc
 └─ millisecond timestamp

UUID v5 (namespace + name):
NS: DNS, Name: "example.com"
Result: always the same deterministic UUID

Related Tools

FAQ

Are UUID v4 collisions possible?
Theoretically yes, but practically impossible. UUID v4 has 122 random bits, giving about 5.3 × 10^36 possible values. To have a 50% chance of a collision you would need to generate 2.71 × 10^18 UUIDs — about 85 years at a billion UUIDs per second.
Should I use UUIDs or auto-increment integers as database primary keys?
Auto-increment integers are smaller, faster to index, and sortable. UUIDs allow distributed generation, do not expose record counts, and work better in distributed systems. UUID v7 is a good middle ground: sortable like integers, distributed like UUIDs, and avoids the index fragmentation problem of random v4 UUIDs.
What is the difference between UUID v4 and CUID/ULID/NanoID?
CUID, ULID, and NanoID are alternative unique ID schemes with specific advantages. ULID is URL-safe and lexicographically sortable. NanoID is URL-safe with a configurable alphabet. CUID v2 is designed to avoid collision fingerprinting. UUID v4 has the advantage of being a universal standard.

Related Terms

/glossary/what-is-uuidv1.0.0