UUIDs (Universally Unique Identifiers) are 128-bit values used to uniquely identify information in computer systems. They appear everywhere: database primary keys, session tokens, file names, distributed system event IDs, and API resources. This guide covers what UUIDs are, the differences…
UUIDs (Universally Unique Identifiers) are 128-bit values used to uniquely identify information in computer systems. They appear everywhere: database primary keys, session tokens, file names, distributed system event IDs, and API resources. This guide covers what UUIDs are, the differences between versions, and when to use each.
What Is a UUID?
A UUID is a 128-bit number, typically displayed in the format 550e8400-e29b-41d4-a716-446655440000 — 32 hexadecimal digits grouped in 8-4-4-4-12 pattern. The specification is defined in RFC 4122. There are over 340 undecillion (3.4 × 10^38) possible UUIDs, making collisions effectively impossible in practice.
UUID Versions Explained
UUID v1 — Time-Based
Version 1 UUIDs encode the current timestamp and the MAC address of the machine generating them. They’re monotonically increasing, which is great for database indexing (fewer B-tree page splits). The downside: they expose your MAC address and have limited privacy guarantees.
UUID v4 — Random
Version 4 UUIDs are generated using cryptographically secure random numbers. They offer no information about when or where they were created, which is generally desirable for privacy and security. This is the most commonly used version today. Use our online UUID generator to generate v4 UUIDs in bulk.
UUID v5 — Name-Based (SHA-1)
Version 5 generates a UUID deterministically from a namespace and a name using SHA-1 hashing. The same input always produces the same UUID. Useful for generating stable identifiers for resources based on their URL or name.
UUIDs vs. Auto-Increment IDs
Auto-increment integers are simple and efficient, but they have limitations: they reveal record counts, make it easy to enumerate resources, and create merge conflicts in distributed databases. UUIDs solve all three problems at the cost of larger storage (16 bytes vs 4-8 bytes) and slightly slower indexing.
UUID Performance in Databases
Random UUIDs (v4) can cause index fragmentation in databases because new values are inserted at unpredictable locations in the B-tree. For high-insert-rate tables, consider UUID v7 (sequential with timestamp prefix) or ULID instead, which maintain rough time-ordering while retaining uniqueness guarantees.
Conclusion
UUIDs are a fundamental tool for building distributed systems, public APIs, and any application where globally unique identifiers matter. For most use cases, UUID v4 is the right choice — generate one whenever you need a unique ID that doesn’t need to carry any specific metadata.