Definition
Entropy in the context of UUIDs refers to the number of unpredictable bits in the identifier — the bits whose values come from a random source rather than from a fixed algorithm, timestamp, or deterministic computation.
Higher entropy means:
- Lower collision probability — more possible values, less chance two generators produce the same UUID
- Higher unpredictability — harder for an attacker to guess or enumerate valid UUIDs
How many bits of entropy does a UUID have?
The answer depends on the version:
| Version | Total bits | Entropy bits | Source |
|---|---|---|---|
| v1 | 128 | ~62 | Timestamp + MAC address (mostly deterministic) |
| v3 | 128 | 0 | MD5 hash of namespace + name (fully deterministic) |
| v4 | 128 | 122 | CSPRNG — 6 bits used for version/variant |
| v5 | 128 | 0 | SHA-1 hash of namespace + name (fully deterministic) |
| v7 | 128 | 74 | 48-bit timestamp + CSPRNG for remainder |
UUID v4 is the highest-entropy version. UUID v7 trades 48 bits of timestamp for 74 bits of randomness — still far more than enough for collision safety, though slightly more predictable than v4.
Where UUID randomness comes from
UUID libraries use a Cryptographically Secure Pseudo-Random Number Generator (CSPRNG), which sources entropy from the operating system’s kernel entropy pool. The kernel accumulates randomness from hardware events (disk I/O timing, interrupt timing, hardware RNG chips on modern CPUs).
| Platform | CSPRNG API |
|---|---|
| Browser | crypto.getRandomValues() |
| Node.js | crypto.randomFillSync() / crypto.randomUUID() |
| Python | os.urandom() (used internally by uuid.uuid4()) |
| Go | crypto/rand.Read() |
| Java | SecureRandom |
| .NET | RandomNumberGenerator |
Never use Math.random() or equivalent for UUID generation. Math.random() is a non-cryptographic PRNG with only ~52 bits of state, meaning it can be seeded and predicted.
Entropy vs security
High entropy makes UUIDs unpredictable, but a UUID is not a secret. Even with 122 bits of randomness, a UUID v4 should not be used as a password, session token, or API key on its own because:
- UUIDs are frequently logged, included in URLs, and appear in referrer headers
- A UUID visible in a URL is visible to every system that logs HTTP requests
- Tokens need not just unpredictability but also secrecy — they must be transmitted only over encrypted channels and stored securely
For secrets, generate a purpose-built random token (e.g., 32 bytes from crypto.getRandomValues(), encoded as Base64 or hex) and protect it like a password.
Entropy and UUID v7 timestamp
UUID v7 embeds a 48-bit Unix millisecond timestamp in the most significant bits. This means:
- The timestamp bits are not random — anyone who knows a v7 UUID was generated at a given time can narrow down its value
- The remaining 74 bits are still random
- For database keys (the primary use case for v7), this predictability is acceptable — the timestamp is not a secret
- For externally visible identifiers where creation time is sensitive, use v4
Checking entropy quality
You can verify your UUID library uses a CSPRNG by checking its source code or documentation. All well-maintained UUID libraries (the uuid npm package, Python’s uuid module, Go’s google/uuid, .NET’s Guid.NewGuid()) use OS-level CSPRNG APIs.
A sign of a low-quality UUID library: it uses Math.random(), rand(), or any language’s default non-secure random function.
Related terms
- Collision — why high entropy makes UUID collisions negligible
- UUID — the full identifier definition and format
- Variant — the 2-bit field that is not part of the random payload
Generate high-entropy UUIDs with the UUID v4 generator or UUID v7 generator.
Frequently asked questions
Where does UUID randomness come from?
UUID v4 and the random bits in v7 come from a Cryptographically Secure Pseudo-Random Number Generator (CSPRNG) — crypto.getRandomValues() in browsers and Node.js, os.urandom() in Python, crypto/rand in Go. Never use Math.random() or equivalent for UUID generation.
Are these UUIDs cryptographically secure?
The randomness is, yes — it comes from the Web Crypto API. That said, a UUID is an identifier, not a secret; don't use one as a password or an unguessable capability token on its own.