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.

  • Contains timestamp — sortable by creation time
  • Contains MAC address — privacy concern
  • Good for: distributed systems needing temporal ordering

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.

  • 122 random bits — collision probability is negligible
  • No information about when/where it was generated
  • Good for: most use cases — database IDs, session tokens, API keys

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.

  • Deterministic — same name + namespace = same UUID
  • Good for: converting existing identifiers to UUIDs consistently

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 →
N

Nattapon Tonapan

Developer & creator of FreeUtil. Building free tools for developers and Thai users.

About the author →

RELATED ARTICLES

Dev / IT6 min read

What is JWT? Understanding JSON Web Tokens

Dev / IT5 min read

Base64 Encoding Explained: What It Is and When to Use It

Dev / IT8 min read

CIDR Notation and Subnetting: A Complete Guide

← Back to all articles