UUID Generator: Understanding UUIDs and When to Use Them

Published: April 10, 2026 · 10 min read · Development

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.

What Is a UUID?

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:

UUIDs are also known as GUIDs (Globally Unique Identifiers), a term primarily used in Microsoft ecosystems. The terms are functionally equivalent.

UUID Versions Compared

VersionSource of UniquenessTime-SortablePrivacyStatus
UUIDv1MAC address + timestampYesLowRFC 4122
UUIDv3Namespace + name (MD5)NoHighRFC 4122
UUIDv4RandomNoHighRFC 4122
UUIDv5Namespace + name (SHA-1)NoHighRFC 4122
UUIDv6Reordered v1 timestampYesMediumRFC 9562 (2024)
UUIDv7Unix timestamp ms + randomYesHighRFC 9562 (2024)
UUIDv8CustomVariesVariesRFC 9562 (2024)

UUIDv1: Time-Based (MAC + Timestamp)

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: Name-Based (MD5)

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: Random (The Most Popular)

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.

⚠️ Database Performance Tip: Random UUIDv4 values as primary keys in PostgreSQL, MySQL, or SQL Server cause significant index fragmentation because new rows are inserted at random positions in the B-tree index. For database primary keys, consider UUIDv7 or ULID instead.

UUIDv5: Name-Based (SHA-1)

Identical to UUIDv3 but uses SHA-1 instead of MD5. Provides stronger cryptographic guarantees while maintaining the same deterministic behavior.

Predefined namespaces:

UUIDv7: The Modern Standard (RFC 9562)

Published 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 and UUIDv8: The Extensible Future

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.

Collision Probability: Should You Worry?

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 GeneratedCollision 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.

Programming Implementations

Python

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)]

JavaScript / Node.js

// 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

Java

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();

SQL (PostgreSQL)

-- 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
);

UUIDs vs. Alternatives

FeatureUUIDAuto-IncrementULIDSnowflake ID
Distributed✅ Yes❌ No✅ YesNeeds coordination
Time-Sortablev1, v6, v7✅ Yes✅ Yes✅ Yes
Size128 bits32-64 bits128 bits64 bits
Privacyv4, v5, v7✅ Yes✅ Yes✅ Yes
StandardRFC 4122/9562N/ACommunityTwitter

Best Practices

Conclusion

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.

Generate UUIDs Instantly

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 →