UUID Versions Explained: v1, v4, v7 and When to Use Each
A UUID is a UUID, right? Not quite — v1, v4, and v7 generate them completely differently and have different trade-offs. Pick the wrong one and you'll regret it later.
Every developer has generated a UUID at some point — you run a command, you get a long string with dashes, you stick it in a database and you never think about it again. Until you do. UUIDs aren't all the same. Version 1, version 4, and version 7 generate the same shape of string using completely different methods, and they have completely different properties. A UUID generator usually defaults to v4, and that's fine — until it isn't, because you needed sortable IDs and you didn't find out until you had ten million of them.
The Three Versions You'll Actually Use
v1 is timestamp + MAC address — time-ordered and guaranteed unique per machine, but leaks the MAC address and has privacy issues. v4 is random — 122 bits of randomness, no information embedded, impossible to guess, but not sortable by creation time. v7 is the new one — timestamp-prefixed random, so IDs sort chronologically while still being random and unguessable. The counter-intuitive part is that v4 isn't actually random in the way a random number generator is. It's cryptographically random, which is stronger — "random" usually means uniform distribution, and UUIDs care more about uniqueness than distribution.
How to Pick
Use v4 for most things — user IDs, session IDs, anything where you don't want anyone to be able to guess the next one or extract information from the ID. Use v1 only when you absolutely need time-ordered IDs and privacy isn't a concern — mostly legacy systems at this point. Use v7 when you need both sortable IDs and unguessability — database primary keys, event logs, message queues, anything where chronological order helps with indexing or debugging. For hashing UUIDs into shorter formats or using them as keys in other systems, a hash generator can turn a UUID into a deterministic shorter string when you need something more compact. The biggest mistake people make is picking v4 by default and then discovering six months later that they can't efficiently query by creation time without a separate index.
Default to v4, Know v7 Exists
We covered UUID collision math in our guide to UUID v4 collision probability; the version comparison is the same idea with more choices. Most of the time, v4 is still the right call — it's simple, it's standard, and every language supports it. But when you're designing a new system and you know you'll want chronological ordering, reach for v7 instead — it's the best of both worlds, and the support is there if you look for it.
Tools mentioned in this article
UUID Generator
Generate random UUID v4 identifiers. Click to copy, generate multiple at once with separator options. Good for database keys, test fixtures, or any time you need a unique ID.
Random Number Generator
Generate random numbers within a range. Set minimum, maximum, and count. Option to allow or exclude repeats. Good for raffles, sampling, and testing.
Hash Generator
Generate SHA-1, SHA-256, SHA-384, and SHA-512 hashes from any text. Also supports MD5 for legacy checks. Compare two hashes side by side to verify file integrity.
