UUID generator

Generate one or a thousand UUIDs, version 4 (random) or version 7 (time-ordered).

This tool runs in your browser. We never send what you type or paste to a server.

v4 or v7?

  • Version 4 is 122 random bits. It's the most common choice and reveals nothing about when it was made.
  • Version 7 (RFC 9562, 2024) starts with a 48-bit millisecond timestamp followed by random bits, so new IDs sort after old ones. That keeps database indexes compact and fast, which makes v7 a great choice for primary keys.

Will two UUIDs ever collide?

For v4, you'd need to generate about 2.7 quintillion (2.7 × 1018) UUIDs for a 50% chance of a single duplicate. In practice, collisions only happen with broken random number generators. stackbite uses your browser's cryptographic generator.

Reading a UUID

018f3a6e-7c21-7b4e-9a3d-5f1c2e8b4d60
              ^    ^
              |    variant (8, 9, a or b)
              version (7)

The first character of the third group is the version. A v7 UUID starts with the time it was made in milliseconds, so v7 IDs sort in creation order. That keeps database indexes compact, which is why v7 is a good choice for primary keys.

Where the 128 bits go

A UUID is 16 bytes written as 32 hex digits in groups of 8-4-4-4-12. Six of the bits are fixed in both versions this tool makes: four for the version (the first digit of the third group) and two for the variant (the first digit of the fourth group is 8, 9, a or b). The rest, per RFC 9562:

v4   122 random bits
v7   48-bit Unix time in milliseconds | version | 12 random bits | variant | 62 random bits

Because a v7 UUID starts with the time, you can read it back. The example from above was made at 17:51:10.369 UTC on 2 May 2024:

const v7 = '018f3a6e-7c21-7b4e-9a3d-5f1c2e8b4d60';
const ms = parseInt(v7.replace(/-/g, '').slice(0, 12), 16);   // first 48 bits
console.log(ms);                                // → 1714672270369
console.log(new Date(ms).toISOString());        // → 2024-05-02T17:51:10.369Z
console.log(v7[14], v7[19]);                    // → 7 9   version, then variant

That is also the privacy cost of v7: anyone who sees the ID learns when the record was created. Use v4 for IDs that appear in public URLs if that matters. When you generate several v7 UUIDs here in the same millisecond, the list is sorted so it stays in order.

Generating UUIDs in code

In JavaScript, crypto.randomUUID() returns a v4 UUID in every current browser (on HTTPS pages and localhost) and in Node. Avoid snippets built on Math.random(), which is not designed to be unpredictable or collision-resistant. To check that a string is a well-formed UUID:

console.log(crypto.randomUUID());     // → e.g. 3b241101-e2bb-4255-8caf-4136c566a962
const UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
console.log(UUID_RE.test('018f3a6e-7c21-7b4e-9a3d-5f1c2e8b4d60'));   // → true
console.log(UUID_RE.test('018f3a6e-7c21-7b4e-ca3d-5f1c2e8b4d60'));   // → false   c is not a valid variant

There is no built-in v7 in JavaScript yet. Setting the bits yourself takes a few lines; this is essentially what the tool does:

function uuidv7() {
  const b = crypto.getRandomValues(new Uint8Array(16));
  let t = Date.now();
  for (let i = 5; i >= 0; i--) { b[i] = t % 256; t = Math.floor(t / 256); }   // 48-bit big-endian time
  b[6] = (b[6] & 0x0f) | 0x70;   // version 7
  b[8] = (b[8] & 0x3f) | 0x80;   // variant 10xx
  const h = [...b].map((x) => x.toString(16).padStart(2, '0')).join('');
  return `${h.slice(0, 8)}-${h.slice(8, 12)}-${h.slice(12, 16)}-${h.slice(16, 20)}-${h.slice(20)}`;
}
console.log(uuidv7());                          // → e.g. 019a8a1c-5e2b-7c3d-8f40-1b2c3d4e5f60

Python's uuid module makes v4 and also v5, which hashes a namespace and a name, so the same input always gives the same UUID:

import uuid
u = uuid.uuid4()
print(u)                          # → e.g. 9f1c6f3e-1b7a-4e2d-a5c4-0d8e7f6a5b4c
print(u.version, len(u.bytes))    # → 4 16
print(u.hex)                      # → e.g. 9f1c6f3e1b7a4e2da5c40d8e7f6a5b4c   no hyphens
print(uuid.UUID('018F3A6E-7C21-7B4E-9A3D-5F1C2E8B4D60'))   # → 018f3a6e-7c21-7b4e-9a3d-5f1c2e8b4d60   parsing normalises case
print(uuid.uuid5(uuid.NAMESPACE_DNS, 'example.com'))        # → cfbff0d1-9375-5685-968c-48ce8b15ae17   same name, same UUID

Python 3.14 added uuid.uuid7(), and its .time attribute returns the milliseconds. PostgreSQL has gen_random_uuid() for v4, and PostgreSQL 18 adds uuidv7() and uuid_extract_timestamp(). Not run here:

python3.14 -c "import uuid; u = uuid.uuid7(); print(u, u.time)"
SELECT uuidv7();                               -- PostgreSQL 18
uuidgen                                        # macOS, Linux (util-linux)
cat /proc/sys/kernel/random/uuid               # Linux

In a plain Bash with OpenSSL, set the version and variant on 16 random bytes; in PowerShell, use [guid]::NewGuid() (or New-Guid):

h=$(openssl rand -hex 16)
v=$(( (0x${h:16:2} & 0x3f) | 0x80 ))     # set the variant bits
printf '%s-%s-4%s-%02x%s-%s\n' "${h:0:8}" "${h:8:4}" "${h:13:3}" "$v" "${h:18:2}" "${h:20:12}"   # → e.g. 5c3e8f0a-9b1d-4c2e-b7a6-1f0e9d8c7b6a
[guid]::NewGuid().ToString()                    # → e.g. 0f8fad5b-d9cb-469f-a165-70867728950e
[guid]::NewGuid().ToString('N').ToUpper()       # → e.g. 0F8FAD5BD9CB469FA16570867728950E

Storage and comparison gotchas

  • Store 16 bytes, not 36 characters. Use the database's native type (uuid in PostgreSQL, uniqueidentifier in SQL Server, BINARY(16) in MySQL). A text column takes more than twice the space and makes every index bigger.
  • Case. RFC 9562 says to write UUIDs in lower case but accept either. Comparing them as strings without normalising treats ABC… and abc… as different IDs.
  • Microsoft byte order. .NET's Guid.ToByteArray() and SQL Server store the first three groups little-endian, so the same UUID has different bytes there than in PostgreSQL or Python's uuid.bytes. Convert through the string form when moving binary UUIDs between systems.
  • SQL Server sorting. uniqueidentifier sorts by the last group first, so v7 UUIDs do not come out in time order there without extra work.
$g = [guid]'00112233-4455-6677-8899-aabbccddeeff'
[BitConverter]::ToString($g.ToByteArray())      # → 33-22-11-00-55-44-77-66-88-99-AA-BB-CC-DD-EE-FF   first three groups reversed

Questions

Is a GUID the same as a UUID?

Yes. GUID is Microsoft's name for the same 128-bit identifier.

Can I generate UUIDs without hyphens?

Yes. Untick "Hyphens" to get the 32-character form.

How do I generate a UUID in JavaScript?

Call crypto.randomUUID(). It returns a random version 4 UUID such as 3b241101-e2bb-4255-8caf-4136c566a962 and works in current browsers on secure (HTTPS or localhost) pages and in Node.

How do I get the timestamp out of a UUID v7?

Take the first 12 hex digits (ignoring the hyphen), read them as a hexadecimal number, and you have milliseconds since 1 January 1970 UTC. In JavaScript: new Date(parseInt(uuid.replace(/-/g, '').slice(0, 12), 16)).

What is the nil UUID?

00000000-0000-0000-0000-000000000000, all bits zero. It is often used as a placeholder for "no ID". RFC 9562 also defines the max UUID, ffffffff-ffff-ffff-ffff-ffffffffffff.

Are UUIDs safe to use as secret tokens?

A v4 UUID from a cryptographic generator is hard to guess, but it was not designed as a secret, and v7 UUIDs are partly predictable from the time. For password-reset links or API keys, use a dedicated random token of at least 128 bits.