...
This UUID generator makes version 4 and version 7 UUIDs right here in your browser. Version 4 comes from crypto.randomUUID() when your browser has it, and otherwise from crypto.getRandomValues() with the version and variant bits set by hand. Version 7 is built from the current time plus fresh random bytes. None of it touches my server. If you want to check that, open your browser's network tab and click Regenerate a few hundred times. You will see a whole lot of nothing.
I built it because most UUID sites still treat v4 as the only option, and because I wanted a decoder that tells me when a v7 ID was minted without me doing hex arithmetic on a napkin.
What a UUID actually is
A UUID is a 128-bit number written as 32 hex digits in five groups: 8-4-4-4-12. The current standard is RFC 9562 (May 2024), which replaced RFC 4122 and added versions 6, 7 and 8.
Two small fields tell you what kind of UUID you are holding:
- Version: the first hex digit of the third group. In
019535d9-3df7-79fb-b466-fa907fa17f9eit is 7. - Variant: the top bits of the fourth group. For every normal UUID the first hex digit there is
8,9,aorb. Anything else is a legacy NCS or Microsoft value, or garbage.
That means a v4 UUID has 122 random bits, not 128. Six bits are spent announcing what it is.
UUID v4 vs v7 vs v1 and v6
Version 4 is 122 random bits. It tells you nothing about when or where it was made, which is exactly what you want for IDs that show up in URLs.
Version 7 is the one I reach for on new tables. Its layout, straight from the RFC:
| Field | Bits | What goes in it |
|---|---|---|
| unix_ts_ms | 48 | Milliseconds since 1970-01-01 UTC |
| ver | 4 | 0111 (7) |
| rand_a | 12 | Random bits, or a counter for ordering within one millisecond |
| var | 2 | 10 |
| rand_b | 62 | Random bits |
Because the timestamp comes first, v7 UUIDs sort by creation time, both as bytes and as text.
How this page fills rand_a: it uses RFC 9562 section 6.2, Method 1, a 12-bit counter. On each new millisecond the counter starts at a random value with its top bit cleared (so it has room to count). Each further UUID in the same millisecond adds one. If the counter runs out, or your clock jumps backwards, the page keeps using the last timestamp (or moves it one millisecond ahead) so the next UUID is still larger than the previous one. rand_b is always 62 fresh random bits. The upshot: a bulk batch of 1,000 v7 UUIDs from this page comes out in strictly increasing order.
Version 1 is the old time-based format: a 60-bit count of 100-nanosecond intervals since 15 October 1582, plus a clock sequence and a node ID that was historically your network card's MAC address. The timestamp bytes are stored low-part first, so v1 values do not sort by time. Version 6 is the same data with the timestamp reordered so it does sort. The RFC is blunt about both: systems that do not need v1 compatibility should use v7 instead.
Versions 3 and 5 are hashes of a namespace plus a name (MD5 and SHA-1). Same input, same UUID, every time. Version 8 is a free-for-all for custom layouts.
Why v7 is better for database primary keys
Most databases keep primary keys in a B-tree. A random v4 key can belong anywhere in that tree, so every insert touches a random leaf page. Pages split all over the place, the hot part of the index is the whole index, and your cache works harder than it needs to.
A v7 key is always a little bigger than the last one, so inserts pile up at the right-hand edge of the index, much like an auto-increment integer. RFC 9562 section 6.11 calls this index locality. The size of the difference depends on your database, your hardware and your row sizes, so I am not going to hand you a made-up percentage. Benchmark your own workload if the number matters to you.
The trade-off: a v7 UUID leaks its creation time to anyone who sees it. For an order ID in a customer-facing URL that may be fine. For something like an account ID where signup time is sensitive, use v4.
If you are designing a schema around keys like these, I wrote a whole book on this sort of decision: Databases in the Era of AI.
UUID vs GUID
Same thing. GUID (globally unique identifier) is Microsoft's name for it. The differences are cosmetic: Windows tools like to print GUIDs in uppercase and wrap them in braces, like {6F9619FF-8B86-D011-B42D-00C04FC964FF}. The one real difference to watch for is binary storage. .NET's Guid.ToByteArray() writes the first three groups little-endian, so 00112233-4455-6677-... comes out as bytes 33 22 11 00 55 44 77 66 ... instead of the RFC order. If bytes move between systems, test a round trip.
Will I ever get a collision?
For v4 this is the birthday problem. With 122 random bits there are 2122 (about 5.3 × 1036) possible values. After generating n of them, the chance that at least two match is approximately:
p(n) ≈ 1 - e^(-n² / (2 × 2^122))
Plugging in real numbers:
- 1 billion UUIDs: p ≈ 9.4 × 10-20
- 1 trillion UUIDs: p ≈ 9.4 × 10-14
- For a 50 percent chance you need n ≈ √(2 ln 2 × 2122) ≈ 2.71 × 1018 UUIDs. At a billion per second, that is about 86 years of nonstop generating.
The real collision risks are boring: a generator using a weak or badly seeded random source, a VM snapshot restored twice with the same PRNG state, or someone copy-pasting a UUID from a tutorial into two config files. Use a CSPRNG (the v4 and v7 generators below all do) and still put a unique constraint on the column. It costs nothing.
For v7 the math is per millisecond: two UUIDs can only collide if they share a timestamp, and then they still need to match on the remaining 74 bits. That is plenty unless you are minting enormous volumes from many machines in the same millisecond.
Storing UUIDs in PostgreSQL
PostgreSQL has a native uuid type that stores the 16 bytes, not the 36-character string. gen_random_uuid() gives you a v4 and has been built in since PostgreSQL 13. PostgreSQL 18 added uuidv7(), uuidv4() (an alias) and uuid_extract_version(). I ran these against the official 18 and 17 Docker images: 18 works, 17 says uuidv7() does not exist.
-- PostgreSQL 18+
CREATE TABLE orders (
id uuid PRIMARY KEY DEFAULT uuidv7(),
created_at timestamptz NOT NULL DEFAULT now(),
total_cents integer NOT NULL
);
INSERT INTO orders (total_cents) VALUES (1999)
RETURNING id, uuid_extract_timestamp(id);
-- Any version since 13, random v4
CREATE TABLE sessions (
id uuid PRIMARY KEY DEFAULT gen_random_uuid()
);
On PostgreSQL 17 or older, generate v7 in your application and insert it into a plain uuid column. The column type does not care which version you give it.
Storing UUIDs in MySQL
MySQL has no UUID column type. Use BINARY(16) and convert at the edges. UUID_TO_BIN() turns the text form into 16 bytes and BIN_TO_UUID() turns it back. Tested on MySQL 8.4:
CREATE TABLE orders (
id BINARY(16) PRIMARY KEY,
total_cents INT NOT NULL
);
INSERT INTO orders (id, total_cents)
VALUES (UUID_TO_BIN('019535d9-3df7-79fb-b466-fa907fa17f9e'), 1999);
SELECT BIN_TO_UUID(id) AS id, total_cents FROM orders;
Both functions take an optional swap_flag. Setting it to 1 swaps the time-low and time-high groups, which only makes sense for version 1 UUIDs from MySQL's own UUID() function (that function returns v1). It moves the fast-changing part of the timestamp to the end so the index behaves better:
CREATE TABLE events (
id BINARY(16) PRIMARY KEY DEFAULT (UUID_TO_BIN(UUID(), 1)),
n INT
);
SELECT BIN_TO_UUID(id, 1) FROM events;
Do not use swap_flag = 1 with v7. A v7 UUID is already time-first, and swapping would scramble the order you chose it for. Also, always read back with the same flag you wrote with, or you will get a valid-looking but wrong UUID.
Generating UUIDs in code
Python. uuid.uuid4() uses os.urandom. uuid.uuid7() (and uuid6(), uuid8()) arrived in Python 3.14. Python's v7 uses a 42-bit counter for ordering within a millisecond.
import uuid
print(uuid.uuid4())
print(uuid.uuid7()) # Python 3.14+
u = uuid.UUID("019535d9-3df7-79fb-b466-fa907fa17f9e")
print(u.version, u.time) # 7 1740365184503 (ms since epoch for v7)
From the shell, python -m uuid prints a v4, and on 3.14 python -m uuid -u uuid7 -C 5 prints five v7s.
Node.js. crypto.randomUUID() is built in and uses a CSPRNG. It only makes v4. For v7, use a maintained package such as uuid from npm (import { v7 } from 'uuid') or a small function like the one in this page's source.
node -e "console.log(crypto.randomUUID())"
Go. The standard library has no UUID package. github.com/google/uuid is the usual choice, and v1.6.0 has NewV7:
package main
import (
"fmt"
"log"
"github.com/google/uuid"
)
func main() {
fmt.Println(uuid.New()) // v4, panics if the random source fails
id, err := uuid.NewV7()
if err != nil {
log.Fatal(err)
}
fmt.Println(id, id.Version())
}
Linux shell. uuidgen from util-linux (the uuid-runtime package on Debian and Ubuntu) prints a v4 with -r. Recent versions, such as the one in Debian 13, also accept -7 for v7. Check uuidgen --help on your box.
PowerShell. New-Guid or [guid]::NewGuid() for v4. If your PowerShell runs on .NET 9 or later (check [System.Environment]::Version), [guid]::CreateVersion7() gives you v7.
When not to use a UUID
A UUID is an identifier, not a secret. RFC 9562 says it outright: implementations should not assume UUIDs are hard to guess, and must not use them as security capabilities, meaning identifiers whose mere possession grants access. A v4 made with a good random source is hard to guess in practice, but that is not what the format promises, you cannot tell from looking at one how it was made, and v7 hands out its creation time with only 74 bits of randomness behind it. For API keys, session tokens, password reset links and invite codes, use a real random token and store its hash. My API key generator makes those, and the strong random password generator covers passwords.
A few other places I skip UUIDs:
- Small internal lookup tables that never leave the database. A
smallintis fine and much easier to read in a query plan. - Anything a human types. Nobody should read 36 characters over the phone. Use a short code instead, or a random PIN if it only needs to be digits.
- As a stand-in for authorization. Unguessable URLs are not access control. Check that the logged-in user may see the record, every time.
UUID generator FAQ
Is a UUID the same thing as a GUID?
Yes, for practical purposes. GUID is the name Microsoft uses for the same 128-bit identifier. The text form is the same 8-4-4-4-12 hex layout, and Windows tools often show it in uppercase inside curly braces. The only real gotcha is byte order: some Microsoft APIs store the first three groups little-endian, so the same GUID can look different as raw bytes.
Should I use UUID v4 or UUID v7?
Use v7 for database primary keys and anything you want to sort by creation time, because new values land next to each other in the index. Use v4 when the ID should reveal nothing, including when it was made. Both are 128 bits and fit the same uuid column.
Can two random UUIDs collide?
In theory yes, in practice no. A v4 UUID has 122 random bits. You would need about 2.7 quintillion of them before the chance of a single duplicate reaches 50 percent. A broken random number generator is a far more likely cause of duplicates than bad luck.
Are the UUIDs on this page generated on your server?
No. They are generated by JavaScript in your browser using the Web Crypto API, either crypto.randomUUID or crypto.getRandomValues. Nothing you generate or paste into the decoder is sent to sethserver.com.
Can I use a UUID as an API key, session token, or password reset token?
No. RFC 9562 says UUIDs must not be used as security capabilities, and a v7 UUID gives away its creation time and has fewer random bits. Use a purpose-built random token of at least 128 bits instead, and store only a hash of it.
How do I read the timestamp out of a UUID v7?
Take the first 12 hex digits (ignoring the hyphen), read them as one 48-bit number, and treat it as milliseconds since 1970-01-01 UTC. The decoder on this page does that for you, and PostgreSQL 18 has uuid_extract_timestamp for the same job.
How should I store UUIDs in MySQL?
Store them in a BINARY(16) column and convert with UUID_TO_BIN and BIN_TO_UUID. That is 16 bytes instead of 36 characters. Only pass swap_flag 1 for version 1 UUIDs from MySQL's UUID function. Version 7 UUIDs are already time-first, so convert them without swapping.
Related tools: API key generator, PIN generator, strong random password generator, secret key generator.
-Sethers