What is a UUID — and should you use version 4 or version 7?
How UUIDs identify things without a central counter, how to read one, why collisions are not a practical worry, and which version to use for database keys.
Published
Tools for this job: UUID Generator · Random Number Generator · Timestamp Converter
A UUID — universally unique identifier — is a 128-bit label such as 0189d5f2-1e4c-7a3b-9c2d-4e5f6a7b8c9d. Its purpose is to let any computer create an identifier on its own, without asking a central database for the next number, and still be confident no one else will ever create the same one.
Why not just count?
A simple counter — 1, 2, 3 — needs one place that hands out numbers. That becomes a problem when records are created on many servers, on phones that are offline, or in systems that are merged later. Counters also reveal how many records exist, and let anyone guess the next one. UUIDs avoid both.
Reading a UUID
A UUID is written as 32 hexadecimal digits in five groups: 8-4-4-4-12. The first digit of the third group is the version — 7 in the example above. The first digit of the fourth group encodes the variant, and for standard UUIDs it is always 8, 9, a or b. Lower-case, hyphenated form is the standard; braced and upper-case versions exist mainly for older Microsoft tooling, which calls them GUIDs.
Version 4: random
A version 4 UUID fills 122 of its 128 bits with random data. With that many possibilities, you would need to generate around 2.7 × 10¹⁸ of them before a collision became likely — far beyond any real system. Because they are unpredictable, version 4 UUIDs suit public identifiers and tokens where the creation time should not be guessable.
Version 7: time-ordered
Random identifiers have a weakness in databases. Rows arrive with keys scattered all over the range, so new entries land all over the index, which grows fragmented and slow. Version 7 puts a 48-bit timestamp, in milliseconds, at the front, followed by random bits. Identifiers created later sort later, new rows land at the end of the index, and you can sort or filter by creation time.
The trade-off is that a version 7 UUID reveals roughly when it was created. For an internal primary key that is usually fine; for a public token, use version 4.
Generate UUIDs step by step
- Open the UUID Generator and choose version 4 or 7.
- Set how many you need — up to ten thousand at once, enough to seed a test database.
- Pick the format: standard, upper-case, braced or without hyphens.
- Copy the list or download it as a text file.
Both versions are generated with your browser's cryptographic random number generator and set the version and variant bits correctly, so they validate against the current standard, RFC 9562.
Practical tips
- Store UUIDs in a native UUID column where your database has one; it is smaller and faster than text.
- Do not treat a UUID as a secret. Unguessable is not the same as access control.
- Pick one format and stick to it across systems, so comparisons do not fail on case or hyphens.
For a plain random number rather than an identifier, use the Random Number Generator; to read the time inside a timestamp, the Timestamp Converter.