What Is a UUID? A Complete Guide
A UUID (Universally Unique Identifier) is a 128-bit number used to uniquely identify information in computer systems. Also known as GUID (Globally Unique Identifier) in Microsoft ecosystems, UUIDs provide a way to generate unique IDs without requiring a central authority or coordination between distributed systems.
UUIDs were originally standardized in RFC 4122 (2005) and more recently updated in RFC 9562 (2024), which introduced new versions like UUID v7. The standard defines five versions of UUIDs, each with different generation methods and properties.
UUID Format
A UUID is displayed as 32 hexadecimal characters separated by hyphens in five groups:
xxxxxxxx-xxxx-Mxxx-Nxxx-xxxxxxxxxxxx
8-4-4-4-12 (36 characters including hyphens, 32 hex digits)
- M indicates the UUID version (1, 4, 7, etc.)
- N indicates the variant (8, 9, a, or b for RFC 4122 UUIDs)
- All other positions are random (for v4) or derived from timestamps/names
UUID Versions Compared
| Version | Generation Method | Sortable | Random Bits | Use Case |
|---|---|---|---|---|
| v1 | Timestamp + MAC address | Yes | 14 bits | Legacy systems |
| v3 | MD5 hash of namespace + name | No | 0 bits | Deterministic IDs |
| v4 | Random | No | 122 bits | Most common |
| v5 | SHA-1 hash of namespace + name | No | 0 bits | Deterministic IDs |
| v7 | Unix timestamp + random | Yes | 62 bits | Modern databases |
UUID v4 Deep Dive
UUID v4 is the most commonly used version. It generates 122 bits of cryptographically random data, with 6 bits reserved for version (4 bits = "0100") and variant (2 bits = "10") identification.
With 2^122 possible values (approximately 5.3 x 10^36), the probability of collision is vanishingly small:
Generating 1 billion UUIDs per second for 100 years:
~3.15 x 10^18 UUIDs total
Probability of at least one collision:
~0.00000000000000093 (less than 1 in a quadrillion)
Common Use Cases for UUIDs
- Database Primary Keys — UUIDs allow generating IDs on the client side or across distributed database nodes without coordination. Popular in PostgreSQL (uuid type), MongoDB, and DynamoDB.
- Session Tokens — UUID v4 is often used as a session identifier in web applications due to its randomness and unpredictability.
- API Resource IDs — Using UUIDs in API URLs (e.g., /users/550e8400-e29b-41d4-a716-446655440000) prevents enumeration attacks that are possible with sequential integer IDs.
- File Names — Generate unique file names for uploads to prevent collisions, especially in cloud storage systems like S3.
- Distributed Systems — UUIDs enable independent ID generation across microservices without a central ID server, reducing single points of failure.
- Idempotency Keys — APIs use UUIDs as idempotency keys to prevent duplicate processing of the same request.
UUID v4 vs UUID v7: Which Should You Use?
UUID v7 is a newer standard (RFC 9562, 2024) that combines a Unix timestamp with random bits. Here is when to use each:
Use UUID v4 when:
- You need maximum randomness and privacy (no timestamp leakage)
- Sorting order does not matter
- You are working with systems that only support RFC 4122
Use UUID v7 when:
- You need time-sortable IDs (better database index performance)
- You want to extract the creation timestamp from the ID
- You are building new systems with modern databases
UUID vs Other ID Formats
| Format | Length | Sortable | URL Safe | Notes |
|---|---|---|---|---|
| UUID v4 | 36 chars | No | Yes | Most widely supported |
| UUID v7 | 36 chars | Yes | Yes | Timestamp + random |
| ULID | 26 chars | Yes | Yes | Crockford Base32 |
| nanoid | 21 chars | No | Yes | Compact, URL-safe |
| Snowflake | 18 digits | Yes | Yes | Requires coordination |
| Auto-increment | Variable | Yes | Yes | Single DB only |
UUID as Database Primary Key: Pros and Cons
Advantages
- Generate IDs without database roundtrip
- Safe for distributed/multi-region systems
- No enumeration attacks (unlike /users/1, /users/2)
- Easy data merging across databases
- Client-side ID generation possible
Disadvantages
- Larger than integers (16 bytes vs 4-8 bytes)
- Random v4 UUIDs fragment B-tree indexes
- Harder to communicate verbally or type manually
- Slightly slower joins due to larger key size
- Not human-readable for debugging
How to Generate UUIDs Online — Step by Step
- 1. Select the Count (1, 5, 10, or 25) to generate multiple UUIDs at once.
- 2. Optionally enable UPPERCASE for uppercase hex characters (e.g., 550E8400-E29B-...).
- 3. Optionally enable No dashes to remove hyphens (e.g., 550e8400e29b41d4...).
- 4. Click Generate UUID to create fresh UUIDs using cryptographic randomness.
- 5. Hover over any UUID and click Copy, or use Copy All to copy the full list.
Frequently Asked Questions
How do I generate a UUID online?
Click the Generate button on this page to create a fresh UUID v4 instantly. You can generate up to 25 UUIDs at once, copy individual UUIDs or all of them with a single click, and choose formatting options like uppercase or no dashes.
What is UUID v4 and why is it the most popular?
UUID v4 generates 122 bits of cryptographic randomness, making it the simplest and most privacy-preserving UUID version. Unlike v1 (which leaks your MAC address) or v7 (which embeds a timestamp), v4 reveals no information about when or where it was generated. It is supported by every major programming language and database.
What is the probability of UUID v4 collision?
With 5.3 x 10^36 possible values, collision is practically impossible. Generating 1 billion UUIDs per second for 100 years would produce only a 0.00000000000000093 probability of a single duplicate. For all practical purposes, UUID v4 values are unique.
What is the difference between UUID v1, v4, and v7?
UUID v1 uses a timestamp and MAC address (sortable but leaks device info). UUID v4 is purely random (most common, no information leakage). UUID v7 uses a Unix timestamp plus random bits (sortable, better for database indexes, no MAC address leak). Choose v4 for general use, v7 for database primary keys.
Is UUID the same as GUID?
Yes. GUID (Globally Unique Identifier) is Microsoft's term for UUID. They follow the same RFC 4122 specification and are functionally identical. Windows APIs use the term GUID while most other platforms use UUID.
Are these UUIDs cryptographically secure?
Yes. This tool uses the browser's crypto.getRandomValues() API (via the uuid library) which provides cryptographically strong random numbers from the operating system's entropy source. The generated UUIDs are suitable for session tokens, API keys, and other security-sensitive applications.
Should I use UUID as a database primary key?
It depends on your needs. UUIDs are excellent for distributed systems, client-side ID generation, and preventing enumeration attacks. However, random UUID v4 values can cause B-tree index fragmentation. Consider UUID v7 or ULID for better index locality, or use sequential integer IDs for simple single-database applications.
Can I use UUID without dashes?
Yes. Enable the "No dashes" option to generate UUIDs in compact 32-character format (e.g., 550e8400e29b41d4a716446655440000). This is useful for filenames, URL slugs, and systems that don't accept hyphens. Both formats represent the same 128-bit value.