What are UUIDs?
UUID (Universally Unique Identifier) is a standardized identifier format designed to be globally unique across space and time. UUIDs are 128-bit values typically represented as 32 hexadecimal digits, displayed in five groups separated by hyphens: 123e4567-e89b-12d3-a456-426614174000
.
UUIDs are defined by the RFC 9562 standard (which obsoletes the previous RFC 4122) and are used across computing platforms to identify information without requiring centralized registration or coordination.
UUID Format
All UUIDs share a common format consisting of 36 characters (32 hexadecimal digits plus 4 hyphens) arranged in the pattern:
xxxxxxxx-xxxx-Mxxx-Nxxx-xxxxxxxxxxxx
Where:
x
is any hexadecimal digit (0-9, a-f)M
indicates the UUID version (1-7)N
indicates the UUID variant (typically 8, 9, A, or B for modern UUIDs)
Comparison of UUID Versions
Version | Name | Generation Method | Time-ordered | Use Cases |
---|---|---|---|---|
UUID v1 | Timestamp | Current timestamp + node ID (MAC) | Yes (partially) | Logging, distributed systems |
UUID v3 | Name-based (MD5) | MD5 hash of namespace + name | No | Consistent IDs for the same input |
UUID v4 | Random | Random or pseudo-random numbers | No | General purpose, most common |
UUID v5 | Name-based (SHA-1) | SHA-1 hash of namespace + name | No | Consistent IDs with stronger hash |
UUID v6 | Reordered Timestamp | Timestamp (ordered for sorting) | Yes | Database keys, time-sortable records |
UUID v7 | Unix Epoch Timestamp | Unix timestamp + random data | Yes | Modern sortable identifiers |
Nil UUID | Zero UUID | All zeros | N/A | Special value, uninitialized marker |
Advantages of UUIDs
- No Coordination Required: Generate IDs without central coordination
- Global Uniqueness: Extremely low collision probability
- Fixed Length: Consistent 36 character string representation
- Cross-Platform: Supported in virtually all programming languages
- Versatile: Different versions for different use cases
Non-Standard UUID Alternatives
ID Type | Description | Advantages | Disadvantages |
---|---|---|---|
GUID | Microsoft's implementation of UUID | Functionally equivalent to UUID | Some implementation differences in older systems |
ULID | Universally Unique Lexicographically Sortable Identifier | Lexicographically sortable, timestamp first, case-insensitive | Newer, less widespread adoption |
Snowflake ID | Twitter's distributed ID system | Time-sortable, compact (64-bit) | Requires central coordination |
CUID/CUID2 | Collision-resistant IDs | Short, suitable for client-side generation | Not an official standard |
Nano ID | Tiny, secure, URL-friendly unique string ID generator | Smaller than UUID, configurable alphabet | Not standardized |
Short UUID | Shorter encoding of standard UUIDs | More compact representation | Requires conversion to/from standard UUID |
Nil UUID | UUID with all bits set to zero | Special semantic meaning | Not unique (used as special value) |
Minecraft UUID | UUIDs with or without hyphens | Compatible with standard UUIDs | Formatting differences only |
Practical Applications
- Database Primary Keys: Especially in distributed or replicated databases
- Distributed Systems: Identify entities across multiple systems
- Web Applications: Session identifiers, tracking anonymous users
- Content Management: Document and media identifiers
- APIs: Request and transaction identifiers for tracing and debugging
- Internet of Things: Device identification without central registration
- Data Synchronization: Identifying records across multiple data stores
- Software Licensing: Unique product or license keys