Dev / IT5 min read

UUID Explained: v1, v4, v5 and When to Use Each

Everything you need to know about UUIDs — the difference between v1, v4, and v5, how they are generated, and best practices for using them in databases and APIs.

What is a UUID?

A UUID (Universally Unique Identifier), also called a GUID (Globally Unique Identifier), is a 128-bit label used to uniquely identify information. UUIDs are formatted as 32 hexadecimal digits in five groups separated by hyphens: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx.

550e8400-e29b-41d4-a716-446655440000

UUID Versions

UUID v1 — Time-based

UUID v1 is generated from the current timestamp and the MAC address of the generating machine. It is sortable chronologically but reveals information about when and where it was generated.

UUID v4 — Random

UUID v4 is generated from random or pseudo-random numbers. It is the most widely used version due to its simplicity and privacy properties.

UUID v5 — Name-based (SHA-1)

UUID v5 generates a deterministic UUID from a namespace UUID and a name using SHA-1 hashing. The same inputs always produce the same UUID.

Comparison

v1v4v5
SourceTimestamp + MACRandomName + Namespace
SortableYesNoNo
DeterministicNoNoYes
PrivacyLow (leaks MAC)HighMedium
Most commonNoYes ✅Sometimes

UUID in Databases

UUIDs are popular as database primary keys, especially in distributed systems where auto-increment IDs would conflict across multiple database nodes.

-- PostgreSQL
CREATE TABLE users (
  id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
  name VARCHAR(100)
);

💡 For database performance, consider UUID v7 (time-ordered random UUID) which is sortable like v1 but uses random data instead of MAC address. It provides better index performance in most databases.

TRY THE FREE TOOL

UUID Generator

Generate UUID v1, v4, and v5 instantly

Open Tool →
← Back to all articles