How to generate UUIDs
- Pick a type. If you are unsure, use UUID v4 for general-purpose unique IDs, or UUID v7 for primary keys in a database.
- Choose how many you need (up to 1,000) and any formatting: uppercase, without hyphens, or wrapped in braces as some Microsoft tools expect.
- Click Generate and copy the list. Each ID is on its own line.
All values come from crypto.getRandomValues, the browser's cryptographically secure random number generator, not Math.random.
UUID v4 vs UUID v7 vs ULID
| UUID v4 | 122 random bits. Universally supported. Because values are random, inserting them into a B-tree index scatters writes across the index, which can slow down large tables. |
|---|---|
| UUID v7 | Defined in RFC 9562 (2024). The first 48 bits are a Unix timestamp in milliseconds, the rest is random. IDs sort by creation time, which keeps database indexes compact, and they fit any existing UUID column. |
| ULID | Also 48-bit time plus 80 random bits, written as 26 Crockford Base32 characters such as 01HZX3K8Q5M2V9T7RBN4C6YDEF. Shorter and URL-friendly, but stored as text unless your database has a ULID type. |
Examples
v4: 3f2b8c1e-9d4a-4f6b-8e2a-7c5d1b9a0e34
v7: 01928f3a-6b2c-7d4e-9f1a-2b3c4d5e6f70
ULID: 01J8ZK2W5S9X4Q7R3T6V8YBCDE
Nil: 00000000-0000-0000-0000-000000000000
Look at the first digit of the third group: it is the version (4 or 7). The first digit of the fourth group is the variant and is always 8, 9, a or b for standard UUIDs.
Generating UUIDs in code
// JavaScript (browsers, Node 19+)
crypto.randomUUID();
# Python
import uuid; uuid.uuid4()
-- PostgreSQL 13+
SELECT gen_random_uuid();
Frequently asked questions
Can two generated UUIDs ever be the same?
In theory yes, in practice no. With 122 random bits, you would need to generate about 2.7 quintillion v4 UUIDs to have a 50% chance of a single collision.
Are these UUIDs safe to use as secret tokens?
They are generated with a cryptographically secure source, but UUIDs are designed to be identifiers, not secrets. For session tokens or password reset links, use a dedicated random token with at least 128 bits and store it hashed.
Should I use UUID v7 for my database primary keys?
It is a good default for new systems. Time-ordered keys give better index locality than random v4 keys. The trade-off is that v7 reveals roughly when a record was created.
Are UUIDs case-sensitive?
No. RFC 9562 says UUIDs should be output in lowercase but compared case-insensitively. ULIDs are also case-insensitive and are conventionally uppercase.
Is GUID the same as UUID?
Yes. GUID is Microsoft's name for the same 128-bit format. Some Microsoft tools display it in braces, which you can enable above.
Related tools
Last updated: