UUID v4 is random. UUID v7 is sortable. Most code uses the wrong one.
A UUID is 128 bits of identifier, formatted as 32 hex digits in five groups: xxxxxxxx-xxxx-Mxxx-Nxxx-xxxxxxxxxxxx. The character at position M encodes the version, the character at N encodes the variant. Most online generators give you v4 (random) by default — including, currently, this one. For 2026 database design, v4 is rarely the right choice. Here is what each version does and when to use it.
v1 — timestamp plus MAC address (don’t use)
Encodes a 60-bit timestamp and the network MAC address of the machine that generated the UUID. Sortable by time, technically. Leaks the MAC address of your server — useful for an attacker mapping your infrastructure. There are mitigations (random MAC, hashed MAC) but at that point you have reinvented v7. Skip.
v3 and v5 — deterministic name-based
MD5 (v3) or SHA-1 (v5) hash of a namespace UUID concatenated with a name. The same namespace+name always produces the same UUID. Useful when you need a stable ID derived from input you control (e.g., a deterministic ID from a file path, a URL, or an email address). Prefer v5 over v3 since MD5 is deprecated for security — though for name-based UUIDs the threat model is collision-by-accident, not adversarial, so v3 is workable.
v4 — 122 bits of pure random
The default everywhere. Twelve hex characters of metadata (version + variant), 30 hex characters of random. Probability of collision: negligible for any practical scale. Cryptographically random when generated with the right RNG. Excellent for stateless tokens, public-facing IDs where you do not want enumeration, and any case where you do not care about insertion order.
v6 — v1 reordered for sortability (niche)
Takes the timestamp fields of v1, reorders them most-significant-first so the UUID sorts lexicographically by creation time, but still includes the MAC. Largely a transitional spec. If you want time-sortable UUIDs, jump straight to v7.
v7 — what you actually want for database primary keys
Published in RFC 9562 (2024). First 48 bits are a Unix-millisecond timestamp, remaining bits are random. Lexicographically sortable, monotonic within a millisecond, no MAC leak. Designed specifically to be a good primary key in B-tree indexes. This is what you want in PostgreSQL, MySQL, or any database where insertion order matters for index locality.
Why v4 is bad as a database primary key
Pure-random UUIDs as a clustered or default index destroy insertion locality. Each new row lands in a random page of the index, causing random page splits in a B-tree, doubling or tripling write amplification on busy tables. Independent benchmarks (PlanetScale, Supabase, AWS RDS) consistently show 20–50% throughput penalty for v4 vs sequential or time-ordered IDs at scale. v7 keeps the benefits of UUIDs (no central authority, no enumeration risk) while restoring index locality.
ULID and the related crowd
ULID (Universally Unique Lexicographically Sortable Identifier) pre-dates v7 by several years and solves the same problem with Crockford Base32 encoding (26 characters instead of 36, no hyphens). NanoID, KSUID, Snowflake all live in this same space. They are all reasonable; v7 has the advantage of being a UUID and therefore plug-compatible with code expecting one.
Takeaway: For new database designs in 2026: use UUID v7 if your stack supports it, ULID if you prefer the shorter form, v4 only when you specifically want unsortable randomness (public-facing tokens, anti-enumeration). The generator on this page outputs v4 by default because it is what people search for — but if you are designing a primary key for a table that will grow, v7 is the better default. The 20–50% write-throughput penalty of v4-as-PK is real and shows up in production benchmarks, not just theory.
Sources: RFC 9562 (UUIDs, 2024 — supersedes RFC 4122) · ULID specification · Buildkite: v4 to v7 migration write-up.