DevKitHub

API & Security

UUID Generator — v4 and v7, with a UUID Decoder

Generate up to 1,000 version 4 or version 7 UUIDs at once, or paste one to read its version and timestamp. Values come from your browser’s cryptographic random number generator, not from a server.

0 lines

This tool runs entirely in your browser. Your input is never uploaded, stored or logged.

How it works

A version 4 UUID is 128 bits, of which 122 are random. Six bits are fixed: four identify the version and two identify the variant, which is why the thirteenth hex digit is always 4 and the seventeenth is always 8, 9, a or b.

The random bits come from your browser’s cryptographic generator — crypto.randomUUID where available, and crypto.getRandomValues otherwise. Neither is Math.random, which is seeded predictably and must never be used for identifiers that end up in a database or a URL.

With 122 random bits, collisions are not a practical concern: you would need to generate billions of UUIDs before the probability became worth thinking about. The real trade-off is not uniqueness but ordering — random values arrive in no particular sequence, which scatters writes across a B-tree index. Where insert order matters, UUIDv7 or a ULID keeps the uniqueness and adds a time prefix.

Version 7, defined by RFC 9562 in 2024, fixes that ordering. Its first 48 bits are the Unix time in milliseconds, so values sort by creation time as plain strings and new keys land at the end of an index; the remaining 74 bits after the version and variant are random. Within a single millisecond this generator takes the previous value and adds one to those random bits, which is the RFC’s monotonic method, so a batch keeps the order it was made in, and if the bits would overflow it refuses rather than wrapping round. The cost is that a v7 UUID reveals when it was created, to the millisecond. Paste any UUID into the inspector to see that: v7 gives its time directly, v1 and v6 count hundred-nanosecond steps from October 1582 — and can carry the generating machine’s MAC address — while v4 carries no time at all.

Common problems

Every example below is run against this tool in our test suite, so what it says here is what the tool actually does.

Count must be a whole number of at least 1

Why:
A fractional or zero count. The generator produces discrete values, so there is no sensible reading of 2.5 UUIDs.
Fix:
Enter a whole number between 1 and 1000.

Inserts slowed down after switching the primary key to a UUID.

Why:
Random keys land in random places in a B-tree index, so every insert dirties a different page instead of appending to the end. The index stops fitting usefully in cache and page splits multiply.
Fix:
Switch to v7 above, or use a ULID: both keep the uniqueness but put a timestamp in the high bits, so new keys sort last.

The same UUID came out twice.

Why:
Not a collision — 122 random bits do not repeat. It is Math.random somewhere in the chain, or a fixed seed in a test harness, or the value being cached and reused.
Fix:
Check that the generator is crypto.randomUUID or crypto.getRandomValues. Math.random is not a source of unique identifiers.

Frequently asked questions

Are these UUIDs safe to use as database keys?
Yes. Version 4 UUIDs are 122 bits of randomness from a cryptographically secure source, so collisions are not a practical concern. Random keys can fragment B-tree indexes, though; version 7 is the better choice where insert order matters.
Should I use UUID v4 or v7?
v7 for database primary keys, because it sorts by creation time and keeps inserts at the end of the index. v4 where the value must reveal nothing, such as a public identifier, because a v7 UUID exposes its creation time to the millisecond.
Are the UUIDs generated on your server?
No. They are generated in your browser using the Web Crypto API. Nothing is transmitted, stored or logged.

Read more about this

Last updated