Generate Random UUID
Generate up to 1,000 UUIDs at once: random version 4, or time-ordered version 7 for database keys. Copy them as standard, uppercase, unhyphenated, URN or 22-character Base64url text, and paste any UUID to see its version, variant and embedded timestamp.
RFC 9562 · generated in your browser with crypto.getRandomValues()
Anatomy of a Version 4 UUID
A UUID is 128 bits written as 32 hex digits in five groups of 8-4-4-4-12, 36 characters with hyphens. In a version 4 UUID, 6 of those bits are fixed and the other 122 are random:
| Position | Bits | Value | Meaning |
|---|---|---|---|
| 13th hex digit (start of group 3) | 4 | 4 | Version: always 4 for random UUIDs |
| 17th hex digit (start of group 4) | 2 of its 4 | 8, 9, a or b | Variant: the RFC 9562 layout |
| Everything else | 122 | Random | 5.3 × 10³⁶ possible values |
That gives a quick sanity check: a v4 UUID always has a 4 after the second hyphen and 8, 9, a or b after the third. If yours don't, the value was made by something else, or by a homemade generator that skipped the version bits.
UUID Versions 1 to 8 at a Glance
| Version | Built from | Use it for |
|---|---|---|
| 1 | Timestamp (100 ns since 1582) + node ID, often the MAC address | Legacy systems; reveals when and where it was made |
| 2 | DCE security: time + local user or group ID | Almost never used |
| 3 | MD5 hash of a namespace + name | The same name always gives the same UUID; prefer v5 |
| 4 | 122 random bits | The default for IDs, tokens and test data |
| 5 | SHA-1 hash of a namespace + name | Stable IDs derived from URLs or names |
| 6 | Version 1's timestamp reordered so it sorts | Upgrading v1 systems |
| 7 | 48-bit Unix time in ms + 74 random bits | Database primary keys that sort by creation time |
| 8 | Vendor-defined layout | Custom schemes |
RFC 9562 (May 2024) replaced RFC 4122 and added versions 6, 7 and 8. Microsoft calls UUIDs GUIDs; for .NET formats, byte order and SQL Server sorting, see the GUID generator.
How Likely Is a Duplicate?
With 2¹²² possible v4 UUIDs, the birthday approximation gives the chance of at least one duplicate among n UUIDs:
| UUIDs generated | Chance of any duplicate |
|---|---|
| 1 million | 9.4 × 10⁻²⁶ |
| 1 billion | 9.4 × 10⁻²⁰ |
| 1 trillion | 9.4 × 10⁻¹⁴ |
| 1 quadrillion | 9.4 × 10⁻⁸ |
| 2.7 × 10¹⁸ | 50% |
Reaching even odds would take generating a billion UUIDs every second for about 86 years. In practice, duplicates come from bugs, not chance: a generator using a weak or badly seeded random source, a cloned VM restarting with the same state, or code that copies an ID instead of creating one. Use a secure generator (as this page and crypto.randomUUID() do) and still put a unique constraint on the column.
Worked Example: Reading the Time Inside a v7 UUID
A support engineer sees the order ID 01a13498-edc0-7b2d-9e1f-0a2b3c4d5e6f in a log and wants to know when the order was created.
Step 1: Confirm the version
Step 2: Take the first 12 hex digits
Step 3: Read it as Unix milliseconds
This is why v7 UUIDs sort by time, and also why they leak it: anyone who sees the ID can tell when the record was made. Use v4 for IDs shown to customers when creation time is sensitive. The inspector below does these steps for any v1, v6 or v7 UUID.
Storing UUIDs: Text, Binary and Base64url
| Form | Size | Notes |
|---|---|---|
| Standard text | 36 characters | Readable; what APIs and JSON usually carry |
| Hex without hyphens | 32 characters | File names, some legacy columns |
| Binary | 16 bytes | PostgreSQL's uuid type; BINARY(16) elsewhere. Smallest and fastest to index |
| Base64url | 22 characters | Short and URL-safe, e.g. in links |
| URN | 45 characters | urn:uuid:… where a URI is required, as in XML namespaces |
RFC 9562 accepts upper, lower or mixed case, so compare UUIDs case-insensitively, or normalise to lowercase before storing text. A text column holding UUIDs takes more than twice the space of a native 16-byte type, and every index on it grows too.
For primary keys, random v4 values land all over a B-tree index, which hurts insert speed on big tables. Version 7 values arrive in order and append near the end of the index instead. PostgreSQL 18 added uuidv7() for exactly this.
Generating UUIDs in Code and Databases
// JavaScript (browsers on HTTPS, Node 19+)
crypto.randomUUID() // v4
# Python
import uuid
uuid.uuid4() # v4
uuid.uuid7() # v7, Python 3.14+
-- PostgreSQL
SELECT gen_random_uuid(); -- v4 (13+)
SELECT uuidv7(); -- v7 (18+)
// Java
java.util.UUID.randomUUID() // v4
# Linux / macOS shell
uuidgencrypto.randomUUID() only exists on secure (HTTPS or localhost) pages. Avoid homemade generators built on Math.random(): their output is predictable and far more likely to repeat.
Inspect a UUID
Paste a UUID with or without hyphens, braces or a urn:uuid: prefix. For versions 1, 6 and 7 the creation time is decoded; try the RFC's own v1 example, f81d4fae-7dec-11d0-a765-00a0c91e6bf6, made on 3 February 1997.
| Field | Value |
|---|---|
| Version | 7: Unix time + random |
| Variant | 9 → RFC 9562 (standard) |
| Created | 2026-10-13T09:30:00.000Z |
| Random bits | 74 |
| Standard form | 01a13498-edc0-7b2d-9e1f-0a2b3c4d5e6f |
| Base64url | AaE0mO3Aey2eHworPE1ebw |
Frequently asked questions
Should I use UUID v4 or v7?
v7 for database primary keys and anything you want sorted by creation time; v4 when the ID shouldn’t reveal when it was made, or when order doesn’t matter.
Can a UUID be used as a password or secret link?
A v4 UUID has 122 random bits, so it is hard to guess, but IDs are logged, shared and shown in URLs. Use a purpose-made token for secrets, and check access rights rather than relying on an unguessable ID.
Are UUIDs case-sensitive?
No. RFC 9562 allows upper, lower or mixed case, and they all mean the same value. Lowercase is the common convention.
What is the nil UUID?
00000000-0000-0000-0000-000000000000, all zeros. It means “no UUID” and often shows up when a field was never filled in. The max UUID, all f’s, is its counterpart.
Sources
- RFC 9562: Universally Unique IDentifiers (UUIDs): versions 1 to 8, variant bits, nil and max UUIDs.
- MDN: Crypto.randomUUID(): v4 UUIDs in secure contexts.
- Python documentation: uuid: uuid4() and uuid7() (added in 3.14).
- PostgreSQL documentation: UUID functions: gen_random_uuid() and uuidv7().
Related Tools
Create GUIDs for Microsoft and .NET fields.
Generate binary numbers with a chosen bit length.
Create a random pixel image and save it as a PNG.
Generate bytes in hex, Base64, or decimal format.
Pick a date between your chosen start and end dates.
Generate decimals with a chosen range and precision.