How it works
Both versions follow RFC 9562, the current UUID standard:
- Version 4 fills 122 bits with cryptographically secure random data. The remaining 6 bits mark the version (the
4at the start of the third group) and the variant (the third group ends up starting with 8, 9, a or b). - Version 7 puts the current time, in milliseconds since 1970, in the first 48 bits and fills the rest with random data. Two v7 UUIDs created a second apart sort in that order, both as text and as bytes.
Uppercase and “without hyphens” only change how the UUID is written; the value is the same. Most systems accept either form, but lowercase with hyphens is the standard text format.
Anatomy of a UUID
| Part | Example (v7) | Meaning |
|---|---|---|
| First 12 hex digits | 017f22e2-79b0 |
Timestamp: 22 February 2022, 19:22:22 UTC |
| Next digit | 7 |
Version |
| Next 3 digits | cc3 |
Random |
| Next digit | 9 |
Variant (8, 9, a or b) |
| Last 15 digits | 8c4-dc0c0c07398f |
Random |
Generating UUIDs in code
| Language | Version 4 |
|---|---|
| JavaScript (browsers, Node.js) | crypto.randomUUID() |
| Python | uuid.uuid4() |
| Java | UUID.randomUUID() |
| C# | Guid.NewGuid() |
| PostgreSQL | gen_random_uuid() |