ToolStackToolStack
Browse Tools →
Home/Blog/What Is a UUID
EngineeringMay 11, 2026 · 5 min read

What Is a UUID? Format, Versions & When to Use One

JP

Justin Pirrie

Founder, ToolStack · May 11, 2026

TL;DR

  • → UUID is a 128-bit identifier formatted as 8-4-4-4-12 hex characters.
  • → Version 4 (random) is the right choice for most use cases.
  • → Generate one instantly with the free UUID Generator.
Sponsored

Advertisement Space

You've seen them in URLs, database columns, and API responses: 550e8400-e29b-41d4-a716-446655440000. That's a UUID — a 128-bit identifier designed to be unique across every system in the world without any central coordination.

Here's exactly what they are, why they look the way they do, and when to use them.

UUID Format

A UUID has 32 hexadecimal digits arranged in five groups separated by hyphens:

xxxxxxxx-xxxx-Mxxx-Nxxx-xxxxxxxxxxxx
  • 8 hex digits32 bits — time_low in v1, random in v4
  • 4 hex digits16 bits — time_mid in v1, random in v4
  • 4 hex digits (M = version)M indicates the version: 1, 2, 3, 4, or 5
  • 4 hex digits (N = variant)N is 8, 9, a, or b for RFC 4122 UUIDs
  • 12 hex digits48 bits — node/MAC in v1, random in v4

UUID Versions Explained

v1Timestamp + MAC address

Generated from the current time and your machine's MAC address. Guaranteed unique even across machines — but leaks your hardware identity and generates sequential IDs that expose insert order.

v2DCE Security

A variant of v1 used for DCE RPC. Rarely encountered in modern applications. You almost certainly don't need this.

v3Namespace + Name (MD5)

Deterministic — the same namespace and name always produce the same UUID. Uses MD5 hashing. Use this when you need the same logical entity to always have the same ID (e.g., a URL → UUID mapping).

v4Random (use this one)

122 bits of cryptographic randomness. No embedded metadata. Not sequential, not guessable. The right default for database primary keys, session tokens, and any use case where you need a unique opaque ID.

v5Namespace + Name (SHA-1)

Like v3 but uses SHA-1 instead of MD5. Prefer v5 over v3 when you need the namespace+name determinism pattern — SHA-1 is stronger than MD5, even for non-cryptographic purposes.

UUID vs Auto-Increment: Which Should You Use?

FactorUUID v4Auto-increment
Global uniquenessYes — no coordination neededOnly within one database
Reveals record countNo — opaque random IDYes — IDs are sequential
GuessableNoYes
Multi-database safeYesRequires coordination
B-tree index performanceLower — random inserts cause page splitsHigher — sequential inserts
Can generate before insertYesNo — need a DB round-trip
Human readabilityLowHigh (1, 2, 3…)

For distributed systems, APIs, and anything exposed in URLs, UUID v4 is the default. For a simple single-database CRUD app with no external exposure, auto-increment is simpler and performs better.

How to Generate a UUID

Code examples for the most common languages:

Node.js 14.17+
import { randomUUID } from 'node:crypto'; const id = randomUUID();
Python
import uuid id = str(uuid.uuid4())
Go
import "github.com/google/uuid" id := uuid.New().String()
PostgreSQL
SELECT gen_random_uuid();
PHP 8.1+
$id = (string) Str::uuid(); // Laravel // or: $id = vsprintf('%s%s-%s-%04x-%04x-%s%s%s', str_split(bin2hex(random_bytes(16)), 4));

Or skip the code entirely — the ToolStack UUID Generator generates one or a hundred v4 UUIDs instantly in your browser. Useful for test data, seed scripts, or any time you need IDs right now without opening a REPL.

Generate UUIDs instantly

v4 UUIDs, bulk generation, one-click copy. No signup, runs in your browser.

Open UUID Generator →

Frequently Asked Questions

What does UUID stand for?

UUID stands for Universally Unique Identifier. It's a 128-bit label used to uniquely identify information in computer systems. UUIDs are standardised in RFC 4122. They're also sometimes called GUIDs (Globally Unique Identifiers), especially in Microsoft ecosystems — the two terms describe the same format.

How unique is a UUID? Can two ever be the same?

A version 4 UUID has 122 bits of randomness, giving 2^122 (approximately 5.3 × 10^36) possible values. The probability of generating two identical UUIDs is so low it's considered negligible in practice — you'd need to generate about 1 billion UUIDs per second for 86 years to have a 50% chance of a single collision. In real systems, UUID collisions are effectively impossible.

What are the different UUID versions?

There are five UUID versions: v1 uses the current timestamp plus the machine's MAC address (unique but reveals hardware identity). v2 is similar to v1 but for DCE security and is rarely used. v3 generates a UUID by hashing a namespace and name using MD5 — same inputs always produce the same UUID. v4 is randomly generated with no meaningful data embedded — this is the most common version for general use. v5 is like v3 but uses SHA-1 instead of MD5.

When should I use UUID instead of auto-increment?

Use UUID when: you generate IDs in multiple databases or services and need them to be globally unique without coordination; you don't want to expose sequential IDs to users (which reveals record counts and makes scraping trivial); you need to create an ID before inserting into the database (useful for distributed systems). Use auto-increment when: simplicity is the priority, you're building a simple single-database app, performance is critical (UUID primary keys make B-tree indexes less efficient), and sequential ordering by ID is useful.

How do I generate a UUID in code?

In Node.js: import { randomUUID } from 'node:crypto'; const id = randomUUID(); — available natively since Node 14.17. In Python: import uuid; id = str(uuid.uuid4()). In Go: use the google/uuid package. In SQL (PostgreSQL): SELECT gen_random_uuid(). In the browser (no install required): use ToolStack's free UUID Generator.