Skip to main content
Home/Blog/UUID Security and Privacy: Are Generated UUIDs Truly Random?
Developer Tools

UUID Security and Privacy: Are Generated UUIDs Truly Random?

Learn about UUID generation security, privacy implications of different versions, and whether UUIDs are safe for security-sensitive applications like session tokens.

By Inventive HQ Team•
UUID Security and Privacy: Are Generated UUIDs Truly Random?

Are generated UUIDs truly random? A properly generated UUIDv4 is cryptographically unpredictable — 122 of its 128 bits come from a random source, giving about 5.3 x 10^36 possible values — but only if it was generated by a cryptographically secure RNG such as crypto.randomUUID(). A UUID built on JavaScript's Math.random() is unsuitable as a secret, and other versions may leak data: v1 and v6 contain a timestamp and may include a machine MAC address, while v7 embeds a creation timestamp. So "UUID" is not one security property — it is at least six, ranging from cryptographically strong to actively identifying.

That is the summary an AI Overview will give you. Here is what it can't show you: which specific versions leak what, how a real virus author got caught by his own UUID, and a live generator you can inspect byte by byte. Generate a few UUIDs below and watch which fields stay constant across them — those constant bytes are exactly the metadata that can identify you.

GUID & UUID Generator

Generate GUIDs and UUIDs (v1, v4, v7) instantly. Bulk generation, format options, and copy to clipboard. Free online tool.

Open the full GUID & UUID Generator tool →
Loading interactive tool...

The six UUID versions, ranked by security and privacy

The UUID format is defined by RFC 9562 (published May 2024, replacing the older RFC 4122). All versions are 128 bits, formatted as xxxxxxxx-xxxx-Mxxx-Nxxx-xxxxxxxxxxxx, where M marks the version and N marks the variant. What differs is where the other 122 bits come from — and that difference is the entire security and privacy story.

VersionHow it's builtRandom bitsLeaksGuessable?Use it for
v148-bit node field + 60-bit timestamp + clock seqVariableCreation time; possibly MAC addressPartly (time is sequential)Legacy systems only; avoid
v3MD5 hash of namespace + name0The input, if input space is smallYes, if input is knownDeterministic IDs, never secrets
v4Random122NothingNo (with a CSPRNG)General IDs, tokens, keys
v5SHA-1 hash of namespace + name0The input, if input space is smallYes, if input is knownDeterministic IDs, never secrets
v6Reordered v1 (time-sortable)VariableCreation time; possibly MAC addressPartlyTime-sortable legacy migration
v748-bit Unix ms timestamp + generator-defined tailVariableCreation timestampDepends on generator entropyDB primary keys, sortable IDs
Which should I use?————v4 for anonymous random IDs; v7 for sortable DB keys; never v1/v6 for anything sensitive

The takeaway: a CSPRNG-generated v4 is suitable when unpredictability matters; v7 entropy depends on its generator. v3 and v5 are hashes with zero randomness — same input always yields the same UUID, so they are useful for deduplication but must never be treated as secret. v1 and v6 carry a timestamp and may expose a MAC address in their node field.

Anatomy of a UUIDv4: which bytes are random, which are fixed

A common misconception is that all 128 bits of a v4 UUID are random. Six of them are not: four bits are pinned to the version (4) and two bits are pinned to the variant (10). Those fixed bits are why every v4 UUID has a 4 at the start of the third group and one of 8, 9, a, or b at the start of the fourth.

Anatomy of a UUIDv4 showing 122 random bits and 6 fixed bits A UUIDv4 layout: the version nibble is fixed to 4, the variant bits are fixed to 8-b, and the remaining 122 bits are random with 5.3 x 10 to the 36 possible values. UUIDv4: 128 bits = 122 random + 6 fixed 3f9a7c1e-b204-4e8d-a1f2-6b3c9d0e5a71 Version nibble fixed to "4" (4 bits) Variant bits fixed to 8/9/a/b (2 bits) 122 random bits 5.3 x 10^36 values

Those 122 random bits are what make a v4 UUID unguessable — but only when they are drawn from a cryptographically secure source. That single dependency is where most real-world UUID vulnerabilities live.

The one thing that actually breaks UUID security: the RNG

The version tells you how many bits are supposed to be random. Whether they are random depends entirely on the underlying random number generator. This is the failure mode that turns a "secure" v4 into a predictable token.

  • Math.random() is not cryptographic. Its algorithm varies by runtime and is not guaranteed to resist prediction. A UUIDv4 assembled from Math.random() bytes must not be used as a secret token.
  • Use the platform CSPRNG. In modern environments call crypto.randomUUID() (Node 16.7+, all current browsers, Deno, Bun). It draws from the OS cryptographically secure RNG and returns a compliant v4 in one line. For raw bytes, use crypto.getRandomValues() (browser) or crypto.randomBytes() (Node).
  • Old libraries and forks are the risk. Some legacy uuid polyfills, homegrown implementations, and copied Stack Overflow snippets fall back to Math.random() when no crypto API is found. That fallback is silent — the UUID still looks perfectly formatted.

If you generate a UUID and hand it out as a password-reset link, an unguessable value is the whole point. A predictable RNG quietly removes that guarantee while leaving the output looking identical.

The privacy leak: how a UUID caught a virus author

In 1999 the Melissa macro virus spread through infected Word documents. Microsoft Office at the time embedded a UUIDv1-style GUID in document metadata — and UUIDv1 encodes the network card's MAC address directly in its final 48 bits. Investigators extracted the MAC address from documents linked to the virus, matched it to hardware, and identified the author. The embedded identifier helped investigators trace the document.

That is the concrete privacy cost of a time-and-MAC UUID. The lesson generalizes:

What each UUID version reveals about its origin UUIDv1 and v6 reveal a timestamp and may expose a MAC address; v7 reveals a timestamp; v4 reveals no embedded metadata. What a single UUID reveals about where it came from v1 / v6 possible MAC creation time may identify device v7 creation time (48-bit ms) orderable v3 / v5 the hashed input (if guessable) deterministic v4 nothing 122 random bits anonymous

If a UUID will ever appear in a document, a URL, a public API response, or a data export, prefer v4 (leaks nothing) or, where sortability matters, v7 (reveals a timestamp). Reserve v1 and v6 for internal systems that specifically need the node/time fields and where possible MAC-address exposure is understood and acceptable.

Identifier versus secret: the distinction that trips teams up

The single most common UUID mistake is conflating two different jobs:

  • An identifier must be unique. It is not required to be secret, and in practice it is not — UUIDs show up in URLs, logs, referrer headers, error messages, and analytics. Any version satisfies "unique."
  • A secret must be unguessable and confidential. A v4 from a CSPRNG is unguessable, and confidentiality is your job: don't log it, don't leak it via Referer, expire it.

Problems appear when a team uses a UUID as a capability — "if you know the URL, you're authorized" — without checking which version it is. A predictable v1 or a deterministic v5 used as a password-reset token is a real vulnerability, because the value can be reconstructed rather than guessed. A v4 from crypto.randomUUID() can safely double as a secret, provided you also treat it like one: short expiry, single use, never written to logs. For genuinely long-lived secrets, a dedicated 256-bit random token is cleaner than borrowing a UUID for the role.

Practical recommendations

  1. Default to v4 for anonymous identifiers and any value that might be exposed. It leaks nothing and is unguessable with a proper RNG.
  2. Use v7 for database primary keys when you want time-sortable, index-friendly IDs — but remember the embedded timestamp is readable by anyone who holds the ID.
  3. Never assemble UUIDs from Math.random(). Call crypto.randomUUID() or crypto.getRandomValues(). Audit old dependencies for silent Math.random() fallbacks.
  4. Avoid v1 and v6 in anything user-facing; they reveal creation time and may expose a MAC address.
  5. Treat v3/v5 as public. They are deterministic hashes — useful for dedup, useless as secrets.
  6. If a UUID grants access, treat it as a secret: CSPRNG source, expiry, single use, and keep it out of logs and referrer headers.

Generate and inspect a few versions with the tool above, or read our v1 / v4 / v5 version comparison for a deeper field-by-field breakdown. All generation in our tool happens client-side via the browser's native crypto API, so no value is ever transmitted to a server.

Building Something Great?

Our development team builds secure, scalable applications. From APIs to full platforms, we turn your ideas into production-ready software.