UUIDs are the invisible infrastructure behind most modern software. Every time you create a database record, upload a file, or start a session in a modern application, a UUID is probably being generated. Understanding the versions and when to use alternatives like ULID and NanoID makes you a more effective developer.
What Is a UUID?
UUID stands for Universally Unique Identifier. It is a 128-bit number represented as 32 hexadecimal digits in five groups separated by hyphens: 550e8400-e29b-41d4-a716-446655440000. Standardised in RFC 4122, UUIDs are designed to be unique across time and space — generated independently on different machines without central coordination, they will almost never collide.
UUID Versions
UUID v1 — combines current timestamp and the generating machine's MAC address. Guaranteed unique per machine per timestamp interval but leaks MAC address and generation time.
UUID v4 — entirely random with 122 random bits. The most widely used version. The probability of two random v4 UUIDs colliding is approximately 1 in 5.3 undecillion. No MAC address or timestamp leakage.
UUID v5 — deterministic: the same namespace and name always produce the same UUID using SHA-1 hashing. Useful for generating stable identifiers from known inputs like URLs or email addresses.
UUID v4 vs ULID
UUIDs are not sortable by generation time — a later UUID does not sort after an earlier one alphabetically. This causes index fragmentation in database engines like PostgreSQL. ULID (Universally Unique Lexicographically Sortable Identifier) encodes a millisecond-precision timestamp in the first 10 characters, making ULIDs sort chronologically. 26 characters of Crockford Base32 — more compact than 36-character hyphenated UUID.
UUID vs NanoID
NanoID is a smaller, URL-safe alternative. Default 21 characters provides collision probability equivalent to UUID v4. Popular in JavaScript for its small package size and shorter strings for URLs.
When to Use Each
UUID v4 — public APIs and cross-system identifiers where RFC 4122 compliance matters. ULID — database primary keys where chronological ordering benefits query performance. NanoID — URLs, slugs, and user-facing identifiers where shorter strings matter.
Generate Free
The Anonymiz UUID Generator generates UUID v4, ULID, and NanoID instantly in your browser. Generate one or bulk-generate hundreds. No account required.
Frequently Asked Questions
Can two UUIDs ever be the same?
Theoretically yes, practically no. UUID v4 has 122 random bits — generating a duplicate while generating one billion per second for 100 years has about 50% probability. For any realistic application, treating UUID v4 as unique is completely safe.
Should I use UUID as a database primary key?
It depends. In PostgreSQL, UUID v4 primary keys cause index fragmentation because inserts are not sequential. Using ULID or UUID v7 (which includes a timestamp) gives unique IDs while maintaining sequential inserts and better index performance.

