GUID and UUID are the same thing — Globally Unique Identifier and Universally Unique Identifier — just different naming conventions. Microsoft historically used "GUID" in COM/COM+ and .NET, while the broader industry standardized on "UUID" via RFC 4122. Under the hood they're both 128-bit identifiers formatted as xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx.
Anatomy of a UUID
A UUID has five groups separated by hyphens:
550e8400-e29b-41d4-a716-446655440000
|______| |___| |___| |___| |__________|
8 chars 4 4 4 12
time_low time ver+ var+ node
mid hi clock
The 4-bit version field (characters 13–13) encodes which UUID version was used to generate it. The 2-bit variant field signals the layout follows RFC 4122.
UUID Versions
v1 — Time-Based
Version 1 derives uniqueness from the current timestamp (measured in 100-nanosecond intervals since October 15, 1582) plus the generating machine's MAC address. The result is sortable by creation time, which is an advantage for database indexes.
v4 — Random (Most Common)
Version 4 uses 122 random bits from a cryptographically secure RNG. No coordination, no infrastructure, no state. It's the go-to choice for most applications:
// JavaScript
crypto.randomUUID() // → "550e8400-e29b-41d4-a716-446655440000"
// Python
import uuid; str(uuid.uuid4())
// C#
Guid.NewGuid().ToString()
v5 — Namespace + Name (Deterministic)
Version 5 is deterministic: the same namespace UUID + name string always produces the same UUID. It uses SHA-1 internally. This is useful when you need stable IDs from content:
- Converting a URL into a stable UUID for deduplication
- Generating user IDs from email addresses consistently across services
- Creating reproducible test data IDs
Nil UUID
All 128 bits set to zero: 00000000-0000-0000-0000-000000000000. Used as a sentinel "not set" value in APIs and databases, similar to null.
Collision Probability
For v4 (random), the probability of generating a duplicate when creating 1 billion UUIDs per second for 85 years is approximately 50%. In practice, the chance of collision in any realistic application is effectively zero.
| UUIDs Generated | Collision Probability |
|---|---|
| 1,000 | ~0.000000000000000000001% |
| 1 billion | ~0.00000000000000001% |
| 10 trillion | ~0.0000001% |
Output Formats
| Format | Example | Use Case |
|---|---|---|
| Standard | 550e8400-e29b-41d4-a716-446655440000 | Default, most APIs |
| UPPERCASE | 550E8400-E29B-41D4-A716-446655440000 | SQL Server, legacy .NET |
| Braces | {550e8400-e29b-41d4-a716-446655440000} | .NET GUIDs, C++ COM interfaces |
| No hyphens | 550e8400e29b41d4a716446655440000 | Compact storage, URL path segments |
UUIDs as Database Primary Keys
Using UUIDs as primary keys has trade-offs. The main advantage is that keys can be generated on the client without a database round-trip, enabling offline-first architectures. The main disadvantage is that random v4 UUIDs cause B-tree index fragmentation, degrading insert performance at scale.
pg_idkit support it natively.