UUID v7 embeds a 48-bit Unix millisecond timestamp in its leading bits, making new values sort chronologically. ORDER BY id gives creation-time order with no extra index. Specified in RFC 9562 §5.7.
Key points: 48-bit ms timestamp → 4-bit version → 12-bit counter → 62-bit random. The timestamp at the front means string sort = time sort (Lexicographical Order). Use v4 instead for public-facing IDs where creation time must not leak (v4 vs v7).
Read more: UUID Byte Layout · UUID in Databases · RFC 9562 changes
Generate a UUID v7 · Decode a UUID v7 timestamp
Frequently asked questions
What is the best way to learn how UUID v7 works?
Start with the bit layout: UUID v7 puts a 48-bit Unix millisecond timestamp in the leading bits, followed by a 4-bit version (7), a 12-bit monotonic counter, the 2-bit variant, and 62 random bits. The timestamp at the front is why v7 sorts chronologically as a plain string — key to B-tree performance. See the UUID Byte Layout guide and the UUID v7 Explained walkthrough.
Should I use v4 or v7?
Use v7 for database primary keys (time-sortable, index-friendly) and v4 for anything where creation order could leak information, like tokens or share links.
How many bits does a UUID have?
A UUID is exactly 128 bits (16 bytes). In the standard hyphenated string format, 4 bits are used for the version field (position 13) and 2 bits for the variant (high 2 bits of position 17), leaving 122 bits for version-specific data. UUID v4 uses all 122 bits for randomness; UUID v7 uses 48 bits for a Unix millisecond timestamp and 74 bits for a monotonic counter and randomness. See RFC 9562 §4.