v4 · random
default
122 random bits, then the version nibble is forced to 4 and the variant bits to RFC 4122. Browsers use crypto.randomUUID().
Use for tokens, request IDs, client-side keys, anything that should not leak time or identity.
Skip as a database primary key if you care about insert order — random IDs scatter B-tree pages.
v7 · time-ordered
sortable
First 48 bits are Unix time in milliseconds. The rest is random, with version 7. Newer IDs sort after older ones.
Use for database keys, event logs, queues — anywhere chronological order and index locality help.
Do not use if creation time should stay hidden. The timestamp is readable (this page shows it).
v5 · name-based
deterministic
SHA-1 of namespace UUID + name, then version 5. Same inputs always give the same ID.
Use for stable IDs from a DNS name, URL, or imported record — “give me the UUID for this string.”
Not for secrets. Anyone with the name can remake the ID. Prefer v5 over old MD5-based v3.
The other versions, briefly
v1 — timestamp + node (often a MAC). Time-ish, but can leak hardware. Legacy.
v3 — same idea as v5, hashed with MD5. Use v5 instead.
v6 — v1 rearranged so it sorts better. For new work, prefer v7.
v8 — custom layout. Only if you are defining your own scheme.
nil — all zeros. A sentinel, not a real ID.