Good to know
The layout
Both versions follow RFC 9562, which replaced RFC 4122 in 2024. A UUID is 32 hexadecimal digits in groups of 8-4-4-4-12. The first digit of the third group is the version, and the first digit of the fourth group is 8, 9, a or b for the standard variant.
xxxxxxxx-xxxx-Vxxx-Nxxx-xxxxxxxxxxxx
Version 4
122 of the 128 bits are random, taken from crypto.getRandomValues, the browser’s cryptographic random source. The other 6 bits mark the version and variant. The chance of two v4 IDs ever matching is tiny: you would need about 2.7 × 1018 of them before a clash became a coin toss.
n ≈ √(2 × ln 2 × 2122) ≈ 2.7 × 1018
Version 7
A v7 UUID starts with the time in milliseconds since 1970 (48 bits), then the version, then a 12-bit counter, then the variant and 62 random bits. The counter goes up for each ID made in the same millisecond, so a batch from this page always sorts in the order it was created. If the counter fills up, the next millisecond is borrowed.
Worked example: 29 November 2025 at 00:00:00 UTC is 1,764,374,400,000 ms, which is 019acce8cc00 in hex. A v7 UUID made at that moment begins 019acce8-cc00-7…. Paste one into Inspect a UUID and it reads the time back for you.
Which to choose
- v7 for primary keys. New rows land at the end of the index, which keeps databases quicker than scattered random keys.
- v4 where the creation time should not be visible, or when the order does not matter.
What a UUID is not
A UUID is an identifier, not a secret. It may be logged, shown in links and shared, and v7 openly reveals when it was made. For password reset links and API keys, use a dedicated secret token.