A UUID (Universally Unique Identifier) is a 128-bit value used to uniquely identify information in computer systems — without a central authority assigning them. Properly generated UUIDs are statistically guaranteed to be unique across all space and time, making them the backbone of distributed systems, database primary keys, REST APIs, and session management. If you have ever seen a string like 550e8400-e29b-41d4-a716-446655440000, you have seen a UUID.
This guide covers everything developers need to know: the five major UUID versions (v1 through v7), how to read the structure, the collision probability math, UUID vs auto-increment in databases, GUID vs UUID naming, and the right version for every use case — with a free online UUID generator at the end.
Generate UUIDs Instantly — Free
Create single or bulk UUIDs (v1, v4, v7) in your browser. No server calls, no signup. Copy, download, or use directly in your code.
What Is a UUID? Structure and Format Explained
A UUID is a 128-bit identifier displayed as five groups of hexadecimal digits separated by hyphens, in the pattern 8-4-4-4-12 (32 hex chars + 4 hyphens = 36 characters total):
xxxxxxxx-xxxx-Mxxx-Nxxx-xxxxxxxxxxxx
│ │ │ │ │
│ │ │ │ └─ 12 hex digits (node / random)
│ │ │ └────── 4 hex digits (variant + random)
│ │ └─────────── 4 hex digits (version M + random)
│ └──────────────── 4 hex digits (time mid / random)
└───────────────────────── 8 hex digits (time low / random)
The two special nibbles
- Version nibble (M): The first digit of the third group. Values: 1, 2, 3, 4, 5, 6, 7 — tells you which UUID version it is.
- Variant nibble (N): The first digit of the fourth group. For RFC 4122 UUIDs, this is always 8, 9, a, or b (binary 10xx).
Example breakdown
550e8400-e29b-41d4-a716-446655440000
↑ ↑
version=4 variant=a (RFC 4122)
The nil UUID
The nil UUID is a special UUID with all 128 bits set to zero: 00000000-0000-0000-0000-000000000000. It is used as a sentinel or placeholder value — similar to NULL in SQL. Some systems use it to indicate "no UUID assigned yet" or as a default value in nullable UUID fields.
UUID v1 vs v4 vs v5 vs v7 — Full Comparison
There are five standardised UUID versions. Each version encodes different information into the 128 bits. Here is the complete comparison:
| Version | Algorithm | Sortable? | Private? | Best Use Case |
|---|---|---|---|---|
| v1 | MAC address + timestamp (100-ns precision) | Partially (time-ordered) | No — leaks MAC & time | Distributed event logging (legacy) |
| v3 | MD5 hash of namespace + name | No | Yes | Deterministic IDs from names (legacy) |
| v4 | 122 bits of cryptographic random | No | Yes | General purpose — most common choice |
| v5 | SHA-1 hash of namespace + name | No | Yes | Deterministic IDs (prefer v5 over v3) |
| v7 | Unix timestamp (ms) + random bits | Yes (monotonic) | Yes | Database PKs — sortable + index-friendly |
UUID v1 — Time + MAC
UUID v1 encodes a 60-bit timestamp (in 100-nanosecond intervals since Oct 15, 1582) and the MAC address of the generating machine. While technically sortable by time, v1 exposes the machine's MAC address — a privacy concern. It also creates "hot spots" in B-tree indexes because newly generated UUIDs cluster at one end. Avoid in new projects.
UUID v4 — Pure Random
UUID v4 uses 122 random bits (the remaining 6 bits encode version and variant). It is the most widely used UUID version. It requires no coordination between systems, is completely private, and is supported by every UUID library in every language. The only downside: it is not sortable, which can cause B-tree index fragmentation in databases.
UUID v5 — Namespaced SHA-1
UUID v5 deterministically generates a UUID from a namespace UUID + a name string using SHA-1. Given the same inputs, you always get the same UUID. Use this when you need a stable identifier for the same real-world entity (e.g., always generate the same UUID for user email "alice@example.com"). Predefined namespaces: DNS, URL, OID, X.500.
UUID v7 — The Modern Choice for Databases
UUID v7 (RFC 9562, published 2024) encodes a Unix timestamp in milliseconds in the first 48 bits, followed by random bits. Because the timestamp is in the high bits, v7 UUIDs sort chronologically — solving the index fragmentation problem of v4. UUID v7 is now the recommended choice for database primary keys, replacing both v4 (no ordering) and v1 (privacy issues).
UUID Collision Probability — The Math
One of the most common questions about UUIDs: "Can two UUIDs ever be the same?" Technically yes, but the probability is astronomically small.
UUID v4 collision math
UUID v4 uses 122 random bits, giving 2122 ≈ 5.3 × 1036 possible values. Using the birthday problem approximation:
P(collision) ≈ n² / (2 × 2^122)
To get a 50% chance of collision with n UUIDs generated:
n ≈ 2.71 quintillion (2.71 × 10^18)
For practical context: if you generated 1 billion UUIDs per second, it would take approximately 85 years to reach a 50% chance of even a single collision. In practice, UUID collisions are not a real engineering concern when using a cryptographically secure random number generator.
The CSPRNG requirement
The collision guarantee only holds when using a Cryptographically Secure Pseudo-Random Number Generator (CSPRNG). JavaScript's crypto.randomUUID(), Python's uuid.uuid4(), and Java's UUID.randomUUID() all use CSPRNGs. Avoid Math.random()-based UUID generators — they are not cryptographically secure and have higher collision rates.
If your system generates tens of billions of UUIDs in a short period, consider switching to UUID v7 with monotonic random bits, which provides additional collision resistance through a sequence counter within the same millisecond.
UUID in Databases: MySQL, PostgreSQL — UUID vs Auto-Increment
Using UUID as a database primary key is a hotly debated architectural decision. Here is an honest analysis for MySQL and PostgreSQL.
UUID vs Auto-Increment: The Trade-offs
| Factor | UUID (v4) | UUID (v7) | Auto-Increment INT |
|---|---|---|---|
| Uniqueness scope | Global | Global | Per-table only |
| Index fragmentation | High (random inserts) | Low (monotonic) | None (sequential) |
| Insert performance | ~20–40% slower than INT | Similar to INT | Fastest |
| Storage | 16 bytes (binary) / 36 bytes (text) | 16 bytes | 4 bytes (INT) / 8 bytes (BIGINT) |
| Merge / replication | No conflicts | No conflicts | Conflicts without coordination |
| Security | Doesn't expose record count | Doesn't expose record count | Exposes record count in URL |
| Offline generation | Yes — no DB roundtrip needed | Yes | No — requires DB |
MySQL recommendations
In MySQL (InnoDB), the primary key is the clustered index. Random UUID v4 as a PK causes severe index fragmentation because new rows are inserted at random positions in the B-tree rather than at the end. For large tables (10M+ rows), this degrades insert performance significantly. Use UUID v7 or the UUID_TO_BIN(uuid, 1) function which swaps the time components for better ordering. Store as BINARY(16), not VARCHAR(36) — saves 55% storage.
PostgreSQL recommendations
PostgreSQL has native UUID type (16 bytes). Use gen_random_uuid() for v4 (built-in since PostgreSQL 13) or the pg_uuidv7 extension for v7. PostgreSQL also supports UUIDv7 natively in PostgreSQL 17+. For high-throughput tables, prefer UUID v7 or ULID over UUID v4.
Rule of thumb
- Single-server app, < 10M rows: Auto-increment BIGINT is fine and simpler
- Distributed system / microservices: UUID v7 (best balance of all factors)
- Exposing IDs in URLs/APIs: UUID v4 (opaque) or UUID v7 (sortable)
- Need deterministic IDs: UUID v5
GUID vs UUID — Are They the Same Thing?
Short answer: yes, GUID and UUID are essentially the same thing. Here is the distinction:
| Term | Stands For | Origin | Format |
|---|---|---|---|
| UUID | Universally Unique Identifier | Open Group / RFC 4122 | xxxxxxxx-xxxx-Mxxx-Nxxx-xxxxxxxxxxxx |
| GUID | Globally Unique Identifier | Microsoft (COM/ActiveX) | {XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX} |
Microsoft's GUID is a variant of UUID. The key differences are cosmetic: GUIDs are often displayed in uppercase with curly braces (e.g., {550E8400-E29B-41D4-A716-446655440000}). In .NET, System.Guid.NewGuid() generates a version 4 UUID under the hood. When interoperating between Microsoft systems and non-Microsoft systems, strip the braces and lowercase the hex to convert a GUID to a standard UUID.
GUID in SQL Server
SQL Server uses the UNIQUEIDENTIFIER data type for GUIDs. NEWID() generates a random GUID (UUID v4). NEWSEQUENTIALID() generates sequential GUIDs optimised for clustered index performance — the SQL Server equivalent of UUID v7. Always prefer NEWSEQUENTIALID() for clustered index primary keys in SQL Server.
UUID Regex Pattern and Validation
Validating a UUID in your application is straightforward with a regular expression:
Standard UUID regex (case-insensitive)
/^[0-9a-f]{8}-[0-9a-f]{4}-[1-7][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i
This pattern validates:
- The 8-4-4-4-12 structure with hyphens
- Version digit: 1–7 (valid UUID versions)
- Variant bits: 8, 9, a, b (RFC 4122 variant)
Version-specific validation
// UUID v4 only
/^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i
// UUID v7 only
/^[0-9a-f]{8}-[0-9a-f]{4}-7[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i
Generating UUIDs in code
// JavaScript (browser + Node 15+)
crypto.randomUUID() // UUID v4, CSPRNG-backed
// Python
import uuid
uuid.uuid4() # v4 random
uuid.uuid5(uuid.NAMESPACE_DNS, 'example.com') # v5 deterministic
// Java
UUID.randomUUID() // v4
// Go
import "github.com/google/uuid"
uuid.New() // v4
Need one or many UUIDs instantly? ToolsArena's UUID Generator creates bulk UUIDs (v1, v4, v7) in your browser — no server, no data sent over the network.
How to Use the Tool (Step by Step)
- 1
Open the UUID Generator
Navigate to ToolsArena's UUID Generator — no account, no install, works in any browser.
- 2
Select UUID version
Choose v4 for general-purpose random UUIDs, v7 for database primary keys (sortable), or v1 if you need timestamp-based identifiers.
- 3
Set quantity
Enter how many UUIDs you need — generate 1 to 10,000 at once for batch operations.
- 4
Copy or download
Click Copy All to copy to clipboard, or download as a .txt file for large batches. Each UUID is on a new line, ready to paste into your code or spreadsheet.
Frequently Asked Questions
What does UUID stand for?+−
UUID stands for Universally Unique Identifier. It is a 128-bit value specified in RFC 4122 (now superseded by RFC 9562) used to uniquely identify information in computer systems without a central authority.
What is the difference between UUID v4 and UUID v7?+−
UUID v4 uses 122 bits of cryptographic randomness — it is completely random and offers no ordering. UUID v7 encodes a Unix timestamp (milliseconds) in the first 48 bits, making UUIDs sortable by creation time. For database primary keys, UUID v7 is preferred because it avoids B-tree index fragmentation caused by random inserts.
Can two UUIDs ever be the same?+−
Technically yes, but the probability is negligible. With UUID v4 (122 random bits), you would need to generate approximately 2.71 quintillion UUIDs to have a 50% chance of a single collision. Using a cryptographically secure random number generator (which all standard UUID libraries do) makes collisions a non-concern in practice.
Is GUID the same as UUID?+−
Yes, essentially. GUID (Globally Unique Identifier) is Microsoft's implementation of UUID. GUIDs are typically displayed in uppercase with curly braces — e.g., {550E8400-E29B-41D4-A716-446655440000} — but they use the same 128-bit format as standard UUIDs. .NET's System.Guid generates UUID v4 values.
Should I use UUID or auto-increment for database primary keys?+−
For single-server applications, auto-increment BIGINT is simpler and faster. For distributed systems, microservices, or when you need to generate IDs client-side without a database round-trip, use UUID v7. Avoid UUID v4 for primary keys in large tables — its random ordering causes index fragmentation and slower inserts.
What is the nil UUID?+−
The nil UUID is 00000000-0000-0000-0000-000000000000 — all 128 bits set to zero. It is used as a sentinel value meaning "no UUID assigned" or as a default in nullable UUID fields, similar to NULL in SQL.
Generate UUIDs Instantly — Free
Create single or bulk UUIDs (v1, v4, v7) in your browser. No server calls, no signup. Copy, download, or use directly in your code.
Open UUID GeneratorRelated Guides
Hash Generator — MD5, SHA-256, SHA-1 and More Explained (2026)
Generate MD5, SHA-1, SHA-256, SHA-512 hashes online — understand hashing, verify file integrity, secure data.
Strong Password Guide
NIST 2024 guidelines, time-to-crack tables, and the right way to manage passwords.
Base64 Encode & Decode — What It Is, How It Works & When to Use It
Developer guide to Base64 encoding: use cases, online decoder, and common pitfalls