UUID v4 generator
What is a UUID v4 Generator?
A UUID v4 generator creates version 4 Universally Unique Identifiers — 128-bit random IDs like 550e8400-e29b-41d4-a716-446655440000 — that are practically guaranteed to be unique without any central coordination. UUIDs (defined by RFC 9562, which obsoleted the older RFC 4122) solve one of the most common problems in software: how do two systems, databases, or devices each create identifiers independently while being confident they will never collide?
The answer lies in the sheer size of the space. A UUID is 128 bits, and version 4 fills 122 of those bits with cryptographically secure random data (6 bits are fixed: 4 for the version nibble, 2 for the variant). That yields 2^122 ≈ 5.3 × 10^36 possible values. The collision math is so favorable it feels like a trick: you would need to generate about a billion UUIDs per second for a century before reaching even a 50% chance of a single collision. For all practical purposes, every UUID v4 ever generated is unique — no database sequence, no central registry, no coordination required. This property is what makes UUIDs the default choice for distributed primary keys, idempotency tokens, session identifiers, and any ID minted at the edge.
The format itself carries meaning. A UUID v4 is written as 32 hexadecimal digits in five groups — 8-4-4-4-12 — like xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx. The 4 at the start of the third group is the version nibble identifying it as v4 (random); the first character of the fourth group (y) is the variant field, constrained to 8, 9, a, or b, marking the RFC 4122/9562 variant. These fixed bits are how parsers distinguish v4 from other versions: v1 (timestamp + MAC address), v3/v5 (namespace-hashed with MD5/SHA-1 — deterministic, same input always yields the same ID), v6/v7 (time-ordered, with v7 designed for database-friendly sortable IDs), and v8 (custom/experimental).
Why v4 specifically? Because it is the simplest version with the strongest privacy property: pure randomness means the ID reveals nothing about when or where it was created — unlike v1, which embeds a timestamp and the machine's MAC address. The one caveat: because v4 IDs are random, they are not sortable and they fragment database indexes (random insertion order in B-trees), which is why high-write systems sometimes prefer v7. For the vast majority of uses — API resource IDs, test fixtures, correlation IDs, file names — v4 is exactly right.
Our free UUID v4 generator produces cryptographically secure version 4 UUIDs using a proper CSPRNG (cryptographically secure pseudorandom number generator) — not the weak Math.random() that some toy generators use — in bulk, with formatting options (uppercase/lowercase, with or without hyphens, braces). Your requests are processed instantly and never stored. It works hand in hand with our random number generator for test data and our JSON validator when you embed fresh IDs into API payloads.
How to Use the UUID v4 Generator
Generating UUIDs takes seconds:
- Choose how many you need. Set the quantity — one ID for a quick need, or hundreds/thousands for seeding a database, generating test fixtures, or creating a batch of idempotency keys.
- Pick your format. Select lowercase (the standard, e.g.
550e8400-...), uppercase, hyphen-less (32 hex chars, common in some APIs), or brace-wrapped ({550e8400-...}, the Windows/COM convention). The underlying value is identical; only the presentation differs. - Generate. Click the generate button. Each UUID is produced from 122 bits of cryptographically secure random data with the version and variant bits set correctly per RFC 9562.
- Copy or download. Copy individual IDs or grab the whole batch as a list — paste them into your code, SQL seeds, JSON payloads, or config files.
- Validate existing IDs if needed. Have a UUID from elsewhere and not sure it is well-formed? A valid v4 matches the pattern
xxxxxxxx-xxxx-4xxx-[89ab]xxx-xxxxxxxxxxxx— the4version nibble and the8/9/a/bvariant character are the tells. Our JSON validator can also confirm IDs embedded in payloads parse correctly. - Use them correctly. Treat generated UUIDs as opaque identifiers: store them as native UUID/CHAR(36)/BINARY(16) columns, never derive meaning from them, and never use them as secrets (they are identifiers, not passwords — for secrets use our password generator).
Key Features of the UUID v4 Generator
Cryptographically secure randomness. IDs are generated from a CSPRNG — the operating system's secure entropy source — not a predictable PRNG. This matters whenever UUIDs serve as unguessable tokens (password-reset links, invite codes, idempotency keys).
Bulk generation. Generate one UUID or thousands in a single click, each independently random — ideal for database seeding, load-test fixtures, and batch data pipelines.
Multiple output formats. Lowercase standard, uppercase, hyphen-less 32-character, and brace-wrapped variants cover every common convention, from REST APIs to .NET GUIDs to SQL literals.
RFC 9562 compliant. Version nibble (4) and variant bits (10xx) are set correctly, so generated IDs validate against every standards-compliant UUID parser and library.
Collision-safe by construction. With 122 random bits per ID, the birthday-paradox math gives you effectively zero collision risk — no uniqueness checking against a central store is ever needed.
Instant and private. No signup. Your generations are processed instantly and never stored or logged.
| Version | How it is generated | Sortable? | Best for |
|---|---|---|---|
| v1 | Timestamp + MAC address | Yes (by time) | Legacy systems; leaks MAC — avoid for privacy-sensitive use |
| v3 / v5 | MD5 / SHA-1 hash of namespace + name | No | Deterministic IDs: same input → same ID (e.g. stable IDs from natural keys) |
| v4 | 122 bits of secure randomness | No | General-purpose unique IDs; unguessable tokens |
| v6 / v7 | Timestamp-first, time-ordered | Yes | Database primary keys at high write volume (v7 is the modern pick) |
| v8 | Custom / experimental | Depends | Vendor-specific schemes |
The practical takeaway: default to v4 unless you have a specific reason not to. Reach for v7 when you need time-ordered, index-friendly primary keys, and for v5 when you need the same input to deterministically produce the same ID.
UUID v4 Generator Use Cases
Developers
The problem: You are building a distributed system — microservices, mobile clients creating records offline, or a multi-region database — and auto-increment integer IDs will collide or leak information (sequential IDs reveal how many users/orders you have, and they are trivially enumerable: /orders/1245, /orders/1246...).
How this tool helps: Generate v4 UUIDs as your primary keys or public resource identifiers. Offline clients can mint IDs without contacting the server, merges never collide, and the IDs reveal nothing about your scale or creation order. During development, bulk-generate fixtures to seed realistic test databases, and validate payloads containing them with our JSON validator.
QA engineers and testers
The problem: Your test suite needs unique identifiers for every test run — user IDs, order IDs, correlation IDs — and hardcoded values cause cross-test contamination when tests run in parallel or against shared environments.
How this tool helps: Generate a fresh batch of UUIDs per test run and inject them as test data. Because each ID is unique, parallel tests cannot step on each other, and failed runs leave no ambiguous "which test created this record?" mysteries. Pair with our random number generator for randomized numeric fields in the same fixtures.
Students learning databases and APIs
The problem: Tutorials mention UUIDs constantly but the concept stays abstract — "a unique identifier" does not convey why 128 bits of randomness solves coordination problems that auto-increment keys cannot.
How this tool helps: Generate a handful of UUIDs and inspect their structure: find the 4 version nibble, spot the 8/9/a/b variant character, and count the 122 random bits. Then generate a thousand and observe that no two match — a visceral demonstration of the birthday-paradox math. Try storing them as primary keys in a toy database and compare insertion behavior against integers to feel the index-fragmentation tradeoff that motivates v7.
UUIDs in Practice: Code Examples
Generating UUIDs in application code is a one-liner in every major language — but each language has a right way and a subtly wrong way. Here are the correct patterns.
Python. Use the standard library: import uuid; user_id = uuid.uuid4(). This draws from os.urandom(), a CSPRNG — secure by default. Convert with str(user_id) for the hyphenated form or user_id.hex for 32 hex characters without hyphens. For deterministic IDs from a natural key, use uuid.uuid5(uuid.NAMESPACE_DNS, 'example.com').
JavaScript / Node.js. In modern runtimes, crypto.randomUUID() is built in — no package needed — and uses the platform CSPRNG. In browsers, the same crypto.randomUUID() is available in secure contexts. The old recipe of stitching Math.random() hex chunks together is insecure and obsolete; if you see it in a codebase, replace it. For bulk IDs, crypto.getRandomValues() fills a buffer efficiently.
PHP. Frameworks usually provide helpers (Laravel's Str::uuid()), but the portable core is random_bytes(16) with the version/variant bits set manually — or simply Ramsey\Uuid via Composer, the de facto standard library. Never use uniqid() for security-sensitive identifiers: it is timestamp-based and predictable.
Java. UUID.randomUUID() uses a CSPRNG (SecureRandom) internally — correct out of the box. UUID.nameUUIDFromBytes() gives you deterministic v3-style IDs from arbitrary input.
Databases. PostgreSQL: gen_random_uuid() (from pgcrypto) as a column default — id UUID PRIMARY KEY DEFAULT gen_random_uuid() is the idiomatic pattern. MySQL: UUID() generates v1 (note: not v4, and not suitable where unpredictability matters); for v4 in MySQL 8, combine UUID_TO_BIN() with application-generated values. SQL Server: NEWID() for v4-style GUIDs, NEWSEQUENTIALID() for index-friendly sequential GUIDs.
Common mistakes to avoid. Do not use UUIDs as sortable identifiers and then wonder why pagination is odd — v4s have no order; add a created_at column for ordering. Do not expose sequential database IDs publicly while using UUIDs internally and assume the UUIDs provide security — they provide uniqueness, and unguessability only when generated from a CSPRNG. Do not truncate UUIDs to "make them shorter" — an 8-character prefix has only 32 bits of entropy and collides fast at scale. And do not generate UUIDs with Math.random(), rand(), or any non-crypto PRNG when the IDs protect anything (reset tokens, invite links) — predictability there is a vulnerability, not a quirk.
When to reach for alternatives. Need short, URL-friendly IDs? Consider Nano ID or ULIDs (which are also time-sortable). Need database-cluster-friendly keys? UUID v7. Need human-readable references for support tickets? Keep the UUID internally and expose a short, separate ticket number. The UUID is the workhorse; these are the specialists.
UUID Storage and Indexing Tips
How you store UUIDs affects performance more than most developers expect. In PostgreSQL, use the native uuid type: 16 bytes on disk, indexed efficiently, and readable in query output without conversion functions. In MySQL 8+, store as BINARY(16) via UUID_TO_BIN() — and pass true as the second argument to reorder the timestamp bytes for v1 UUIDs, which dramatically improves index locality. Avoid VARCHAR(36) or CHAR(36) for large tables: 36 bytes per key bloats every index that includes it, and string comparison is slower than binary comparison.
For v4 UUIDs specifically, accept that inserts will scatter across the B-tree — that is the price of randomness. Mitigate with adequate fill factor settings, periodic index maintenance, and by keeping UUID-keyed tables' secondary indexes lean. If write throughput becomes a bottleneck, that is your signal to evaluate v7: same 128-bit space, same tooling, but time-ordered so inserts append instead of scattering. And whatever version you choose, never use the UUID as a sort key for user-facing ordering — always order by an explicit timestamp column, which expresses intent instead of relying on ID generation order.
Frequently Asked Questions
What is a UUID?
A UUID (Universally Unique Identifier) is a 128-bit identifier standardized by RFC 9562 (formerly RFC 4122), written as 32 hexadecimal digits in five hyphen-separated groups (8-4-4-4-12), e.g. 550e8400-e29b-41d4-a716-446655440000. It is designed so that IDs generated independently — on different machines, at different times, with no coordination — are practically guaranteed unique. UUIDs are used as database primary keys, API resource identifiers, session tokens, and anywhere else decentralized unique IDs are needed.
What does the "v4" in UUID v4 mean?
The version nibble — the first hex digit of the third group — identifies how the UUID was generated. Version 4 means the ID was built from random (or pseudorandom) data: 122 of the 128 bits are random, with 4 bits fixed to 0100 (the digit 4) and 2 bits fixed for the variant. Other versions include v1 (timestamp + MAC), v3/v5 (namespace name hashes), and v6/v7 (time-ordered). You can recognize a v4 UUID at a glance by the 4 in position 15 (e.g. ...-41d4-...).
Can two UUID v4s ever collide?
Theoretically yes; practically no. With 122 random bits, there are about 5.3 × 10^36 possible values. By the birthday paradox, you would need to generate roughly 2.7 × 10^18 UUIDs — about a billion per second for 85 years — to reach a 50% chance of one collision. To put it another way: you are vastly more likely to be struck by lightning while winning the lottery than to ever observe a v4 collision. No central registry or duplicate-checking is needed.
Are UUIDs secure? Can I use them as passwords or tokens?
UUID v4s generated from a cryptographically secure RNG are unguessable (122 bits of entropy ≈ 37 random decimal digits), so they work fine as opaque tokens: password-reset links, email-verification tokens, API idempotency keys, invite codes. Our generator uses a CSPRNG, making its output suitable for these uses. They are not suitable as human-memorized passwords (use our password generator for those), and v1 UUIDs should never be used as secrets since they embed timestamps and MAC addresses.
What is the difference between UUID v4 and UUID v7?
v4 is pure randomness — maximum privacy (no embedded timestamp), but random insertion order, which fragments B-tree database indexes under heavy write loads. v7 is time-ordered: the first 48 bits are a Unix timestamp in milliseconds, followed by random data — so IDs sort chronologically and insert efficiently, while remaining unique and unguessable. Rule of thumb: v4 for general-purpose IDs and tokens; v7 for database primary keys in write-heavy tables. Both are defined in RFC 9562.
Should I store UUIDs as strings or binary in a database?
As binary (16 bytes) when performance matters, as text when simplicity matters. The hyphenated string form is 36 characters (36+ bytes in UTF-8); storing as BINARY(16) (MySQL) or uuid (PostgreSQL's native 16-byte type) halves the storage and speeds up indexes — significant at scale since every secondary index carries the primary key. PostgreSQL's native uuid type is the gold standard: compact storage with readable text I/O. Whatever you choose, use a native or binary type rather than VARCHAR(36) for large tables.
What is a GUID? Is it the same as a UUID?
Essentially yes. GUID (Globally Unique Identifier) is Microsoft's term for the same 128-bit identifier; a v4 GUID and a v4 UUID are structurally identical and interoperable. The differences are cosmetic and conventional: Microsoft typically displays GUIDs uppercase and brace-wrapped ({550E8400-E29B-41D4-A716-446655440000}), while the broader industry uses lowercase without braces. Our generator offers both formats — the underlying 128-bit value is the same either way.
Why do some systems use sequential IDs instead of UUIDs?
Sequential integer IDs are smaller (4–8 bytes vs 16), human-friendly, index-optimal (always appended, never fragmenting), and sortable by creation time. Their downsides: they require central coordination (a single sequence generator becomes a bottleneck and single point of failure in distributed systems), they leak business metrics (competitors can estimate your order volume), and they are enumerable (an attacker can iterate /users/1 through /users/100000). Many systems use both: integer primary keys internally, UUIDs as public-facing identifiers.