Key takeaways
- A UUID is 128 bits rendered as 32 hex digits in five groups. The first digit of the third group is the version; the first digit of the fourth group is the variant, which is 8, 9, a or b for every modern UUID.
- Version 4 carries 122 random bits. Version 7 carries 74 random bits plus a 48-bit millisecond timestamp. Version 1 carries a 60-bit timestamp, a 14-bit clock sequence and a 48-bit node.
- Use v4 for anything a user or client can see, because it reveals nothing about creation order or rate. Use v7 for internal database primary keys, because its timestamp prefix makes inserts append instead of splitting index pages.
- One billion v4 UUIDs in total gives a collision probability near 9 x 10^-20. Even odds need about 2.7 x 10^18 values, roughly 86 years at a billion per second.
- UUID and GUID are the same 128-bit identifier. UUID is the RFC term; GUID is Microsoft's name for it. Case and hyphenation are presentation, not value.
- Store UUIDs as a native uuid type or BINARY(16), not as a 36-character string. The string form costs more than twice the space in every index that touches it.
The Layout: 128 Bits, Five Groups, Two Diagnostic Digits
Every UUID renders the same way: 8-4-4-4-12 hexadecimal digits, 32 in total, with four hyphens. The hyphens carry no information. They exist so a human can compare two values by eye without losing their place, and every serious parser strips them before doing anything else.
Two of those digits are diagnostic. The first digit of the third group is the version, which tells you the minting strategy: 1 for timestamp-and-node, 3 and 5 for name-based hashes, 4 for random, 6 for reordered v1, 7 for Unix-time-plus-random. The first digit of the fourth group is the variant, and for anything following RFC 4122 or RFC 9562 it is 8, 9, a or b — binary 10xx. Those two bits are reserved, which is why the random bit counts below are 122 and 74 rather than 124 and 76.
The UUID generator reads both digits for you. Paste any value into its inspector and it reports validity, version, variant and whether the value is NIL, without transmitting anything. That is the fastest way to settle an argument about what a legacy system is actually emitting: the version digit does not lie, even when the documentation does.
One subtlety worth knowing before you trust an inspector: the all-f value ffffffff-ffff-ffff-ffff-ffffffffffff is a reserved sentinel in the RFC, and its variant digit is f, which is outside the 8-b range. A strict validator rejects it. That is correct behaviour, not a bug — it is a different reserved value from NIL, and it is not a usable identifier.
Version 4: 122 Random Bits and Nothing Else
Version 4 is the default for a reason. It has no timestamp, no node, no namespace and no input — just 122 bits from a cryptographic random source, with the version and variant nibbles stamped into place. Nothing about the value reveals when it was made, where it was made, or what it was made from.
The implementation matters more than the version number. crypto.randomUUID() is native in every modern browser and returns a v4 UUID directly. Where it is unavailable, the fallback fills 16 bytes with crypto.getRandomValues, then sets bytes[6] = (bytes[6] & 0x0f) | 0x40 for the version and bytes[8] = (bytes[8] & 0x3f) | 0x80 for the variant. Both paths draw from the operating system's CSPRNG.
What is never acceptable is Math.random(). It is a fast deterministic PRNG seeded from a small internal state, it is not cryptographically secure, and its output can be predicted from a handful of samples. An identifier generator built on it produces values that look unique and are not safe. If a tool cannot tell you which source it uses, assume the worst.
The collision arithmetic is a birthday problem, and it is routinely quoted wrong. With 122 random bits there are 2^122, about 5.3 x 10^36, possible values. The probability of at least one collision after generating n values is approximately 1 - exp(-n^2 / (2 x 2^122)). Plugging in real numbers: one million UUIDs gives about 9.4 x 10^-26; one billion gives about 9.4 x 10^-20; one trillion gives about 9.4 x 10^-14. Even odds — a 50% chance of a duplicate — require roughly 2.7 x 10^18 values, which is about 86 years of continuous generation at one billion per second.
So the popular reassurance that you can generate a billion per second for a century safely is false by about eighteen orders of magnitude. At that rate you would produce 3.2 x 10^18 values and the collision probability would be around 61%. The honest statement is narrower and still completely reassuring: at any rate a real system sustains, a v4 collision is far less likely than the hardware silently corrupting the value. When duplicates do appear, the cause is a broken or reseeded random source, not arithmetic.
Version 7: A Timestamp Prefix That Makes Indexes Append
Version 7, standardised in RFC 9562, spends the first 48 bits on a big-endian Unix millisecond timestamp and leaves 74 bits random. Because the timestamp is the most significant part of the value and is written most-significant-byte-first, the hexadecimal string sorts in creation order. That single property is the entire reason v7 exists.
The database consequence is concrete. A B-tree index keeps keys in sorted order on pages. Insert a random v4 key and it lands at an arbitrary position, which splits a full page, moves half its contents, and leaves both pages half-empty. Insert millions of them and the index bloats, cache locality collapses, and write latency climbs. Insert a v7 key and it is greater than every existing key, so it appends to the rightmost leaf — the same write pattern as an auto-increment integer, but globally unique without coordination.
You can verify the ordering property directly. Generate a batch of v7 values a second apart and sort them as strings: the lexicographic order matches the chronological order exactly. Values minted inside the same millisecond share their first 13 characters and differ only in the random tail, so they are not strictly ordered within that millisecond — which is fine, because nothing needs them to be.
The 74 random bits are per-millisecond, not global, and that changes how you should read the collision risk. Within a single millisecond there are 2^74, about 1.9 x 10^22, possible tails. A thousand values in the same millisecond gives about 2.6 x 10^-17; a million gives about 2.6 x 10^-11; a billion in one millisecond gives about 2.6 x 10^-5. No real workload puts a billion identifiers into one millisecond, so v7 is safe — but the guarantee is per-tick, and it is worth stating that way rather than borrowing v4's number.
The trade is privacy. A v7 identifier tells anyone holding it approximately when the record was created, and a collection of them reveals creation rate. For an internal primary key that never leaves your systems, that is irrelevant. For a public URL, an API key or a filename in an open bucket, it is an information leak — use v4 there. The NanoID generator is the other option for public tokens: shorter, URL-safe, and with no embedded time at all.
Version 1: Gregorian Time, and a Node That Is Not a MAC Address
Version 1 is the original 1980s design from the Apollo NCS work that became RFC 4122. It combines a 60-bit timestamp, a 14-bit clock sequence and a 48-bit node. The timestamp is not Unix time: it counts 100-nanosecond intervals from 15 October 1582, the start of the Gregorian calendar. Converting to Unix milliseconds means subtracting 122192928000000000 intervals and dividing by 10000.
That offset is the reason v1 timestamps look absurd when read naively, and the reason the timestamp converter is a separate tool rather than a mental calculation. The generator here embeds the timestamp and the inspector decodes it back, so you can confirm the round trip: mint a v1 for a known instant, paste it into the inspector, and read the same instant back as an ISO string.
The node field is where the privacy problem lives. Classically it is the machine's MAC address, which means a v1 UUID permanently identifies the hardware that created it. That was a reasonable trade on a closed network in 1985 and is a bad one on the public internet now. RFC 4122 section 4.5 provides the escape: when no MAC address is available, a random 48-bit node may be used with the multicast bit set to mark it as random.
That is what this generator does. The node is drawn from the CSPRNG and its low bit is forced to 1, so the value is honestly labelled as a random node rather than pretending to be hardware identity. The result keeps v1's structure and timestamp while leaking nothing about the machine. The random budget is 14 clock-sequence bits plus 47 node bits — 61 in total, since one node bit is spent on the multicast flag.
Version 1 also has an ordering quirk worth knowing: its timestamp fields are stored least-significant-first, so v1 UUIDs do not sort chronologically as strings. Version 6 exists purely to fix that, rearranging the same fields so the timestamp sorts first. If you are migrating a legacy v1 system and want index locality without changing the timestamp semantics, v6 is the compatibility bridge; if you are designing something new, v7 is simpler and does not carry the Gregorian epoch at all.
NIL, Name-Based Versions, and What This Tool Does Not Generate
NIL is 00000000-0000-0000-0000-000000000000. It is not random and not unique — it is a sentinel meaning "no identifier", used as a column default, a null-object placeholder, and a test fixture for null handling. Generating a batch of NIL values produces the same string every time, which is correct. Its entropy is zero bits, and any tool that reports otherwise is mislabelling a constant as a random draw.
Versions 3 and 5 are name-based and deterministic: hash a namespace UUID together with a name and you get the same identifier every time. v3 uses MD5, v5 uses SHA-1, and v5 is preferred because MD5's collision weaknesses are worse. These are the right choice when you need a stable identifier derived from something that already has a name — a URL, an email address, a DNS domain — and you want two independent systems to derive the same value without talking to each other. The hash generator computes the underlying digests, though a name-based UUID also needs the namespace bytes and the version/variant stamping, which is a separate construction.
Being clear about scope is more useful than implying coverage. This generator produces v4, v7, v1 and NIL, and it inspects any version including v3, v5 and v6. It does not mint name-based v3 or v5 values, because those require a namespace input and a different construction. If you need those, use a library that implements RFC 9562 name-based generation rather than assuming a random generator can be pointed at a string.
Storage and Formatting: Where the Bytes Actually Cost You
The canonical string is 36 characters. The value is 16 bytes. Storing the string in a VARCHAR(36) column therefore costs more than twice the space, and every index over that column carries the same penalty — wider keys mean fewer entries per page, more pages, more I/O. PostgreSQL's native uuid type and MySQL's BINARY(16) both store the compact form. SQL Server's uniqueidentifier is 16 bytes as well, though its default string rendering and its non-standard sort order have surprised people migrating from other engines.
MySQL has no native uuid type, so the usual pattern is BINARY(16) with UUID_TO_BIN() and BIN_TO_UUID(). Since MySQL 8.0, UUID_TO_BIN(uuid, 1) swaps the time-low and time-high parts of a v1 value to make it sort — a manual version of what v7 does by design. If you are starting fresh, generating v7 and storing BINARY(16) avoids the swap entirely.
Formatting is presentation and nothing more. Uppercase, lowercase, hyphenated, plain 32-character hex, and brace-wrapped {...} all denote the same 128 bits. Comparison is case-insensitive at the byte level, so a system that stores uppercase and a system that emits lowercase interoperate fine. The generator offers all five forms, plus a quoted comma-separated list ready for a WHERE id IN (...) clause, which is the format people actually need when seeding fixtures or writing a migration.
Two cautions on the plain-hex form. First, some legacy systems and some binary GUID renderings are byte-swapped relative to the canonical string, so a 32-character hex value copied from a debugger may not match the same identifier rendered canonically. Second, dropping hyphens makes the value harder to compare by eye and easier to truncate silently in a fixed-width column. Use it when a target system requires it, not as a default.
Choosing a Version: The Decision That Actually Matters
Most UUID arguments are about the wrong question. The version number matters far less than whether the identifier is public or internal, and whether it is a primary key or just a value.
For a public identifier — anything in a URL, an API response, a filename, a token a client holds — choose v4 or NanoID. The requirement is that the value reveals nothing: not creation time, not creation rate, not sequence position, not hardware. An auto-increment integer fails this badly, because it tells an observer exactly how many records exist and how fast they are being created. v7 fails it more subtly, because the timestamp prefix is readable by anyone who knows the layout.
For an internal primary key, choose v7. You keep the distributed-generation property that made UUIDs attractive — any node can mint an identifier with no round trip, no lock and no coordination — while recovering the append-only write pattern of a sequential key. This is the combination that auto-increment cannot offer and v4 cannot offer either.
For a value derived from an existing name, choose v5 with a fixed namespace. Determinism is the point: two systems that never communicate derive the same identifier from the same input.
And for a secret, choose none of these. A UUID is unique, not unpredictable in the sense a credential needs, and it is formatted for storage rather than for entropy per character. The password generator exists for that job, and the random number generator exists for draws and seeds. The distinction is worth internalising: uniqueness, unpredictability and fairness are three different properties, and a tool built for one is usually wrong for the others. The generators guide works through the entropy arithmetic behind that separation.
One last production rule that no generator can enforce for you: identifiers supplied by a client are inputs, not facts. Generate them server-side, or validate and re-key them on arrival. A browser-side generator is the right place to mint fixtures, seed data and migration keys — it is not a substitute for your application owning its own identifier space.
Frequently asked questions
The questions people ask most about uuid versions: v1, v4, v7 and nil explained, answered directly.