UUID format
A UUID is 128 bits, written as 32 hexadecimal digits in five groups:
xxxxxxxx-xxxx-Vxxx-Nxxx-xxxxxxxxxxxx
V is the version (4 or 7) and N is the variant (8, 9, a or b for standard UUIDs).
In a v7 UUID, the first 12 hex digits are the creation time in milliseconds, which is why v7 IDs sort by age.
When to use which
- Database primary keys: v7, for fast, sequential inserts.
- Public identifiers where creation time shouldn't leak: v4.
- Test data and fixtures: either; generate up to 1,000 at once.
Frequently asked questions
What's the difference between UUID v4 and v7?
Version 4 is completely random. Version 7 (RFC 9562) starts with a timestamp, so new IDs sort in creation order. That makes v7 a better choice for database primary keys, because inserts stay sequential and indexes stay efficient.
Can two UUIDs ever be the same?
In theory, but not in practice. A v4 UUID has 122 random bits; you'd need to generate about a billion UUIDs every second for 86 years to have a 50% chance of a single duplicate.
Is a GUID the same as a UUID?
Yes. GUID (globally unique identifier) is Microsoft's name for the same 128-bit format. They're written the same way, though GUIDs are often shown in uppercase and sometimes wrapped in braces.
Are these UUIDs random enough for security?
They're generated with your browser's cryptographically secure random number generator. Even so, don't use a UUID as a password or secret token; use a purpose-built token generator for that.