What Are UUIDs and When Should You Use Them?

What Is a UUID?

A UUID (Universally Unique Identifier) is a 128-bit number used to identify information in computer systems. It is formatted as 32 hexadecimal digits displayed in five groups separated by hyphens: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx. An example UUID looks like 550e8400-e29b-41d4-a716-446655440000.

The key property of UUIDs is that they can be generated independently on any machine without coordination, and the probability of producing a duplicate is negligibly small. This makes them ideal for distributed systems where multiple servers need to create unique identifiers simultaneously.

UUID Versions

Version 1 combines a timestamp with the MAC address of the generating machine. It guarantees uniqueness but reveals when and where it was created, which may be a privacy concern.

Version 4 uses random or pseudo-random numbers for all significant bits. This is the most commonly used version because it is simple to generate, does not leak information about the source machine, and has an astronomically low collision probability. With 122 random bits, you would need to generate about 2.7 quintillion UUIDs before having a 50% chance of one collision.

Version 5 generates a UUID by hashing a namespace and name using SHA-1. Given the same namespace and name, it always produces the same UUID. This is useful for creating deterministic identifiers from existing data.

Version 7 (newer) combines a Unix timestamp with random data, producing time-sortable UUIDs. This version is gaining popularity because it preserves the benefits of randomness while improving database index performance through chronological ordering.

UUIDs vs. Auto-Increment IDs

Auto-increment IDs (1, 2, 3, …) are simple, compact, and efficient for database indexing. They work well for single-database applications where the database manages the sequence.

UUIDs excel in distributed systems, API-first designs, and scenarios where IDs need to be generated before database insertion. They prevent information leakage (sequential IDs reveal object counts and creation rates) and eliminate conflicts when merging data from multiple sources.

The trade-offs: UUIDs consume more storage (16 bytes vs. 4-8 bytes), produce worse index performance for random versions (inserts into random positions in B-trees), and are less human-friendly. Version 7 UUIDs mitigate the indexing issue by maintaining chronological order.

When to Use UUIDs

Distributed systems: Microservices generating records independently need collision-free IDs without a central authority. UUIDs eliminate the bottleneck of a centralized ID generator.

Public APIs: Exposing sequential IDs in URLs lets users enumerate your resources. UUID-based URLs like /users/550e8400-e29b-41d4-a716-446655440000 prevent this information leakage.

Offline-first applications: Mobile apps and local-first software that sync data later benefit from generating IDs without needing a server connection.

Data merging: When combining datasets from different sources (company mergers, multi-tenant systems), UUIDs prevent key conflicts that sequential IDs would create.

Generating UUIDs

Every major programming language provides UUID generation. JavaScript: crypto.randomUUID(). Python: uuid.uuid4(). Java: UUID.randomUUID(). PHP: Str::uuid() in Laravel or Ramsey/UUID library. Most databases also support UUID generation natively.

Use the UUID generator on CalcHub to create UUIDs instantly, or explore our developer tools for other identifier and encoding utilities.

Generate UUIDs for your projects with CalcHub’s developer tools.

Explore all free tools on CalcHub

Browse Tools