What is a UUID
A UUID (Universally Unique Identifier) is a 128-bit number used to uniquely identify information across systems. The UUID format ensures that even when generated by different devices globally, there's nearly zero chance of duplication. Developers use UUIDs for database keys, API requests, and device tracking.
UUID Format Structure
The standard UUID format looks like this: 8-4-4-4-12 hexadecimal digits separated by hyphens. Here's the breakdown:
- First 8 digits: Time-based identifier (version 1)
- Next 4 digits: Version type
- Next 4 digits: Clock sequence
- Last 12 digits: Random or namespace-based data
This format creates 32 characters in total, typically displayed as 36 characters with hyphens.
How UUIDs Are Generated
UUIDs use different generation methods (versions):
- Version 1: Combines timestamp and device MAC address
- Version 4: Uses random numbers
- Version 5: Hash-based using a namespace and name
Each version follows the same UUID format but generates values differently. Version 4 is most commonly used today for its simplicity and security.
When to Use UUIDs
Use UUIDs when you need:
- Unique identifiers across distributed systems
- Security against predictable IDs
- Scalable database keys
- Tracking user sessions or devices
Avoid UUIDs for sequential numbering where simplicity is more important than uniqueness. The UUID format works best in cloud environments and large networks where collision risks are highest.
UUID Format Examples
Here are common UUID examples:
1. Version 1: 550e8400-e29b-41d4-a716-446655440000
2. Version 4: 6ba7b810-9dad-11d1-80b4-00c04fd430c8
3. Version 5: f47ac10b-58cc-5aef-970f-3b0b59e9e7d1
The UUID format remains consistent across versions, with the 13th-16th digits indicating the version type. This standardization makes UUIDs compatible with all major programming languages and databases.