Saved

Utilix knowledge base

What Is a UUID?

Published Apr 17, 2026

A UUID (Universally Unique Identifier) is a 128-bit label used to uniquely identify information in computer systems. It is also known as a GUID (Globally Unique Identifier) in Microsoft contexts.

A UUID looks like this:

550e8400-e29b-41d4-a716-446655440000

It contains 32 hexadecimal digits separated by hyphens in the format 8-4-4-4-12.

Why UUIDs?

When building distributed systems or databases, you need IDs that are unique across many machines without central coordination. Sequential integers require a central counter, which creates a bottleneck. UUIDs can be generated independently on any machine without risk of collision.

UUID Versions

There are multiple UUID versions, each with a different generation strategy. The two most commonly used today are v4 and v7.

UUID v4 (Random)

UUID v4 uses 122 bits of cryptographic randomness. The remaining 6 bits encode the version (4) and variant (RFC 4122).

  • Pros: Completely unpredictable, privacy-preserving, simple to generate
  • Cons: Not sortable — random UUIDs scatter in B-tree indexes, causing poor database performance on large tables

UUID v7 (Time-Ordered)

UUID v7 was introduced in RFC 9562 (2024). It encodes a Unix millisecond timestamp in the first 48 bits, followed by random bits.

  • Pros: Monotonically increasing, excellent database index locality, still globally unique
  • Cons: Leaks timestamp (minor privacy consideration)

Recommendation: Use UUID v7 for database primary keys. Use UUID v4 when you don't want IDs to leak timing information.

The Probability of a Collision

Generating a duplicate UUID v4 requires generating approximately 2.7 quintillion (2.7 × 10¹⁸) UUIDs. In practice, collisions are astronomically unlikely for any reasonable use case.

UUIDs in Code

Most languages have UUID generation built in or in their standard library:

  • JavaScript/Node.js: crypto.randomUUID() (Web Crypto API)
  • Python: import uuid; uuid.uuid4()
  • Java: java.util.UUID.randomUUID()
  • PostgreSQL: gen_random_uuid() or the uuid-ossp extension