How to generate a UUID
- Select a version — choose v4 for a purely random UUID or v7 for a time-sorted UUID suited to database primary keys.
- Generate — click Generate (or set a count up to 10,000 and generate in bulk). Each UUID is created using your browser's cryptographically secure random number generator — no server involved.
- Copy — click Copy All to grab every UUID, or export as a JSON array, CSV, or SQL VALUES clause and paste directly into your code or database seed script.
UUID v4 vs v7 — which to use in 2026
v4 is 122 bits of pure randomness plus 6 version/variant bits — no timestamp component whatsoever. That makes it ideal for user IDs, session tokens, API keys, and any opaque identifier where sequential order must not leak. The downside: random insertion order destroys B-tree locality in databases, causing page splits and slower index scans on write-heavy tables.
v7 (RFC 9562, ratified 2024) embeds a 48-bit Unix millisecond timestamp in the first 48 bits, followed by random bits. Lexicographic sort equals time sort. Use v7 for database primary keys in PostgreSQL, MySQL, MongoDB, and any write-heavy table where chronological sort order matters. Index performance is dramatically better than v4 because rows insert in roughly sequential order. Most new schemas in 2026 default to v7. See the deep-dive: UUID v4 vs v7 for databases.
v1 encodes your MAC address and a timestamp — a privacy risk; avoid it in public-facing systems.
v8 is reserved for custom/experimental formats and is not intended for general use.
UUID format
A UUID is always 32 hexadecimal digits arranged in five groups separated by hyphens, totalling 36 characters:
xxxxxxxx-xxxx-Mxxx-Nxxx-xxxxxxxxxxxx - M — the version digit.
4for v4,7for v7. - N — the variant bits. Always
8,9,a, orbfor RFC 9562 UUIDs.
Example (v4):
550e8400-e29b-41d4-a716-446655440000
The format is identical whether you call them UUIDs (IETF) or GUIDs (Microsoft) — the 36-character string is the same. Some systems strip hyphens for a compact 32-char hex form; others wrap in braces ({550e8400-...}) for .NET Guid compatibility. This tool supports all three output styles.
UUID collision probability
UUID v4 has 122 random bits, giving 2122 possible values — approximately 5.3 × 1036 unique UUIDs. To put that in perspective:
- At 1 trillion (1012) generated UUIDs, the probability of any collision is roughly 1 in 1012 — one in a trillion.
- To reach a 50% chance of collision you would need to generate around 2.7 × 1018 UUIDs — more than the estimated number of grains of sand on Earth.
For practical purposes: you will never see a UUID collision in production. The birthday-paradox math only becomes relevant at astronomical scale. Read the full analysis: UUID collision probability explained.
UUID in different languages
Every major runtime ships native UUID generation. No third-party library needed in most cases:
JavaScript / TypeScript (Node.js 19+ and all modern browsers)
// Native — no library needed
crypto.randomUUID() // returns a v4 UUID string Python
import uuid
str(uuid.uuid4()) # v4 random UUID
str(uuid.uuid7()) # v7 time-sorted UUID (Python 3.14+) Go
import "github.com/google/uuid"
uuid.New().String() // v4
uuid.Must(uuid.NewV7()).String() // v7 PHP
// PHP 8.3+
$uuid = \Symfony\Component\Uid\Uuid::v4()->toRfc4122();
// or composer require ramsey/uuid
\Ramsey\Uuid\Uuid::uuid4()->toString(); SQL (PostgreSQL 13+)
SELECT gen_random_uuid(); -- v4, built-in, no extension needed When to use a UUID (and when not to)
- Use UUID: distributed system primary keys (no coordination needed), public-facing IDs where sequential enumeration would be a security risk, idempotency keys, request trace IDs.
- Skip UUID: human-readable slugs (
my-blog-postbeats01928f9c-9e42-7d3f-...), monotonic counters where you need guaranteed ordering without timestamp coupling, storage-constrained environments (128 bits vs. 64-bit integer). For those cases consider a password generator for secrets or a hash generator for content-addressed IDs — note that hashes and UUIDs serve different purposes: hashes are deterministic, UUIDs are not. - UUID vs ULID: ULIDs are also time-sortable but use base32 encoding and are 26 characters instead of 36 — shorter and URL-safe by default. UUIDs have broader ecosystem support. Read the comparison: NanoID vs UUID.
FAQ
Is UUID the same as GUID?
Yes. GUID (Globally Unique Identifier) is Microsoft's terminology; UUID (Universally Unique Identifier) is the IETF/RFC term. Both describe the same 128-bit, 36-character format defined in RFC 9562 (formerly RFC 4122). You will see "GUID" in .NET, SQL Server, and COM; "UUID" everywhere else — the underlying bytes are identical.
Can I use UUID as a database primary key?
Yes, and the version matters. Use v7 for primary keys — the embedded timestamp keeps rows inserting in roughly sequential order, which preserves B-tree locality and gives you far better index performance on write-heavy tables (PostgreSQL, MySQL InnoDB, MongoDB). Use BINARY(16) or the native UUID type rather than VARCHAR(36) to halve storage and index size. v4 works but causes random page splits at scale.
What's the difference between UUID and ULID?
Both are time-sortable 128-bit identifiers, but they differ in encoding and ecosystem. ULIDs encode as 26 base32 characters (URL-safe, no hyphens, case-insensitive), while UUIDs encode as 36 hex characters with hyphens. UUIDs have native support in virtually every database, language runtime, and framework. ULIDs are more compact and prettier in URLs. If you're starting from scratch and don't need UUID compatibility, either works — pick UUID for maximum portability.
Why not v1 or v5?
v1 encodes your MAC address and a high-resolution timestamp — a privacy leak in public-facing identifiers. v5 generates deterministic UUIDs from a namespace + name hash (SHA-1), useful for reproducible IDs but not for unique random ones. v4 and v7 cover ~99% of real-world use cases.
Is this tool offline?
Yes. All generation uses crypto.randomUUID() (v4) and crypto.getRandomValues() (v7 entropy) — both backed by your operating system's CSPRNG. No data is sent to any server.
Related tools
- JSON Formatter — Format, validate, and beautify JSON online. 100% client-side — your data never leaves your browser.
- Base64 Encoder / Decoder — Encode and decode Base64 strings and files. Client-side, safe for sensitive data.
- Timestamp Converter — Convert Unix timestamps, epoch seconds/milliseconds, and ISO 8601 dates.
- Hash Generator — Generate MD5, SHA-1, SHA-256, and SHA-512 hashes client-side.
Related articles
- 4 min readCUID2 — Collision-Resistant IDs Better Than UUID v4CUID2 generates secure, URL-safe, database-friendly IDs with better collision resistance than UUID v4. Learn how CUID2 differs from UUID, nanoid, and ULID, with JavaScript and...
- 4 min readUUID Versions Explained — v1, v3, v4, v5, and v7UUID has multiple versions with different generation strategies. Learn when to use UUID v4 (random), v5 (name-based SHA-1), v7 (time-ordered), and why v1 and v3 are largely...
- 5 min readNanoID vs UUID — Which Unique ID Generator Should You Use?NanoID generates shorter, URL-safe unique IDs using a custom alphabet. UUID v4 is the standard 128-bit identifier. Here's when to use each and how they compare on size, speed,...
- 5 min readULID Generator — Universally Unique Lexicographically Sortable IdentifiersULID is a 26-character sortable unique identifier that embeds a millisecond timestamp prefix. Unlike UUID v4, ULIDs sort chronologically. Here's how ULIDs work and when to use...
- 5 min readUUID Collision Probability — How Likely Are Duplicate UUIDs?UUID v4 has 122 bits of randomness. Collisions are theoretically possible but astronomically unlikely. Here's the math behind UUID uniqueness and when collision risk actually...
- 5 min readUUID Format — Understanding the 128-Bit Unique Identifier StructureUUIDs follow a specific 8-4-4-4-12 hexadecimal format defined by RFC 4122. Here's what each section of a UUID means, the version and variant bits, and how to parse UUID fields.
Pillar
Part of Encoding & Crypto — Base64, URL, JWT, hashes, UUID, QR, password.
Written by Mian Ali Khalid. Last updated 2026-05-12.