UUID (Universally Unique Identifier) is a 128-bit identifier standardized by RFC 4122. The standard text representation is 32 hexadecimal digits in five groups separated by hyphens:
550e8400-e29b-41d4-a716-446655440000
The probability of generating a duplicate UUID v4 is approximately 1 in 5.3 × 10³⁶ — so vanishingly small that for all practical purposes, UUIDs generated independently are guaranteed to be unique, even across different machines and without central coordination.
UUID versions compared
UUID v1 — Time-based
Generated from the current timestamp (100-nanosecond intervals since October 15, 1582) plus the machine's MAC address. The timestamp component makes v1 UUIDs sortable by creation time.
Tradeoff: v1 UUIDs reveal when and on which machine they were generated. This is a privacy concern for externally-visible IDs.
Use when: You need rough chronological ordering and privacy is not a concern — for example, internal logging or event sourcing systems.
UUID v4 — Random
The most widely used version. Generated from 122 bits of cryptographically secure random data. No timing, location, or sequential information is embedded.
Use when: General purpose unique identifiers — database primary keys, session tokens, API keys, file upload IDs, tracking IDs, correlation IDs.
UUID v5 — Name-based (SHA-1)
Deterministic: the same namespace UUID + name string always produces the same UUID. Uses SHA-1 hashing internally.
Common predefined namespaces:
DNSnamespace: for domain names (example.com)URLnamespace: for full URLsOIDnamespace: for ISO Object IdentifiersX500namespace: for X.500 distinguished names
Use when: You need to consistently generate the same ID for the same input — for example, generating a stable user ID from an email address, creating deterministic IDs for content-addressed storage, or producing consistent identifiers from known inputs across different systems.
ULID — Universally Unique Lexicographically Sortable ID
A newer alternative to UUID that is both unique and lexicographically sortable. The first 10 characters encode the timestamp in millisecond precision, the remaining 16 characters are random.
01ARZ3NDEKTSV4RRFFQ69G5FAV
│ │ │
└─ 48-bit └─ 80-bit random
timestamp
Advantages over UUID v4: Sorts chronologically, encodes creation time, uses Crockford Base32 (case-insensitive, no ambiguous characters like 0/O, 1/I/l).
Use when: Database primary keys where index performance matters (random UUID v4 causes page splits in B-tree indexes), or anywhere you want IDs that sort by insertion time.
NanoID — URL-friendly random ID
Smaller than UUID by default (21 characters vs 36), uses only URL-safe characters from a 64-character alphabet. Cryptographically secure.
V1StGXR8_Z5jdHi6B-myT
Use when: URL slugs, short tokens, user-facing identifiers where UUID's 36-character length is inconvenient.
UUIDs as database primary keys
Pros
- Generated client-side without a database round-trip
- Safe to merge records from multiple data sources (no ID collisions)
- No sequential ID enumeration (you cannot guess IDs by incrementing: 1, 2, 3...)
- Natural sharding key for distributed systems
Cons
- Larger storage than integer IDs: 16 bytes (UUID binary) or 36 bytes (UUID text) vs 4–8 bytes (int/bigint)
- Random UUID v4 hurts B-tree index performance due to random insertion order, causing frequent page splits
- Less human-readable than sequential integers during debugging
The solution for databases
Use ULIDs or UUID v7 (an emerging standard that is time-ordered like ULID but in standard UUID format) for database primary keys. Time-ordered IDs give the same performance characteristics as sequential integer IDs while retaining the distribution and privacy benefits of UUIDs.
Bulk UUID generation for test data
When building and testing applications, you often need large sets of unique IDs — for seeding databases, generating test fixtures, or populating API test payloads. Generating 100–1000 UUIDs in bulk and exporting as a JSON array or SQL INSERT VALUES statement is much faster than writing generation code manually.
How to generate UUIDs free
- Go to UUID Generator
- Select the version (v4 is recommended for most use cases)
- Click Generate or press Space or Enter to regenerate instantly
- For UUID v5: select a namespace and enter your input name
- For NanoID: adjust size and alphabet as needed
- Use bulk generation (up to 1000) and export as plain text, JS array, JSON, or SQL
All generation uses your browser's built-in crypto.randomUUID() and crypto.getRandomValues() — cryptographically secure and never sent to a server.