What Is a UUID? v4 vs v7 and When to Use Each
A UUID (Universally Unique Identifier) is a 128-bit ID you can generate anywhere without asking a central counter, yet it's practically guaranteed to be unique. You'll find them as record IDs, file names, session and order numbers. Here's how they work and which version to pick. To make some right now, use the UUID Generator.
Anatomy of a UUID
A UUID is written as 32 hex characters in an 8-4-4-4-12 pattern: 550e8400-e29b-41d4-a716-446655440000 — 36 characters with the hyphens.
The first character of the third group is the version (4 above) and the first of the fourth group is the variant (a here), so you can tell how a UUID was made just by looking at it.
The versions
RFC 9562 defines eight versions; four come up in practice:
| Version | Contents | Pros | Cons |
|---|---|---|---|
| v1 | Timestamp + node ID | Time-ordered | Can leak the machine's MAC |
| v4 | 122 random bits | Simple, unguessable | Unordered; scattered in indexes |
| v5 | SHA-1 of namespace + name | Same input → same UUID | Not random |
| v7 | Millisecond time + random | Ordered and unguessable | Reveals creation time |
Can two UUIDs collide?
A v4 UUID has 2¹²² ≈ 5.3 × 10³⁶ possible values. By the birthday problem you'd need about 2.7 × 10¹⁸ of them for a 50% chance of one duplicate — roughly 85 years at a billion UUIDs per second. With a proper random source, collisions are not a practical concern.
What matters is the generator: this site's tool uses the browser's cryptographic crypto.randomUUID().
Database primary keys: v4 or v7?
Random v4 keys land all over a B-tree index, which on large, write-heavy tables means page splits and poor cache use. v7 keys are time-ordered, so new rows append at the end of the index — close to the performance of auto-increment integers, while still generated anywhere.
Rule of thumb: v4 for public-facing IDs where order doesn't matter, v7 for primary keys of busy tables. Remember that v7 exposes when a record was created.
Are UUIDs safe as secrets?
A UUID is an identifier, not a secret — it ends up in URLs, logs and screenshots. For password-reset links or API keys, use purpose-built random tokens of sufficient length. For strong passwords there's the Password Generator, and to fingerprint data, the Hash Generator.