UUIDs (Universally Unique Identifiers) are 128-bit identifiers used across distributed systems to generate unique IDs without coordination. This guide explains how to generate them and when to use each version.
โก Try It Free โ No Signup
Works instantly in your browser. No account, no install, no upload.
Generate UUID Free โWhat Is a UUID?
A UUID is a 128-bit number formatted as 32 hexadecimal digits in 5 groups separated by hyphens: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx. Example: 550e8400-e29b-41d4-a716-446655440000. The probability of generating the same UUID twice is astronomically small.
UUID v1 vs UUID v4
| Version | Based On | Pros | Cons |
|---|---|---|---|
| v1 | Timestamp + MAC address | Time-sortable | Leaks MAC address |
| v4 | Random | Private, simple | Not sortable |
v4 is the most commonly used โ it's generated from random numbers and doesn't expose any system information.
Common Uses for UUIDs
- Primary keys in databases (instead of auto-increment integers)
- Session tokens and API keys
- Filenames for uploaded files to avoid collisions
- Distributed systems where multiple nodes generate IDs independently
- Idempotency keys in payment APIs
UUID in Code
# Python
import uuid
print(uuid.uuid4()) # โ e.g. 550e8400-e29b-41d4-a716-446655440000
# JavaScript (Node.js 14.17+)
const { randomUUID } = require('crypto');
console.log(randomUUID());
// Browser
crypto.randomUUID();
Frequently Asked Questions
Is a UUID truly unique?
For practical purposes, yes. UUID v4 has 2^122 possible values. If you generated 1 billion UUIDs per second for 100 years, the probability of a collision is still negligibly small.
What's the difference between UUID and GUID?
GUID (Globally Unique Identifier) is Microsoft's term for the same concept. They are structurally identical.
Can UUIDs be used as database primary keys?
Yes, but with a trade-off: random UUIDs cause index fragmentation in B-tree indexes. For sequential IDs, consider UUID v7 (time-ordered) or ULID.
Are UUIDs case-sensitive?
No. UUIDs are typically lowercase but are case-insensitive. Both 550e8400... and 550E8400... refer to the same UUID.