UUID Generator
UpdatedWhat is a UUID v4? A UUID v4 is a 128-bit identifier built from 122 random bits, written as 36 characters like 1f3d4c6a-9b2e-4f7a-8c1d-5e6f7a8b9c0d. Collisions are negligible: you would need about 2.7 quintillion UUIDs for a 50 percent chance of one duplicate. The generator below uses your browser's crypto.randomUUID and also makes v1, v5 and v7 IDs.
By version
What is a UUID?
A UUID (Universally Unique Identifier) is a 128-bit value standardized in RFC 9562, the May 2024 update that replaces the long-running RFC 4122. The canonical printed form is 32 lowercase hexadecimal digits arranged in five groups separated by hyphens: 8-4-4-4-12. Two specific positions inside that string carry structural meaning rather than payload bits. The 13th hex digit (the first character of the third group) is the version nibble, fixed to 4 for a v4 UUID, 1 for v1, 5 for v5, and 7 for v7. The 17th hex digit (the first character of the fourth group) holds the variant bits, set to 8, 9, a, or b for any UUID that follows the RFC 9562 variant.
Worked example: 550e8400-e29b-41d4-a716-446655440000. Reading left to right, the third group 41d4 opens with the version nibble 4, telling us this is a v4 UUID generated from random bits. The fourth group a716 opens with a, a valid RFC variant marker. The remaining 122 bits (everything outside those two reserved nibbles) carry the actual entropy. The 128-bit width is identical across every version, so the storage and on-the-wire footprint never changes regardless of which generation algorithm produced the value.
Choosing a UUID version
RFC 9562 defines eight versions, but four of them cover nearly all real-world code. The choice between them is not stylistic. Each version trades a different property against random-only entropy, and picking the wrong one shows up months later as either a security audit finding or a database performance regression.
- v1 embeds a 60-bit timestamp and the originating machine's 48-bit MAC address. The result is sortable by creation time, which is useful, but it leaks the MAC of the host that minted it, which is not. Most modern stacks treat v1 as deprecated and reach for v7 when time-ordering matters.
- v4 packs 122 random bits with no embedded metadata. There are about 5.3 x 10^36 possible values, so collisions are not a practical concern. v4 is the correct default for API request IDs, message envelopes, and anywhere ordering is irrelevant.
- v5 takes a SHA-1 hash of a namespace UUID concatenated with a name string, then masks in the version and variant bits. The output is fully deterministic: the same namespace and name always yield the same UUID. We reach for v5 when minting a stable internal ID derived from an external system's primary key (a Stripe customer ID, a GitHub repo full name) so that re-ingestion is idempotent.
- v7 prepends a 48-bit Unix-millisecond timestamp followed by 74 random bits. Successive inserts therefore land on the rightmost page of a b-tree primary-key index instead of scattering across pages, and the index pages stay hot in the OS cache because new rows always hit the same locality. On large tables that shows up as faster bulk inserts and less write amplification than random v4 keys. PostgreSQL 18 generates them natively with
uuidv7().
Worked example: insert one million rows into a Postgres table with a UUID primary key. With v4, every insert hits a random b-tree leaf page, the buffer pool churns, and bulk-load throughput collapses well below sequential-key baselines. Swap the same table to v7 and the throughput climbs back near serial-integer territory, because the index is effectively append-only against its rightmost edge. Secondary-index performance is identical across versions, so the win is concentrated entirely on the primary-key b-tree.
Common pitfalls
UUIDs look interchangeable on the page, and that visual uniformity is exactly what makes the misuses below so common. Each of these has shown up in production audits we have walked through, and each is preventable by picking the right primitive at the right layer instead of letting a generic v4 string carry weight it was not designed for.
- Using v4 UUIDs as session tokens or password reset tokens. The 122 bits of entropy are technically sufficient, but UUIDs are routinely logged on purpose (request IDs, trace IDs, error reports) and the version nibble at hex position 13 reveals structure that a pure-random token would not. We mint auth-adjacent identifiers from a dedicated CSPRNG: 32 bytes from
crypto.getRandomValues, Base64URL-encoded, handled like a password and never logged. - Storing UUIDs as
CHAR(36)orVARCHAR(36)in MySQL. The hyphenated string form occupies 36 bytes; the raw 128-bit value occupies 16. Switching the column toBINARY(16)makes each key 2.25 times smaller and fits more entries into every index page, which speeds up lookups. MySQL 8 converts both ways withUUID_TO_BIN()andBIN_TO_UUID(). - Picking v1 because somebody asked for "sortable IDs." v1 leaks the host MAC address into every emitted value, which is a privacy and fingerprinting problem the moment those IDs cross a trust boundary. RFC 9562 codifies v7 as the modern replacement, and we have not minted a new v1 in production code since the 9562 draft stabilized.
- Generating UUIDs on the client without
crypto.randomUUID(). AMath.random-based fallback is biased, predictable, and not collision-safe at scale.crypto.randomUUID()draws from the platform CSPRNG and ships natively in Node.js 14.17+, Chrome 92+, Firefox 95+ and Safari 15.4+. In browsers it only works on secure (HTTPS or localhost) pages, so on a plain HTTP page fall back tocrypto.getRandomValues, neverMath.random.
How do I generate a random UUID in Postman?
Use one of Postman's built-in dynamic variables. Put {{$guid}} or {{$randomUUID}} in the URL, a header or the request body, and Postman generates a fresh value when the request runs. Postman's dynamic variables reference describes $guid as “a uuid-v4 style guid” and $randomUUID as “a random 36-character UUID”.
In a JSON body, keep the quotes around the variable, because a UUID is a string:
{
"orderId": "{{$guid}}",
"requestId": "{{$randomUUID}}",
"quantity": 1
}In a pre-request or post-response script, the docs say to wrap the name in double curly braces and pass it to pm.variables.replaceIn(), for example pm.variables.replaceIn('{{$guid}}'). Variable names are case-sensitive, so type them exactly as shown. The same list has $timestamp, the current Unix timestamp in seconds, which you can read as a date in the epoch converter.
Both example values in Postman's docs have a 4 as the 13th hex digit, the version position explained above, so treat both variables as random v4-style IDs. The list has no time-ordered option. For database keys that should sort by creation time, make them with the UUID v7 generator and paste them in.
When to use this tool
We built the generator for three concrete workflows. The first is a QA engineer minting bulk seed data for a test fixture: a hundred v4 IDs at once, copied straight into a SQL script or a JSON test bundle, with no shell loop and no language-specific snippet to babysit. The second is a backend dev producing a v5 UUID derived from an external system's primary key (a Stripe customer ID, a Salesforce account ID, an Auth0 user_id) so the resulting internal record can be re-derived idempotently the next time the same record arrives through the ingestion pipeline. The third is an architect demonstrating v7 time-ordering during a design review: generating a handful of v7s in sequence shows the timestamp in the first twelve hex characters ticking upward, which sells the b-tree-friendliness argument faster than a benchmark slide does.
Frequently asked
Are UUIDs really unique?
For practical purposes, yes. A v4 UUID has 122 random bits, about 5.3 x 10^36 possible values, so you would need around 2.7 quintillion of them for a 50 percent chance of a single duplicate. At a billion UUIDs a second, that takes about 86 years.
Can I use a UUID as a session token?
We don't recommend it. A v4's 122 random bits are technically enough, but UUIDs get logged everywhere (request IDs, trace IDs, error reports) and people treat them as harmless. For anything auth-related, generate 32 bytes with crypto.getRandomValues, encode them as Base64URL, and handle the result like a password.
UUID v4 vs v7: which should I use?
Use v7 for database primary keys and v4 where order doesn't matter, such as request IDs. A v7 UUID starts with a 48-bit Unix millisecond timestamp, so new rows land on the rightmost page of the primary-key index, while random v4 keys land on random pages, which fragments the index and churns the buffer cache. The trade-off is that anyone holding a v7 can read when it was created, so prefer v4 for public IDs where that matters. Use v5 when the same input must always produce the same UUID, and avoid v1, which embeds a MAC address and which RFC 9562 effectively replaces with v7.
How do I generate UUIDs in JavaScript, Python, or SQL?
JavaScript: crypto.randomUUID() returns a v4 in every modern browser and in Node.js 14.17 and later, and the uuid npm package has v7() since version 10. Python: uuid.uuid4() from the standard library. PostgreSQL has gen_random_uuid() for v4 since version 13 and a built-in uuidv7() since version 18.
Is crypto.randomUUID() safe for production?
Yes. It draws from the platform's cryptographically secure random generator and returns an RFC-compliant v4 string. It is available in Node.js 14.17+, Chrome 92+, Firefox 95+ and Safari 15.4+, so no polyfill is needed; just note that it only produces v4.
Sources: RFC 9562, UUID versions 1 to 8 · MDN on crypto.randomUUID(). How we check our data