UUID v4 Explained: How Random UUIDs Work

When developers say "I need a UUID", they are almost always referring to UUID Version 4. While there are several versions of the UUID standard (such as Version 1 based on MAC address and time), Version 4 is the most popular because it relies purely on random numbers.

How It Works

A UUID v4 is essentially a massive randomly generated number, with a few bits reserved to indicate its version and variant.

Specifically, out of the 128 bits:

  • 4 bits indicate the version (which will be set to 4).
  • 2 or 3 bits indicate the variant (which specifies the layout format).
  • 122 bits are completely random.

Cryptographic Security

For a UUID v4 to be safe from collisions, it must be generated using a cryptographically secure random number generator (CSPRNG). If a system uses a weak pseudo-random number generator (like Math.random() in JavaScript), the identifiers become predictable, and the risk of generating a duplicate increases dramatically.

Modern browsers provide a built-in API called crypto.randomUUID() that handles this securely, ensuring excellent entropy (randomness quality).

The Probability of Collisions

Because there are 122 random bits, the total number of possible UUID v4 values is 2122, which is roughly 5.3 x 1036. This number is astronomically large. If you were to generate 1 billion UUIDs every single second, it would take approximately 85 years for there to be a 50% chance of a single duplicate collision.


Generate a Secure UUID v4

You can generate up to 1,000 secure, random UUID v4 values instantly using our UUID Generator tool.