dev cosmos/blog/guid-generator-guide

GUID vs UUID: The Complete Developer Guide to Unique Identifiers

Everything you need to know about GUIDs, UUID versions, formats, collision probability, and when to use each in your system.

GID

GUID Generator

v1 · v4 · v5 · Nil

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.

GID
Open in Dev Cosmos
GUID Generator →

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.

⚠️
Privacy Concern
v1 UUIDs embed the host's MAC address. If you generate them server-side this leaks internal network topology. Use a random node (as this tool does) or prefer v4/v7 in privacy-sensitive contexts.

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 GeneratedCollision Probability
1,000~0.000000000000000000001%
1 billion~0.00000000000000001%
10 trillion~0.0000001%

Output Formats

FormatExampleUse Case
Standard550e8400-e29b-41d4-a716-446655440000Default, most APIs
UPPERCASE550E8400-E29B-41D4-A716-446655440000SQL Server, legacy .NET
Braces{550e8400-e29b-41d4-a716-446655440000}.NET GUIDs, C++ COM interfaces
No hyphens550e8400e29b41d4a716446655440000Compact 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.

💡
Consider UUID v7 for Databases
UUID v7 (a newer draft standard) combines a millisecond timestamp prefix with random bits, giving you sortable UUIDs that don't fragment indexes. PostgreSQL extensions like pg_idkit support it natively.
More from the Blog