UUID Generator Online — Generate UUID v4 and v7 Instantly
A UUID is a 128-bit identifier formatted as 32 hex digits in 5 groups. UUID v4 uses random generation; UUID v7 uses timestamp + random for sorted uniqueness. Here's when to use...
A UUID (Universally Unique Identifier) is a 128-bit value represented as 32 hexadecimal digits in five hyphen-separated groups: 550e8400-e29b-41d4-a716-446655440000. Generated correctly, the collision probability is low enough that uniqueness is guaranteed for all practical purposes.
Use the UUID Generator to generate UUID v4 and v7 identifiers instantly without installation.
UUID format
All UUID versions follow the same 8-4-4-4-12 format:
xxxxxxxx-xxxx-Mxxx-Nxxx-xxxxxxxxxxxx
M = version (4 or 7)
N = variant (8, 9, a, or b for RFC 4122)
Example UUID v4: f47ac10b-58cc-4372-a567-0e02b2c3d479
Total: 32 hex digits = 128 bits. The version digit identifies UUID type; the variant bits identify the UUID specification (RFC 4122 uses 10xx).
UUID v4 (random)
UUID v4 generates 122 bits of randomness (128 bits minus 6 used for version and variant). The remaining 122 bits come from a cryptographically secure random number generator.
f47ac10b-58cc-4372-a567-0e02b2c3d479
↑ ↑
Version=4 Variant=a (10xx binary)
Collision probability: With 122 random bits, the expected number of UUIDs you’d need to generate before hitting a collision is ~2.7 × 10^18. At 1 billion UUIDs generated per second, a 50% probability of collision occurs after ~85 years. Effectively unique for any real application.
Use UUID v4 for: Session tokens, API keys, non-sequential IDs where randomness matters, IDs that shouldn’t expose creation order.
UUID v7 (timestamp-ordered)
UUID v7 encodes a Unix timestamp in milliseconds in the high bits, followed by random bits. This makes UUIDs sortable by creation time.
01906b8e-7cc0-7d42-a567-0e02b2c3d479
↑↑↑↑↑↑↑↑↑↑↑↑
Unix ms timestamp (48 bits)
Why this matters for databases: Standard B-tree indexes perform best when new values are inserted in sequential order. UUID v4 is random — every insert lands at a random position in the index, causing page splits and fragmentation. UUID v7 inserts near the end of the index (latest timestamp = latest in order), just like auto-increment IDs.
Benchmark: For high-insert-rate tables (100K+ rows/second), UUID v7 can be 3-5× faster than UUID v4 for insert operations due to index locality.
Use UUID v7 for: Database primary keys, any ID that benefits from creation-time ordering, IDs you’d filter by recency.
Generating UUIDs in code
JavaScript (Node.js 21+ / modern browsers)
// Browser/Node.js — built-in crypto module:
const { randomUUID } = require('crypto');
const uuid = randomUUID(); // UUID v4
console.log(uuid); // "f47ac10b-58cc-4372-a567-0e02b2c3d479"
// Browser:
const uuid2 = crypto.randomUUID(); // UUID v4
JavaScript with uuid library
import { v4 as uuidv4, v7 as uuidv7 } from 'uuid';
const id_v4 = uuidv4(); // Random UUID v4
const id_v7 = uuidv7(); // Timestamp-ordered UUID v7
console.log(id_v4); // e.g., "110e8400-e29b-41d4-a716-446655440000"
console.log(id_v7); // e.g., "01906b8e-7cc0-7000-8000-000000000000"
Python
import uuid
# UUID v4 (random):
id_v4 = uuid.uuid4()
print(id_v4) # UUID('f47ac10b-58cc-4372-a567-0e02b2c3d479')
print(str(id_v4)) # "f47ac10b-58cc-4372-a567-0e02b2c3d479"
# UUID v1 (timestamp-based, older standard — prefer v7):
id_v1 = uuid.uuid1()
print(str(id_v1))
# UUID from a string:
parsed = uuid.UUID('f47ac10b-58cc-4372-a567-0e02b2c3d479')
print(parsed.version) # 4
Python’s standard library doesn’t include UUID v7 yet (as of 3.12). Use the uuid7 package:
from uuid7 import uuid7
id_v7 = uuid7()
SQL (PostgreSQL)
-- Generate UUID v4 (requires pgcrypto or uuid-ossp extension):
SELECT gen_random_uuid();
-- f47ac10b-58cc-4372-a567-0e02b2c3d479
-- UUID column with auto-generation:
CREATE TABLE items (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
name TEXT
);
-- PostgreSQL 17+ native UUID v7:
SELECT gen_random_uuid_v7();
UUID vs ULID vs NanoID
| Format | Size | Sortable | Collision-safe | Use case |
|---|---|---|---|---|
| UUID v4 | 36 chars | No | Yes (122 bits) | General purpose IDs |
| UUID v7 | 36 chars | Yes | Yes | Database PKs |
| ULID | 26 chars | Yes | Yes | Shorter sortable IDs |
| NanoID | Configurable | No | Configurable | Short URLs, tokens |
| KSUID | 27 chars | Yes | Yes | k-sortable IDs |
ULID (Universally Unique Lexicographically Sortable Identifier) is an alternative to UUID v7 — same idea (timestamp + random, sortable) but uses Crockford’s Base32 for a shorter representation (26 chars vs 36).
NanoID is useful when you need short IDs (12–21 chars) for URLs or user-facing identifiers. Not timestamp-ordered.
When NOT to use UUIDs
User-facing identifiers: A UUID like f47ac10b-58cc-4372 is hard to type, communicate verbally, or include in a short URL. For user-facing IDs, use a NanoID or a sequential integer with a prefix.
Sequential data where order matters: If you need to know which record was created first from the ID alone, UUID v4 doesn’t help. Use UUID v7, ULID, or KSUID.
Very high-frequency inserts with UUID v4: As described above, UUID v4’s random ordering degrades B-tree index performance. UUID v7 or sequential IDs are better for write-heavy tables.
Related tools
- UUID Generator — generate UUID v4 and v7 instantly
- UUID v4 vs v7 — choosing the right version for your database
Related posts
- UUID v4 vs v7 for Databases: The Benchmark You Need — UUID v4 fragments your primary key index. UUID v7 fixes it with millisecond-orde…
- CUID2 — Collision-Resistant IDs Better Than UUID v4 — CUID2 generates secure, URL-safe, database-friendly IDs with better collision re…
- NanoID vs UUID — Which Unique ID Generator Should You Use? — NanoID generates shorter, URL-safe unique IDs using a custom alphabet. UUID v4 i…
Related tool
Generate UUID v4 and v7 identifiers in bulk.
Written by Mian Ali Khalid. Part of the Encoding & Crypto pillar.