Understanding UUID Versions
UUID (Universally Unique Identifier) comes in different versions, each designed for specific use cases. The version number doesn't mean "newer" or "better" - it indicates the generation method used to create the UUID.
Quick Answer: If you just need a unique ID, use UUID v4 (random).
That's what Guid.NewGuid(), UUID.randomUUID(), and uuid.uuid4() generate.
UUID Version 4 - Random (Most Common)
Generation: Pure random or cryptographically secure pseudo-random numbers
Use Case: General purpose unique identifiers (99% of use cases)
Pros: Simple, no privacy concerns, no collision risk, no external dependencies
Cons: Not sortable, not deterministic
// .NET / C#
Guid id = Guid.NewGuid();
// Output: f47ac10b-58cc-4372-a567-0e02b2c3d479
// JavaScript
const id = crypto.randomUUID();
// Output: 8a9c1b2e-3f4d-4567-8901-2a3b4c5d6e7f
Use v4 when: You need unique IDs for database records, session tokens, file names, etc.
UUID Version 5 - Name-Based (SHA-1)
Generation: SHA-1 hash of namespace + name
Use Case: Deterministic UUIDs (same input always produces same UUID)
Pros: Reproducible, no need to store mapping, consistent across systems
Cons: Not random, requires namespace
# Python
import uuid
namespace = uuid.NAMESPACE_DNS
name = "example.com"
id = uuid.uuid5(namespace, name)
# Always produces: cfbff0d1-9375-5685-968c-48ce8b15ae17
# Same input = same UUID every time
id2 = uuid.uuid5(namespace, "example.com")
assert id == id2 # True!
// Go
import "github.com/google/uuid"
namespace := uuid.NameSpaceDNS
id := uuid.NewSHA1(namespace, []byte("example.com"))
// Always produces: cfbff0d1-9375-5685-968c-48ce8b15ae17
Use v5 when: You need the same UUID for the same input (e.g., generating UUIDs for email addresses, URLs, or usernames)
UUID Version 1 - Time-Based
Generation: Current timestamp + MAC address + clock sequence
Use Case: Time-ordered unique identifiers
Pros: Sortable by creation time, guaranteed uniqueness per machine
Cons: Reveals MAC address (privacy issue), Reveals timestamp
// Java
import java.util.UUID;
import com.fasterxml.uuid.Generators;
UUID id = Generators.timeBasedGenerator().generate();
// Output: 550e8400-e29b-11d4-a716-446655440000
// └─timestamp─┘ └─MAC address─┘
Privacy Warning: v1 UUIDs can expose your computer's MAC address and creation time. Modern applications typically use v4 instead.
Use v1 when: You need time-ordered IDs AND privacy isn't a concern (consider UUIDv6/v7 instead)
UUID Version 3 - Name-Based (MD5)
Generation: MD5 hash of namespace + name
Use Case: Legacy deterministic UUIDs
Status: Deprecated - Use v5 instead (MD5 is cryptographically weak)
# Python (not recommended)
import uuid
id = uuid.uuid3(uuid.NAMESPACE_DNS, "example.com")
# Use uuid5() instead!
Don't use v3: MD5 has known vulnerabilities. Use v5 for name-based UUIDs.
Upcoming: UUID Version 6, 7, 8
Status: Draft specification (RFC in progress as of 2025)
v6: Time-ordered like v1, but sortable and more privacy-friendly
v7: Unix timestamp-based, sortable, no MAC address
v8: Custom/experimental formats
These newer versions are not yet widely supported in standard libraries. Stick with v4 or v5 for production use.
Comparison Table
| Version | Method | Use Case | Recommendation |
|---|---|---|---|
| v4 | Random | General unique IDs | Recommended |
| v5 | SHA-1 hash | Deterministic IDs | When needed |
| v1 | Timestamp + MAC | Time-ordered IDs | Privacy risk |
| v3 | MD5 hash | Legacy | Use v5 instead |
How to Identify UUID Version
The version is encoded in the UUID itself. Look at the 13th character (after removing hyphens):
f47ac10b-58cc-4372-a567-0e02b2c3d479
^
Version 4 (random)
cfbff0d1-9375-5685-968c-48ce8b15ae17
^
Version 5 (SHA-1 name-based)
550e8400-e29b-11d4-a716-446655440000
^
Version 1 (timestamp-based)
Decision Flowchart
Do you need a unique ID?
-
→ Just a random unique ID?
Use UUID v4 -
→ Must be the same for the same input?
Use UUID v5
(e.g., always same UUID for "user@example.com") -
→ Must be time-ordered?
Consider UUIDv7 (future) or alternatives
If privacy isn't critical: UUID v1