โ† Back to Blog ZeroDataUpload Home

How to Generate UUIDs: v1, v4, and v7 Explained

Milan Salvi Jan 11, 2026 7 min read Guides
How to Generate UUIDs: v1, v4, and v7 Explained

Table of Contents

  1. What Is a UUID?
  2. The UUID Format
  3. UUID v1: Time-Based
  4. UUID v4: Random
  5. UUID v7: Time-Ordered Random
  6. Comparison: Which Version Should You Use?
  7. Generating UUIDs in Practice
  8. Conclusion

If you have ever built an application that needs unique identifiers for records, users, transactions, or any other entities, you have likely encountered UUIDs. These 128-bit identifiers are designed to be globally unique without requiring a central authority. But there are multiple versions of UUIDs, each with different characteristics. This guide explains the three most commonly used versions and helps you choose the right one for your project.

1. What Is a UUID?

UUID stands for Universally Unique Identifier. It is a 128-bit value designed to be unique across all systems, all time, and all space, without needing a central registry or coordination between the systems generating them. UUIDs are also known as GUIDs (Globally Unique Identifiers), a term popularized by Microsoft.

The UUID specification is defined in RFC 9562 (which replaced the original RFC 4122 in 2024). It defines several versions of UUIDs, each using a different method to generate unique values. The probability of generating two identical UUIDs is so astronomically low that for all practical purposes, every UUID ever generated is unique.

UUIDs solve a fundamental problem in distributed systems: how do you generate unique identifiers without a single point of coordination? In a monolithic application, you might use an auto-incrementing integer from your database. But in distributed systems with multiple servers, microservices, or offline clients, auto-incrementing IDs can collide. UUIDs provide uniqueness guarantees without any coordination.

2. The UUID Format

A UUID is typically displayed as a string of 32 hexadecimal digits grouped in a 8-4-4-4-12 pattern, separated by hyphens:

550e8400-e29b-41d4-a716-446655440000
โ”‚        โ”‚    โ”‚    โ”‚    โ”‚
โ”‚        โ”‚    โ”‚    โ”‚    โ””โ”€ Node (48 bits)
โ”‚        โ”‚    โ”‚    โ””โ”€ Clock sequence (16 bits)
โ”‚        โ”‚    โ””โ”€ Version (4 bits) + time_hi (12 bits)
โ”‚        โ””โ”€ time_mid (16 bits)
โ””โ”€ time_low (32 bits)

The version number is encoded in the third group. For example, 41d4 starts with 4, indicating this is a version 4 UUID. The variant is encoded in the fourth group: values starting with 8, 9, a, or b indicate the standard RFC variant.

Despite containing hyphens in the standard representation, UUIDs are 128-bit (16-byte) values at their core. The string representation is just for human readability. When stored in databases, UUIDs can be stored as 16-byte binary values for efficiency.

3. UUID v1: Time-Based

UUID v1 generates identifiers based on the current time and the MAC address of the generating machine. The timestamp provides uniqueness over time, and the MAC address provides uniqueness across machines.

Structure:

Advantages:

Disadvantages:

// Example UUID v1
// 6ba7b810-9dad-11d1-80b4-00c04fd430c8
//                 ^
//                 1 = version 1

4. UUID v4: Random

UUID v4 is the most widely used version. It generates identifiers using random (or pseudo-random) numbers. Of the 128 bits, 122 are randomly generated, with the remaining 6 bits used for the version (4 bits) and variant (2 bits) identifiers.

Structure:

Advantages:

Disadvantages:

// Generating UUID v4 in JavaScript
const uuid = crypto.randomUUID();
// Example: "f47ac10b-58cc-4372-a567-0e02b2c3d479"
//                       ^
//                       4 = version 4

The collision probability of UUID v4 is extraordinarily low. You would need to generate approximately 2.71 quintillion (2.71 x 10^18) UUIDs to have a 50% chance of a single collision. To put that in perspective, if you generated one billion UUIDs per second, it would take approximately 86 years to reach that threshold.

5. UUID v7: Time-Ordered Random

UUID v7 is the newest version, introduced in RFC 9562 (2024). It combines the best features of v1 and v4: time-based ordering with random uniqueness, and without the privacy concerns of exposing MAC addresses.

Structure:

Advantages:

Disadvantages:

Recommendation

For new projects in 2026, UUID v7 is the best default choice. It provides the sortability benefits of time-based UUIDs, the privacy benefits of random UUIDs, and excellent database performance. Use UUID v4 when you need no timestamp information in the ID, or when maximum compatibility with older systems is required.

6. Comparison: Which Version Should You Use?

Here is a quick decision guide:

7. Generating UUIDs in Practice

Here is how to generate UUIDs in common programming languages:

// JavaScript (v4 - native)
crypto.randomUUID();

// Python (v4)
import uuid
str(uuid.uuid4())

// Java (v4)
UUID.randomUUID().toString();

// Go (v4, using google/uuid)
uuid.New().String()

// PHP (v4)
Ramsey\Uuid\Uuid::uuid4()->toString();

For generating UUIDs quickly without writing code, or when you need bulk generation (up to 10,000 at once), tools like UUID Generator by ZeroDataUpload support v1, v4, and v7 generation entirely in your browser. All UUIDs are generated locally using cryptographic randomness, so they are suitable for production use.

8. Conclusion

UUIDs are a foundational concept in software engineering. Understanding the differences between versions helps you make informed decisions about your application's identifier strategy. UUID v4 remains the most widely used and compatible option, while UUID v7 represents the future of UUID generation with its superior database performance and sortability.

Whichever version you choose, the core guarantee remains the same: every UUID you generate will be unique, without requiring any central coordination or authority. That is a powerful property for building distributed, scalable systems.

Related Articles

Milan Salvi

Milan Salvi

Founder, Leena Software Solutions

Milan is the founder of ZeroDataUpload and Leena Software Solutions, building privacy-first browser tools that process everything client-side. View all articles ยท About the author.

Published: January 11, 2026