About
uuidgen was created and is maintained by the YouTube channel The Seasoned Programmer. Questions or suggestions? Email info@the-seasoned-programmer.com.
Every UUID on this site is made in your browser using crypto.getRandomValues, the same secure random number generator browsers use for encryption keys. Nothing is sent to a server.
What is a UUID?
A UUID (universally unique identifier) is a 128-bit number that anyone can make, on any computer, without asking a central authority, and still be confident nobody else will ever make the same one. That makes them handy as IDs for database rows, files, messages, devices and anything else that needs a name before it reaches a shared system. They were standardised in RFC 4122 (2005), which RFC 9562 replaced in 2024, adding versions 6, 7 and 8.
Which version should I use?
- Database primary keys: v7. Its timestamp prefix means new keys land at the end of the index, avoiding the page splits and cache misses that random v4 keys cause in B-tree indexes.
- Everything else that needs a random ID: v4. It reveals nothing about when or where it was made.
- The same input should always give the same ID: v5. For example, turning URLs or email addresses into stable IDs.
- v1, v3 and v6 are for compatibility with existing systems.
Name-based UUIDs (v5 and v3)
A v5 UUID is a SHA-1 hash of a namespace UUID followed by a name, with the version and variant bits set. The RFC predefines namespaces for DNS names, URLs, ISO OIDs and X.500 names, or you can make your own namespace by generating a v4 UUID once and keeping it. Anyone with the same namespace and name gets the same UUID, so services can agree on IDs without talking to each other. Note that the name can't be recovered from the UUID, but it can be guessed, so don't put secrets in names.
Storing UUIDs
- Use a native type where there is one:
uuidin PostgreSQL,uniqueidentifierin SQL Server,BINARY(16)in MySQL (withUUID_TO_BIN). That's 16 bytes instead of 36 characters. - SQL Server sorts
uniqueidentifiervalues by their last group first, so v7 UUIDs don't sort by time there. UseNEWSEQUENTIALID()or a sequential GUID scheme if insert order matters. - Compare UUIDs case-insensitively if they're stored as text:
A1B2…anda1b2…are the same UUID.