What Is a UUID? (Universally Unique Identifier)
A UUID (Universally Unique Identifier) is a 128-bit identifier formatted as 32 hexadecimal characters in five groups: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx. UUIDs are designed to be globally unique without requiring any central coordinator, registry, or database check.
UUID Versions Explained
UUID v1 encodes the current timestamp and the device's MAC address — making it time-ordered but revealing hardware identity. UUID v3 and v5 are deterministic (same input always produces the same UUID) using MD5 or SHA-1 respectively. UUID v4 uses purely random bits and is the most widely recommended for general use. UUID v7 (RFC 9562, 2024) combines millisecond timestamps with random bits for database-friendly, time-sortable IDs.
How Random Is UUID v4?
UUID v4 has 122 random bits (6 bits are fixed for version and variant). That gives 2^122 ≈ 5.3 × 10^36 possible values. If you generated one billion UUIDs per second, you would need more than 100 billion years to have a 50% chance of a collision. For practical purposes, UUID v4 collision is impossible.
UUID vs Auto-Increment IDs
Auto-increment IDs (1, 2, 3…) are sequential, easy to guess, and require a central database to assign. UUIDs can be generated anywhere (client, server, offline) without coordination, making them ideal for distributed systems, offline-first apps, and multi-tenant architectures where you do not want IDs to be predictable.
UUID vs ULID vs NanoID
ULID (Universally Unique Lexicographically Sortable Identifier) and UUID v7 add timestamp prefixes, making them naturally sortable in databases — an advantage for indices. NanoID generates shorter URL-safe random strings and is often used when UUID's 36-character length is inconvenient. All three are suitable alternatives depending on your requirements.