Reading a version 7 UUID by hand
A UUID looks like a random blob, but a version 7 UUID carries readable information. RFC 9562, the standard that defines UUIDs, gives this example: 017f22e2-79b0-7cc3-98c4-dc0c0c07398f. Take the hyphens out and you have 32 hex digits, which is 128 bits. Every one of those bits has a job, and we can read them all with nothing more than a calculator.
The first 12 hex digits, 017f22e279b0, are 48 bits of time. As a decimal number that is 1,645,557,742,000. It counts milliseconds since the start of 1970 in UTC, so it is 22 February 2022 at 19:22:22 UTC. That is 2:22:22 in the afternoon in New York, a date the authors of the standard clearly chose on purpose. Because the time comes first, sorting version 7 UUIDs as text also sorts them by when they were made.
The next digit is 7, the first digit of the third group. That is the version, and it is the same in every version 7 UUID. The three digits after it, cc3, are 12 random bits. The fourth group starts with 9, which is 1001 in binary. Its top two bits, 10, are the variant: they say this UUID follows the RFC layout and not one of the older Microsoft or NCS layouts. That is why the first digit of the fourth group is always 8, 9, a or b. The two bits left over in that digit, and the 15 digits after it, are 62 more random bits.
So a version 7 UUID is 48 bits of time, 4 bits of version, 2 bits of variant and 74 random bits. A version 4 UUID keeps the same version and variant positions and makes everything else random, 122 bits in all. How many is enough? The birthday rule says a collision becomes likely long before you have used up the space. For 122 bits, the number of UUIDs at which there is a 1% chance that any two match is about 3.3 × 10^17. If you made a million every second, that would take more than 10,000 years.
Version 7 has fewer random bits, 74, but they only have to be unique within the same millisecond. Two IDs made in different milliseconds already differ in their first 48 bits. This generator goes one step further for bulk lists. When it makes a second ID in the same millisecond, it does not draw fresh random bits; it takes the previous ID’s random part and adds one. RFC 9562 calls this method 2. The result is that a list of 1,000 version 7 UUIDs made in one click is already in sorted order, and each one is still unguessable from outside, because the starting point was random.
The honest limits. A UUID is unique, not secret: version 4 is hard to guess, but nothing about the format promises that, and version 7 openly shows its creation time. Use a real random token for anything that grants access. The clock in a version 7 UUID is your device’s clock, so a computer with the wrong time makes IDs with the wrong time in them. And these are only as random as crypto.getRandomValues, which every modern browser backs with the operating system’s secure random source.