v4 or v7?
| Version | What it is | Use it for |
|---|---|---|
| v4 | 122 random bits | Anything where the id just needs to be unique |
| v7 | 48-bit timestamp, then randomness | Database keys, event ids, anything you’ll sort or page through |
| nil | All zeros | A placeholder meaning “no id” |
v4 is the one most people mean by “a UUID”. v7 is newer, standardised in 2024, and is the better default for rows in a database.
Why v7 is kinder to a database
A v4 UUID is random, so consecutive inserts land in unrelated places in the index. The database keeps splitting pages and jumping around the disk, and the index grows larger than it needs to be. It works, but it gets slower as the table grows.
A v7 starts with the time in milliseconds, so ids made close together sort close together. Inserts append to the end of the index, and “give me the newest 50 rows” becomes a range scan rather than a sort. You also get the creation time for free, without a separate column.
The trade-off is that the time is visible to anyone who sees the id.
Are they really unique?
A v4 UUID has 122 random bits. That’s a large enough space that collisions are a theoretical concern rather than a practical one: you’d need to generate about 2.7 quintillion ids for a 50% chance that any two matched, roughly 85 years of producing a billion every second.
What does go wrong in practice is a weak source of randomness: a library using Math.random, or a system where several machines start from the same seed. This page uses the browser’s cryptographic generator, which is designed for keys and tokens.
The formats you’ll meet
The same id turns up written in several ways, and they’re all the same 16 bytes:
0189d6a1-2b3c-4d5e-8f90-1234567890ab: the standard hyphenated form0189d6a12b3c4d5e8f901234567890ab: compact, common in URLs and some database columns{0189D6A1-2B3C-4D5E-8F90-1234567890AB}: braces and uppercase, from Microsoft toolsurn:uuid:0189d6a1-2b3c-4d5e-8f90-1234567890ab: the formal URN form
The generator writes whichever you tick, and the inspect box accepts all of them.
Reading a UUID
Two characters tell you most of what there is to know. The first character of the third group is the version, and the first character of the fourth group is the variant, which is 8, 9, a or b for anything modern.
That’s how the inspect box knows what you pasted, and how it can pull the timestamp back out of a v1 or a v7.