What Is a UUID? Format, Versions, and Use Cases Explained
A UUID (Universally Unique Identifier) is a 128-bit number formatted as a 36-character string. Correctly generated, a UUID has a collision probability so low it's treated as globally unique.
Advertisement
A UUID (Universally Unique Identifier) is a 128-bit identifier designed to be unique across space and time — without requiring a central registry or coordination between systems. If you generate a UUID on your laptop right now, it has a vanishingly small probability of ever matching one generated by any other device anywhere in the world. This property makes UUIDs invaluable in distributed systems, databases, and APIs.
UUID Definition
UUID stands for Universally Unique Identifier. It's a 128-bit (16-byte) number, usually represented as a 32-character hexadecimal string broken into five groups separated by hyphens. The format is standardized in RFC 4122. UUIDs are also called GUIDs (Globally Unique Identifiers) in Microsoft contexts — the two are technically identical.
Example UUID
550e8400-e29b-41d4-a716-446655440000 Breakdown: {time_low}-{time_mid}-{time_hi_version}-{clock_seq}-{node}
UUID Format Explained
A UUID is 36 characters total: 32 hex digits plus 4 hyphens. The 8-4-4-4-12 grouping is the standard representation:
UUID structure: 8-4-4-4-12
| Group | Characters | Meaning |
|---|---|---|
| xxxxxxxx | 8 hex chars (32 bits) | Time low (or random in v4) |
| -xxxx | 4 hex chars (16 bits) | Time mid (or random in v4) |
| -xxxx | 4 hex chars (16 bits) | Version + time high |
| -xxxx | 4 hex chars (16 bits) | Variant + clock sequence |
| -xxxxxxxxxxxx | 12 hex chars (48 bits) | Node (MAC address in v1, random in v4) |
The 13th character (the first character of the third group) encodes the UUID version. A UUID starting with `550e8400-e29b-4...` — the '4' indicates version 4. The 17th character (first of the fourth group) encodes the variant: 8, 9, a, or b indicates the standard RFC 4122 variant.
Advertisement
UUID Versions
UUID versions: how each is generated
| Version | Generation Method | Key Property | When to Use |
|---|---|---|---|
| v1 | Timestamp + MAC address | Sortable by time, exposes MAC address | Legacy systems needing time ordering |
| v2 | Timestamp + MAC + POSIX UID | DCE Security standard | Rarely used |
| v3 | MD5 hash of namespace + name | Deterministic (same input = same UUID) | Deterministic IDs from names |
| v4 | Random (122 random bits) | Completely random, most common | General purpose — default choice |
| v5 | SHA-1 hash of namespace + name | Deterministic, stronger than v3 | Deterministic IDs (preferred over v3) |
| v6 | Reordered timestamp | Sortable by time, privacy-safe | Database primary keys with time ordering |
| v7 | Unix timestamp + random bits | Sortable, random, modern | Database primary keys — recommended new projects |
UUID v4 is the most commonly used version for general-purpose IDs in applications. It's generated entirely from random bits, making it statistically unique without embedding any system information. UUID v7 is the emerging standard for database primary keys because it's both random (collision-resistant) and sortable by creation time (which improves database index performance).
UUID vs Auto-Increment IDs
UUID vs auto-increment ID comparison
| Property | UUID (v4) | Auto-Increment (INT/BIGINT) |
|---|---|---|
| Length | 36 chars (string) or 16 bytes (binary) | 4–8 bytes |
| Global uniqueness | Yes — no coordination needed | Only within a single table/database |
| Guessable | No — 122 random bits | Yes — sequential numbers |
| Index performance | Worse (random inserts fragment B-tree) | Better (sequential, compact) |
| Sharding / distributed | Excellent | Requires coordination or sequences |
| Reveals record count | No | Yes (last ID = total records) |
| Human-readable | No | Yes (small numbers) |
Generate UUID v4 Free
Generate one or multiple UUIDs instantly. Copy in standard or no-hyphen format.
When to Use UUIDs
- Distributed systems: multiple databases or services can generate IDs independently without coordination
- Security: UUIDs don't reveal your total record count or creation order to end users or attackers
- Public-facing APIs: exposing sequential IDs lets attackers enumerate resources (/api/users/1, /2, /3...)
- Merging databases: combining two databases' records requires globally unique IDs to avoid conflicts
- Client-side ID generation: mobile apps and frontend code can generate IDs before saving to the server
- Referencing records across microservices: a UUID generated in one service is valid as an identifier in any other
UUID in Databases
Storing UUIDs in databases has performance considerations. UUID v4's random nature creates random B-tree insertions — each new record inserts at a random position in the index, causing page splits and cache misses at scale. This is 'UUID fragmentation' and can significantly impact write performance on large tables.
Solutions: (1) Use UUID v7, which has a timestamp prefix making IDs time-sortable and inserts nearly sequential. (2) Store UUIDs as BINARY(16) instead of CHAR(36) — saves 20 bytes per row and improves comparison speed. (3) Use your database's native UUID type (PostgreSQL `uuid`, MySQL 8.0+ `UUID_TO_BIN()`).
How to Generate a UUID
- JavaScript/Node.js: crypto.randomUUID() (built-in since Node 19), or the 'uuid' npm package
- Python: import uuid; uuid.uuid4() — built into the standard library
- PostgreSQL: gen_random_uuid() — built-in, no extension needed
- MySQL: UUID() function — generates version 1 UUID
- Java: UUID.randomUUID() — generates version 4
- C#/.NET: Guid.NewGuid() — generates version 4 GUID
- Command line: python3 -c 'import uuid; print(uuid.uuid4())'
- Online: Use our free UUID Generator below
Free UUID Generator
Generate UUID v4 IDs in bulk. Copy to clipboard or download as a list.
Advertisement
Frequently Asked Questions
What is a UUID?
A UUID (Universally Unique Identifier) is a 128-bit identifier that's statistically unique across all space and time. It's represented as a 36-character string in the format xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx. UUIDs are used as record IDs, API keys, and identifiers in distributed systems.
What does UUID stand for?
UUID stands for Universally Unique Identifier. The 'universally unique' refers to the statistical guarantee that a UUID generated anywhere in the world has a negligible probability of colliding with any other UUID ever generated.
What is the difference between UUID and GUID?
UUID and GUID (Globally Unique Identifier) are functionally identical — GUID is Microsoft's name for the same 128-bit identifier format. Both follow RFC 4122. The terms are often used interchangeably in technical discussions.
Is UUID v4 truly unique?
Not mathematically guaranteed, but statistically certain. A UUID v4 has 122 random bits. The probability of generating two identical UUIDs is approximately 1 in 5.3 × 10^36. In practice, this collision probability is negligible — you'd need to generate approximately 2.71 quintillion UUIDs to have a 50% chance of any collision.
Should I use UUID or auto-increment for database IDs?
UUID v4 is better for distributed systems, security (non-guessable IDs), and merging databases. Auto-increment IDs are better for performance-critical applications where index fragmentation matters and global uniqueness isn't required. UUID v7 is an emerging middle ground: sortable by creation time (like auto-increment) but globally unique (like UUID v4).
How do I generate a UUID in JavaScript?
In modern Node.js: crypto.randomUUID() (built-in since Node 19). In browsers: crypto.randomUUID() is available in all modern browsers. For legacy environments: install the 'uuid' npm package and use uuidv4().