What is UUID? Difference between UUID v1, v3, v4, and v5
Generate secure random UUID v4 identifiers instantly and privately in your browser with one click.
Open UUID / GUID Generator →In modern database architecture and distributed systems, uniquely identifying resources is critical. While auto-incrementing integer IDs (like 1, 2, 3) work for single databases, they fail in distributed microservices. This is where UUIDs (Universally Unique Identifiers) come in. In this guide, we will cover what a UUID is, how it works, and the key differences between versions 1, 3, 4, and 5.
What is a UUID?
A UUID is a 128-bit label represented as a 36-character hexadecimal string divided into five groups separated by hyphens:
123e4567-e89b-12d3-a456-426614174000
│ │ │ │ └──────────── Node ID (48 bits)
│ │ │ └───────────────── Variant & Clock Sequence (16 bits)
│ │ └────────────────────── Version Number (4 bits)
│ └─────────────────────────── Timestamp High (16 bits)
└──────────────────────────────────── Timestamp Low & Mid (32 bits)
Because UUIDs are 128-bit, the total number of unique identifiers is \(2^{128}\), which is approximately \(3.4 \times 10^{38}\). The chance of a single duplicate collision is virtually zero.
Understanding the UUID Versions
The RFC 4122 specification defines several algorithms to generate UUIDs. Each version serves a different purpose:
UUID Version 1 (Time-Based)
UUID v1 is generated by combining the host computer's MAC address and the current timestamp. Because it contains the MAC address, v1 UUIDs can be traced back to the computer that created them, raising privacy concerns. However, since they are time-ordered, they are useful for database indexing.
UUID Version 3 (Namespace + MD5 Hash)
UUID v3 is name-based. It generates an identifier by hashing a namespace identifier (like a domain name) and a specific string input using the MD5 algorithm. UUID v3 is deterministic — the same namespace and string will always yield the same UUID.
UUID Version 4 (Randomly Generated)
UUID v4 is generated using cryptographically secure random numbers. Of the 128 bits, 122 bits are completely random, and 6 bits are reserved for variant and version info. V4 is the most popular choice for modern databases (like PostgreSQL primary keys) and APIs because it is entirely random, secure, and preserves privacy.
UUID Version 5 (Namespace + SHA-1 Hash)
UUID v5 is identical to v3, but it uses the **SHA-1** hashing algorithm instead of MD5. Since SHA-1 is more secure than MD5, v5 is preferred over v3 for name-based deterministic UUID generation.
Comparison Table: UUID Versions
| Version | Generation Method | Uniqueness Type | Privacy / Safety | Best Use Case |
|---|---|---|---|---|
| v1 | Time & MAC Address | Time-dependent | ⚠️ Low (exposes MAC) | Time-sorted logs |
| v3 | MD5 Hash & Name | Deterministic | ✅ Safe | Legacy name mapping |
| v4 | Secure Randomness | Unpredictable | ✅ Highly Safe | Database Primary Keys |
| v5 | SHA-1 Hash & Name | Deterministic | ✅ Safe | Deterministic ID mapping |
Which UUID Version Should You Use?
- Choose **UUID v4** for 95% of standard applications (API keys, session IDs, database primary keys). It is secure, random, and private.
- Choose **UUID v5** if you must generate the exact same ID for the same text input consistently (e.g., mapping URLs to unique IDs).
- Avoid **UUID v1** unless you explicitly need time-sorted identifiers and do not mind exposing server hardware details.
Generate UUIDs Instantly Online
To generate single or bulk RFC 4122 v4 UUID identifiers, use our offline UUID Generator. It runs locally in your browser with zero data leaving your device.