Skip to content
Developer GuideGenerators

UUID v4 Explained

Learn how UUID v4 identifiers are structured, how randomness affects collision risk, where UUIDs are useful, and how they compare with sequential IDs.

What is a UUID?

A universally unique identifier is a 128-bit value designed so independently generated identifiers can be used without a central counter. The familiar text form contains 32 hexadecimal digits divided by hyphens into groups of 8-4-4-4-12.

UUID is the standards-oriented name; GUID is a closely related term commonly used in Microsoft ecosystems.

UUID v4 structure

550e8400-e29b-41d4-a716-446655440000

In a version 4 UUID, the first hexadecimal digit of the third group is 4. The first digit of the fourth group identifies the standard variant and is commonly 8, 9, a, or b. The remaining available bits are random.

Randomness and collision risk

UUID v4 provides 122 random bits after reserving version and variant bits. That is a very large space, so accidental duplication is extremely unlikely with a cryptographically secure random generator and ordinary volumes.

“Extremely unlikely” is not the same as impossible. Poor random sources, implementation bugs, copied fixtures, or manual reuse can create duplicates, so storage systems should still enforce uniqueness.

UUID v4 versus auto-increment IDs

  • Distributed generation: UUIDs can be created before a database round trip.
  • Predictability: sequential IDs reveal ordering and approximate counts; random UUIDs are harder to enumerate but are not access-control secrets.
  • Index locality: random values can produce less database index locality than increasing keys.
  • Size: UUID text and 128-bit storage are larger than many integer keys.

Common UUID v4 uses

UUID v4 is useful for request correlation, offline-created records, event identifiers, test fixtures, public object references, and records produced across multiple services. It should not be treated as proof of authorization merely because it is difficult to guess.

Generate a UUID v4

The Orbilyra UUID Generator uses the browser's cryptographically secure UUID capability to generate one or many lowercase, hyphenated version 4 values locally.

If a record also needs a creation time, store an explicit timestamp. The Unix timestamp guide explains how machine-readable time values differ from random identifiers.

FAQ

Frequently asked questions

What is a UUID?

A UUID is a 128-bit identifier represented in a standardized textual form. Different UUID versions generate or derive those bits in different ways.

What makes a UUID version 4?

Version 4 uses random or pseudorandom bits, with fixed version and variant fields that identify the UUID layout.

Can two UUID v4 values collide?

Yes in principle. The random space makes accidental collisions extremely unlikely when UUIDs are generated correctly, but it is not mathematically impossible.

Is UUID v4 ordered by creation time?

No. Random UUID v4 values do not naturally sort by creation time. Use a separate timestamp or an identifier designed for ordering if chronological locality matters.

Should a database still enforce uniqueness?

Yes. A primary key or unique constraint provides a final integrity check even when application-generated collisions are highly unlikely.

← Back to Developer Guides