UUID Versions Reference
A UUID is a 128-bit identifier. The version nibble in the third group records how it was generated. These are the versions defined by RFC 9562 (which superseded RFC 4122).
| Version | Generated from | Time-ordered | Typical use |
|---|---|---|---|
| v1 | Timestamp + node (MAC) | Roughly | Legacy time-based ids |
| v3 | MD5 of a namespace + name | No | Deterministic ids from a name |
| v4 | Random | No | General-purpose unique ids |
| v5 | SHA-1 of a namespace + name | No | Deterministic ids (preferred over v3) |
| v6 | Reordered v1 timestamp | Yes | Sortable, v1-compatible |
| v7 | Unix epoch (ms) + random | Yes | Sortable keys for databases |
Frequently asked questions
Which UUID version should I use?
Use v4 for general unique identifiers, and v7 when you want database keys that sort by creation time. Use v5 when the id must be reproducible from a name.
Is UUID v7 better than v4 for database primary keys?
Often yes. v7 embeds a millisecond timestamp in its leading bits, so new ids are roughly sequential. That reduces index fragmentation compared to fully random v4.