Every database record, API request, and distributed system component needs a unique identifier. Auto-incrementing integers work for single-server setups, but they break down in distributed environments where multiple nodes need to generate IDs independently without coordination. UUIDs (Universally Unique Identifiers) solve this problem elegantly—and they're used everywhere from database primary keys to Bluetooth device identification.
This guide explains what UUIDs are, compares all major versions, and helps you choose the right one for your application.
A UUID is a 128-bit identifier represented as a 36-character string in the format:
550e8400-e29b-41d4-a716-446655440000
xxxxxxxx-xxxx-Mxxx-Nxxx-xxxxxxxxxxxx
The string format uses hexadecimal digits (0-9, a-f) separated by hyphens. The two significant positions are:
8, 9, a, or b for RFC 4122 UUIDs)UUIDs are also known as GUIDs (Globally Unique Identifiers), a term primarily used in Microsoft ecosystems. The terms are functionally equivalent.
| Version | Source of Uniqueness | Time-Sortable | Privacy | Status |
|---|---|---|---|---|
| UUIDv1 | MAC address + timestamp | Yes | Low | RFC 4122 |
| UUIDv3 | Namespace + name (MD5) | No | High | RFC 4122 |
| UUIDv4 | Random | No | High | RFC 4122 |
| UUIDv5 | Namespace + name (SHA-1) | No | High | RFC 4122 |
| UUIDv6 | Reordered v1 timestamp | Yes | Medium | RFC 9562 (2024) |
| UUIDv7 | Unix timestamp ms + random | Yes | High | RFC 9562 (2024) |
| UUIDv8 | Custom | Varies | Varies | RFC 9562 (2024) |
UUIDv1 combines the generating machine's MAC address with a 60-bit timestamp (100-nanosecond intervals since October 15, 1582) and a clock sequence to handle rapid generation.
Example: 6ba7b810-9dad-11d1-80b4-00c04fd430c8
version: 1 timestamp MAC address
Advantages: Time-sortable, globally unique due to MAC address, no coordination needed.
Disadvantages: Exposes the generating machine's MAC address (privacy concern), same machine at same time can produce similar UUIDs, clock regression can cause collisions.
UUIDv3 generates a deterministic UUID by hashing a namespace UUID and a name together using MD5. The same namespace and name always produce the same UUID.
uuidv3("6ba7b810-9dad-11d1-80b4-00c04fd430c8", "example.com")
→ 90b472e3-4b35-3fb9-b8de-53e4b47f4e3f
Use case: Generating consistent identifiers for the same named entity across systems. For example, generating the same UUID for a user based on their email address regardless of which server generates it.
Warning: Uses MD5, which is cryptographically broken. If you need name-based UUIDs with cryptographic guarantees, use UUIDv5 instead.
UUIDv4 generates entirely random UUIDs. 122 of the 128 bits are random; the remaining 6 bits are fixed for version and variant identification.
Example: 550e8400-e29b-41d4-a716-446655440000
version: 4 variant random (122 bits)
Advantages: Simple to implement, no privacy concerns, no coordination needed, excellent uniqueness guarantees.
Disadvantages: Not time-sortable (terrible for database indexes), randomly distributed UUIDs cause index fragmentation in B-tree databases.
Identical to UUIDv3 but uses SHA-1 instead of MD5. Provides stronger cryptographic guarantees while maintaining the same deterministic behavior.
Predefined namespaces:
DNS — 6ba7b810-9dad-11d1-80b4-00c04fd430c8URL — 6ba7b811-9dad-11d1-80b4-00c04fd430c8OID — 6ba7b812-9dad-11d1-80b4-00c04fd430c8X.500 — 6ba7b814-9dad-11d1-80b4-00c04fd430c8Published in RFC 9562 (2024), UUIDv7 is rapidly becoming the recommended default. It combines a Unix timestamp in milliseconds (48 bits) with random data (74 bits), creating IDs that are both unique and time-sortable.
Example: 0190a6e3-7b1c-7cd3-a3f2-4e5d6c7b8a9f
timestamp (ms) version: 7 random
Advantages:
Use case: Database primary keys in distributed systems, event IDs, log correlation, any scenario where you need both uniqueness and sortability.
UUIDv6 reorders UUIDv1's timestamp fields to put the most significant time bits first, making it sortable while preserving the MAC address structure. It's essentially a sortable UUIDv1.
UUIDv8 is a custom format — RFC 9562 reserves it for vendor-specific or application-specific UUID schemes. You define your own layout within the 128-bit space.
The birthday paradox tells us the probability of at least one collision among n generated UUIDs. For random UUIDs (v4) with 122 random bits:
| UUIDs Generated | Collision Probability |
|---|---|
| 1 billion | ~0.00000000006 |
| 1 trillion | ~0.00000006 |
| 2.71 quintillion | ~50% |
To have a 50% chance of a single UUIDv4 collision, you'd need to generate approximately 2.71 × 10¹⁸ UUIDs. At a rate of one billion per second, that would take about 85 years. For virtually all real-world applications, UUID collisions are not a practical concern.
import uuid
# UUIDv4 (random)
id_v4 = uuid.uuid4()
# UUID('550e8400-e29b-41d4-a716-446655440000')
# UUIDv5 (name-based, SHA-1)
id_v5 = uuid.uuid5(uuid.NAMESPACE_DNS, "example.com")
# UUIDv7 (Python 3.13+)
id_v7 = uuid.uuid7()
# Generate multiple
ids = [str(uuid.uuid4()) for _ in range(10)]
// Node.js (v19+)
import { randomUUID } from 'crypto';
const id = randomUUID(); // UUIDv4
// UUIDv7 (Node.js 22+)
import { uuidv7 } from 'crypto';
const id7 = uuidv7();
// Browser
const id = crypto.randomUUID(); // UUIDv4
import java.util.UUID;
// UUIDv4
UUID id = UUID.randomUUID();
// UUIDv3
UUID v3 = UUID.nameUUIDFromBytes(
"example.com".getBytes(StandardCharsets.UTF_8)
);
// String output
String str = id.toString();
-- Generate UUIDv4
SELECT gen_random_uuid();
-- UUIDv7 (PostgreSQL 17+)
SELECT gen_random_uuid();
-- Column type
CREATE TABLE users (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
name TEXT NOT NULL
);
| Feature | UUID | Auto-Increment | ULID | Snowflake ID |
|---|---|---|---|---|
| Distributed | ✅ Yes | ❌ No | ✅ Yes | Needs coordination |
| Time-Sortable | v1, v6, v7 | ✅ Yes | ✅ Yes | ✅ Yes |
| Size | 128 bits | 32-64 bits | 128 bits | 64 bits |
| Privacy | v4, v5, v7 | ✅ Yes | ✅ Yes | ✅ Yes |
| Standard | RFC 4122/9562 | N/A | Community |
UUIDs have evolved significantly since their introduction in RFC 4122. While UUIDv4 remains the most widely used, UUIDv7 (standardized in RFC 9562) represents the future—combining the simplicity of random UUIDs with the practical benefits of time-sortability. For database primary keys, distributed systems, and any application needing globally unique identifiers without coordination, UUIDs remain the gold standard.
Choose your UUID version based on your requirements: v7 for database keys, v4 for general-purpose unique IDs, v5 for deterministic naming, and v3/v6 for specific legacy use cases.
Create UUIDs in v4 and v7 formats with our free online UUID generator. Generate single or bulk UUIDs directly in your browser.
Try Our Free UUID Generator →