What is a UUID?

UUID stands for Universally Unique Identifier. It is a 128-bit value that is guaranteed (with overwhelming statistical probability) to be unique across all space and time.

A UUID is usually written as 32 hexadecimal digits in five groups: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx (8-4-4-4-12 format). For example:

550e8400-e29b-41d4-a716-446655440000

The problem with auto-increment IDs

Most databases use auto-incrementing integers as primary keys: 1, 2, 3, and so on. This works fine for small applications, but it breaks down in modern systems for three reasons:

1. Distributed systems

If you have multiple database servers, you cannot easily coordinate auto-increment. Server A and Server B might both generate ID 1. UUIDs solve this - each server generates IDs independently with zero coordination.

2. Security

If your URL contains /users/42, anyone can guess that /users/43 exists. They can enumerate your entire user base with a simple script. With UUIDs (/users/550e8400-e29b-...), this is impossible.

3. Client-side generation

Sometimes you need to generate an ID before saving to the database (offline apps, optimistic UIs). With UUIDs, the client can create an ID that is guaranteed to be unique without asking the server.

UUID versions: v1, v4, v5

There are several UUID versions. The three most common are v1, v4, and v5.

UUID v1 - Time-based

Uses the current timestamp plus a MAC address. It is sort of "unique by time". The downside: it leaks your MAC address, which is a privacy concern. Avoid v1 unless you have a specific reason.

UUID v4 - Random (recommended)

Generates 122 random bits. There is no way to predict them, no information leak, and no coordination needed. This is the most common version, used by databases, APIs, and distributed systems everywhere.

💡 Why v4 is the default choice

v4 UUIDs are generated from crypto.getRandomValues() - the same cryptographic source used by banks. The chance of a collision is roughly 1 in 2^122. You will not be the unlucky one.

UUID v5 - Name-based (deterministic)

Uses SHA-1 hashing of a namespace + name. Same input always produces the same UUID. Useful for generating stable IDs from URLs, emails, or file paths. If you generate a v5 UUID for example.com today and again in 5 years, you will get the same UUID.

When to use UUIDs

Use UUIDs when:

  • You have a distributed system with multiple database servers.
  • You need to generate IDs on the client (before saving to DB).
  • You need to hide the total count or sequence of records.
  • You need to merge data from multiple sources safely.
  • You are building a public API where sequential IDs are a security issue.

Use auto-increment integers when:

  • You have a single database server.
  • You need maximum performance and minimum storage.
  • You do not care about sequence exposure.
  • Your application is small and simple.

🆔 Try the Free UUID Generator

Generate v1, v4, and v5 UUIDs instantly. No signup, works offline.

Open UUID Generator →

How to generate UUIDs

Every major programming language has built-in UUID support:

  • JavaScript/Node: crypto.randomUUID()
  • Python: import uuid; uuid.uuid4()
  • Go: github.com/google/uuid
  • PHP: Ramsey\Uuid\Uuid::uuid4()
  • Rust: uuid::Uuid::new_v4()

For quick manual generation, use our UUID Generator - it supports v1, v4, and v5, and can generate up to 1,000 UUIDs at once.

Frequently asked questions

What does UUID stand for?

UUID stands for Universally Unique Identifier. It is a 128-bit number represented as 32 hexadecimal digits, usually written in five groups separated by hyphens (8-4-4-4-12).

Which UUID version should I use?

For most use cases, use v4 (random). It is the most common version, safe for privacy, and supported everywhere. Use v5 if you need deterministic IDs. Avoid v1 unless you have a specific reason.

Are UUIDs really unique?

For v4 UUIDs, the probability of generating two identical UUIDs is roughly 1 in 2^122. To put that in perspective: you would need to generate a billion UUIDs per second for about 85 years before the chance of a single collision becomes significant.

UUID vs auto-increment integer: which is better?

It depends. Auto-increment integers are smaller, faster for indexing, and easier to read. UUIDs are better for distributed systems, client-side generation, or hiding sequential IDs publicly.

Do UUIDs slow down databases?

Slightly. Random UUIDs (v4) cause index fragmentation. For high-scale systems, consider UUID v7 (time-ordered) or storing UUIDs as binary (16 bytes) instead of strings.

Final thoughts

UUIDs are an elegant solution to a real problem: how do you generate unique IDs across distributed systems without coordination? For most modern applications, UUID v4 is the right choice.

If you need to generate UUIDs quickly, try our free UUID generator. It supports all major versions, works offline, and can generate up to 1,000 UUIDs at once.