Are UUIDs Guaranteed Unique or Secure?
UUIDs are designed to make accidental collisions extremely unlikely when generated correctly, but uniqueness is not an absolute guarantee. A UUID is also an identifier, not proof of authorization or a substitute for a purpose-built secret token.
Generate non-sensitive samples with the UUID Generator, then inspect the version and variant bits. Different-looking values demonstrate fresh generation, not a mathematical proof that no collision can ever occur.
Separate collision resistance from secrecy
| Value | Primary purpose | Security conclusion |
|---|---|---|
| UUIDv4 | Decentralized random identifier | May be hard to guess when correctly generated, but still requires authorization |
| UUIDv7 | Roughly time-ordered identifier | Ordering can improve database locality; timestamp information is visible |
| Name-based UUID | Repeatable identifier for a namespace and name | Deterministic output is not a secret |
| Dedicated random token | Bearer capability or verification challenge | Must include lifecycle, storage, comparison, and expiry controls |
Let the database handle the exceptional collision
id = secure_uuid_v4()
try:
insert_with_unique_primary_key(id, record)
except DuplicateKey:
generate_again_and_retry()
The application uses a suitable generator and treats the unique database constraint as the final authority. It does not run an unreliable check-then-insert race or assume a collision is logically impossible.
Uniqueness depends on the version and generator
UUID is a family of formats, not one generation algorithm. Version 4 uses random or pseudorandom bits; version 7 combines a Unix-epoch timestamp with random bits for time-ordered allocation; name-based versions derive a value from a namespace and name. Correct generation, suitable randomness, and the UUID version therefore matter more than the familiar hyphenated appearance.
A UUIDv4 has fixed version and variant fields, leaving 122 variable bits. That creates a very large space, so collisions are ordinarily unlikely at practical scales when a cryptographically strong random source is used. Unlikely is not impossible. Storage systems should still enforce a unique key and retry generation if an insertion reports a collision.
Identifier, capability, and authorization are different jobs
An identifier answers which record is being referenced. Authorization answers whether this requester may act on that record. Hiding an object behind an unguessable-looking UUID can reduce casual enumeration, but an application must still authenticate the requester and enforce object-level access checks on every operation.
Do not assume every UUID is unpredictable. Time-based, name-based, weakly generated, copied, logged, or leaked values can reveal structure or become known. For password resets, API credentials, session identifiers, and other bearer capabilities, use a reviewed security-token design with sufficient entropy, expiration, revocation, secure storage, and transport controls.
Validate how an identifier is generated and exposed
Choose the UUID version for the system requirement: random allocation, time ordering, or deterministic naming.
Use an operating-system or platform cryptographic random source where the selected version requires randomness.
Enforce uniqueness in the database and make collision retry behavior explicit.
Apply authentication and per-object authorization even when record identifiers appear unguessable.
Security claims a UUID cannot satisfy
- Do not label a UUID as encrypted; the fields and textual representation are standardized and normally visible.
- Do not use a predictable or name-based UUID as a password-reset token or API secret.
- Do not remove database uniqueness constraints because collision probability is small.
UUID uniqueness and security questions
Can two UUIDv4 values ever be the same?
Yes in principle. Correct random generation makes a collision very unlikely, while a unique constraint detects the exceptional case reliably.
Is a UUID safe to expose in a URL?
Exposure depends on the data and product design. A public identifier can appear in logs and shares; it must never replace authentication, authorization, or redaction decisions.
Verify with the right tool and context
Use the UUID Generator only with safe test data. Continue through the developer fundamentals collection.
Specifications and security guidance
RFC 9562: Universally Unique IDentifiers
Defines current UUID formats, versions, generation considerations, and security guidance.
NIST SP 800-90A Rev. 1
Specifies deterministic random bit generators based on hash functions and block ciphers.