UUID Generator (v4)
Generate cryptographically random UUIDs. Useful as primary keys, request IDs, file names.
What is a UUID?
A UUID - Universally Unique Identifier, also called a GUID - is a 128-bit value used to identify something uniquely without needing a central authority to hand out numbers. Any system can generate one independently and be confident it will never collide with any other.
Example: 550e8400-e29b-41d4-a716-446655440000
The format is 32 hexadecimal digits in five hyphen-separated groups. The M position indicates the version, and the N position encodes the variant.
Key takeaways
- A UUID is 128 bits, written as 36 characters including four hyphens.
- Version 4 UUIDs are random - 122 bits of randomness after version and variant bits.
- Collision probability is negligible: you could generate billions with no realistic risk.
- UUIDs are identifiers, not secrets - do not use them as security tokens.
- Random UUIDs make poor database primary keys because they fragment indexes.
UUID versions
| Version | Based on | Sortable? | Common use |
|---|---|---|---|
| v1 | Timestamp + MAC address | Roughly | Legacy; leaks the machine address |
| v3 | MD5 of a namespace + name | No | Deterministic IDs from known names |
| v4 | Random data | No | The general-purpose default |
| v5 | SHA-1 of a namespace + name | No | Deterministic IDs, preferred over v3 |
| v7 | Unix timestamp + random | Yes | Modern choice for database keys |
This generator produces v4 UUIDs, which is the right default for most purposes. Version 7 is worth knowing about if you are choosing database primary keys.
How unique is "unique"?
A v4 UUID has 122 random bits, giving about 5.3 × 10³⁶ possible values. The chance of a collision is governed by the birthday problem, but the numbers involved are so large that it stops being a practical concern.
| UUIDs generated | Probability of any collision |
|---|---|
| 1 million | About 1 in 10²⁵ |
| 1 billion | About 1 in 10¹⁹ |
| 103 trillion | About 1 in a billion |
| 2.7 × 10¹⁸ | About 50% |
To reach a 50% chance of a single collision you would need to generate roughly 2.7 quintillion UUIDs. At a billion per second that takes about 85 years.
Where UUIDs are used
- Database primary keys, particularly in distributed systems where rows are created in several places at once.
- Distributed system correlation IDs, tracing a request across many services.
- Idempotency keys, so a retried API call is not processed twice.
- File and object names where collisions must be impossible.
- Session and transaction identifiers in logging.
- Message IDs in queues and event streams.
UUIDs as database keys: the trade-offs
| Auto-increment integer | UUID v4 | UUID v7 | |
|---|---|---|---|
| Generated by | The database | Anywhere | Anywhere |
| Storage size | 4-8 bytes | 16 bytes | 16 bytes |
| Index locality | Excellent - sequential | Poor - random inserts | Good - time-ordered |
| Reveals record count? | Yes | No | Partially (timing) |
| Safe to expose publicly? | Not ideal | Yes | Mostly |
| Sortable by creation | Yes | No | Yes |
UUIDs are not secrets
If you need an unguessable token, the random string generator is the appropriate tool.
Frequently Asked Questions
What is a UUID?
A Universally Unique Identifier - a 128-bit value written as 32 hexadecimal digits in five hyphen-separated groups. It lets any system generate an identifier independently, without a central authority, and be confident it will not collide with any other.
What is the difference between a UUID and a GUID?
Nothing meaningful. GUID is Microsoft's name for the same 128-bit identifier standard. The terms are used interchangeably, though UUID is the name used in the formal specification.
What is UUID v4?
The random variant. After the version and variant bits are fixed, 122 bits are filled with random data, giving about 5.3 × 10³⁶ possible values. It is the right default for most purposes because it requires no coordination and leaks no information.
Can two UUIDs ever be the same?
In theory yes, in practice no. You would need to generate roughly 2.7 quintillion v4 UUIDs before reaching a 50 percent chance of a single collision. Real-world collisions come from weak random sources, such as cloned virtual machines sharing a seed, not from the mathematics.
Are these UUIDs cryptographically secure?
The randomness is - this generator uses the browser's cryptographically secure random source. That does not make a UUID suitable as a secret, however. Use a purpose-built random token for security purposes rather than a UUID.
Should I use UUIDs as database primary keys?
It depends. They are excellent in distributed systems where several nodes create records simultaneously, and they avoid exposing how many records you have. But random v4 UUIDs fragment B-tree indexes badly on large tables. UUID v7, which prefixes a timestamp, avoids that problem.
Why do random UUIDs slow down databases?
Because B-tree indexes perform best when new keys append at the end. Random UUIDs insert at arbitrary positions, causing page splits throughout the index and destroying cache locality. Sequential integers or time-ordered UUID v7 avoid this.
Can I use a UUID as a password reset token?
Better not to. UUIDs are designed for uniqueness rather than secrecy, and some versions leak information - a v1 UUID embeds a timestamp and the generating machine's MAC address. Use a cryptographically secure random string generated specifically as a token.
Are my generated UUIDs stored anywhere?
No. Generation happens entirely in your browser and nothing is transmitted or recorded. Refreshing the page discards everything.