What is UUID Version 5?
UUID version 5 is a name-based, deterministic UUID generated by hashing a namespace identifier together with a name using the SHA-1 algorithm. The key property of UUID v5 is that given the same namespace and name, you will always get the exact same UUID.
This makes UUID v5 fundamentally different from UUID v4 (random) or UUID v1 (timestamp-based). Instead of generating a new unique identifier each time, UUID v5 creates a consistent identifier that can be reproduced anywhere, anytime, as long as you know the inputs.
UUID v5 is defined in RFC 4122 Section 4.3 and is preferred over UUID v3 (which uses MD5) because SHA-1 is a stronger hash function.
Key Property: Deterministic
The same inputs always produce the same output:
Namespace: DNS (6ba7b810-9dad-11d1-80b4-00c04fd430c8)
Name: example.com
UUID v5: cfbff0d1-9375-5685-968c-48ce8b15ae17
↑ This will be the same on any system, in any programming language
How UUID v5 Generation Works
UUID v5 is generated through the following process:
- 1 Concatenate the namespace UUID (16 bytes) with the name (UTF-8 encoded)
- 2 Compute SHA-1 hash of the concatenated data (produces 20 bytes)
- 3 Take the first 16 bytes of the hash
- 4 Set version bits to "0101" (5) in the 7th byte
- 5 Set variant bits to "10" in the 9th byte
UUID v5 = SHA1(namespace_uuid + name)[0:16]
with version=5 and variant=RFC4122
Standard Namespaces
RFC 4122 defines four standard namespace UUIDs for common use cases:
| Namespace | UUID | Use For |
|---|---|---|
| DNS | 6ba7b810-9dad-11d1-80b4-00c04fd430c8 | Domain names (e.g., "example.com") |
| URL | 6ba7b811-9dad-11d1-80b4-00c04fd430c8 | URLs (e.g., "https://example.com/page") |
| OID | 6ba7b812-9dad-11d1-80b4-00c04fd430c8 | ISO Object IDs (e.g., "1.3.6.1") |
| X.500 DN | 6ba7b814-9dad-11d1-80b4-00c04fd430c8 | X.500 Distinguished Names |
Custom Namespaces
You can create your own namespace UUID for application-specific use cases. A common approach is to generate a UUID v4 once and use it as your application's namespace. For example, you might create a "users" namespace for generating consistent user IDs from email addresses.
UUID v5 vs UUID v3
Both UUID v3 and v5 are name-based and deterministic. The only difference is the hash algorithm:
UUID v3 (MD5)
- • Uses MD5 hash algorithm
- • MD5 has known vulnerabilities
- • 128-bit hash truncated to 122 bits
- • Not recommended for new applications
- • Keep for backward compatibility only
UUID v5 (SHA-1) ✓
- • Uses SHA-1 hash algorithm
- • Stronger than MD5
- • 160-bit hash truncated to 122 bits
- • Recommended for name-based UUIDs
- • Better collision resistance
Note: While SHA-1 itself has theoretical weaknesses for cryptographic signatures, it remains perfectly adequate for UUID generation where collision resistance (not pre-image resistance) is the primary concern.
When to Use UUID v5
Ideal Use Cases
- • Consistent IDs from names: Generate same ID for "[email protected]" everywhere
- • URL-based identifiers: Create UUIDs for web resources
- • Content addressing: Derive ID from content without storing mapping
- • Idempotent operations: Same input = same output = safe retries
- • Cross-system references: Same entity gets same UUID in different systems
- • Migration scenarios: Predictably convert old IDs to UUIDs
Generate UUID v5 in Code
import uuid
# Using standard DNS namespace
dns_namespace = uuid.NAMESPACE_DNS
uuid_v5 = uuid.uuid5(dns_namespace, "example.com")
print(uuid_v5) # cfbff0d1-9375-5685-968c-48ce8b15ae17
# Using URL namespace
url_namespace = uuid.NAMESPACE_URL
uuid_v5 = uuid.uuid5(url_namespace, "https://example.com/page")
# Custom namespace (your own application)
my_namespace = uuid.UUID("12345678-1234-5678-1234-567812345678")
uuid_v5 = uuid.uuid5(my_namespace, "[email protected]")
import { v5 as uuidv5 } from 'uuid';
// Standard namespaces
const DNS_NAMESPACE = '6ba7b810-9dad-11d1-80b4-00c04fd430c8';
const URL_NAMESPACE = '6ba7b811-9dad-11d1-80b4-00c04fd430c8';
// Generate UUID v5
const id = uuidv5('example.com', DNS_NAMESPACE);
console.log(id); // cfbff0d1-9375-5685-968c-48ce8b15ae17
// Same inputs always produce same output
console.log(uuidv5('example.com', DNS_NAMESPACE) === id); // true
import java.util.UUID;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
// Java doesn't have built-in v5, but you can implement it:
public static UUID generateUUIDv5(UUID namespace, String name) {
MessageDigest md = MessageDigest.getInstance("SHA-1");
md.update(toBytes(namespace));
md.update(name.getBytes(StandardCharsets.UTF_8));
byte[] hash = md.digest();
hash[6] = (byte) ((hash[6] & 0x0f) | 0x50); // version 5
hash[8] = (byte) ((hash[8] & 0x3f) | 0x80); // variant
return fromBytes(hash);
}
Related UUID Tools
Frequently Asked Questions
Will UUID v5 give the same result in different languages?
Yes! That's the whole point. Given the same namespace UUID and name string (UTF-8 encoded), UUID v5 will produce identical results in Python, JavaScript, Java, Go, or any correctly implemented library. This is what makes it useful for cross-system identifier generation.
Can someone reverse a UUID v5 to get the original name?
No, SHA-1 is a one-way hash function. You cannot reverse the UUID to discover the original name. However, if someone knows the namespace and can guess possible names, they could verify guesses by generating UUIDs. So don't rely on UUID v5 for security—it's for consistency, not secrecy.
Should I use UUID v3 or v5?
Use UUID v5. It uses SHA-1 which is stronger than MD5 (used in v3). The only reason to use v3 is backward compatibility with existing systems that already use v3. For new projects, always choose v5.
What namespace should I use?
Use the standard namespaces when they fit: DNS for domain names, URL for full URLs, OID for ISO object identifiers. For application-specific uses (like user emails or internal IDs), create your own namespace by generating a UUID v4 once and reusing it consistently.