Make Tools
2026-04-11

UUID Generator: What Are UUIDs and When to Use Them

Understand UUID versions (v1, v4, v5, v7), when to use them, and how to generate UUIDs in your browser or favorite programming language.

UUIDDeveloper ToolsDistributed Systems

What Is a UUID?

A UUID (Universally Unique Identifier) is a 128-bit number used to identify information in computer systems. Written as a 36-character string like 550e8400-e29b-41d4-a716-446655440000, UUIDs are designed to be globally unique without requiring a central authority to coordinate assignment.

The probability of two independently generated UUIDs colliding is astronomically low — you'd need to generate 1 billion UUIDs per second for 85 years to have a 50% chance of a single collision (for v4). Our UUID Generator creates them instantly in your browser.

UUID Versions Explained

UUID v1 — Timestamp-Based

v1 UUIDs combine a timestamp with the MAC address of the generating machine. This guarantees uniqueness (same machine + same time = same UUID) but leaks information about when and where the UUID was created.

Format: xxxxxxxx-xxxx-1xxx-xxxx-xxxxxxxxxxxx
Example: 550e8400-e29b-11d4-a716-446655440000
         ^^^^^^^^ ^^^^ ^^^^

UUID v4 — Random

v4 is the most commonly used version. It's generated from random numbers, with 122 bits of randomness and 6 fixed bits for version and variant. Simple, fast, and no privacy concerns.

Format: xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx
Example: f47ac10b-58cc-4372-a567-0e02b2c3d479
                       ^version  ^variant (8, 9, a, b)

UUID v5 — Name-Based (SHA-1)

v5 generates a UUID from a namespace and a name using SHA-1 hashing. The same namespace + name always produces the same UUID — deterministic and reproducible.

# Python: Generate a UUID v5
import uuid

namespace = uuid.NAMESPACE_DNS
print(uuid.uuid5(namespace, "example.com"))
# Always returns: cfbff0d1-9375-5685-968c-48ce8b15ae17

UUID v7 — Timestamp + Random (New)

v7 (RFC 9562) combines a Unix timestamp with random bits. It's sortable by creation time while maintaining randomness — the best of both v1 and v4. Increasingly the recommended choice for database primary keys.

Format: xxxxxxxx-xxxx-7xxx-xxxx-xxxxxxxxxxxx
Structure: 48-bit timestamp | 12-bit random | version | 62-bit random

When to Use UUIDs

  • Database primary keys: Avoid sequential IDs that reveal record counts. UUIDs let clients generate IDs before insertion.
  • Distributed systems: Multiple nodes can generate IDs independently without coordination.
  • API resources: Expose UUIDs instead of auto-incrementing integers to prevent enumeration attacks.
  • Session tokens: Unique, unguessable identifiers for user sessions.
  • File naming: Prevent collisions when multiple processes write files simultaneously.

UUIDs vs Other ID Systems

UUID vs Auto-Increment

Auto-increment integers are fast and compact but reveal information (total records, creation order) and require a central database to coordinate. UUIDs trade size for decentralization.

UUID vs ULID

ULIDs are 128-bit IDs that encode a timestamp in the first 48 bits, making them lexicographically sortable. They're more database-friendly than v4 UUIDs but less standardized. UUID v7 addresses the same problem within the UUID standard.

UUID vs NanoID

NanoID generates shorter, URL-friendly identifiers (21 characters by default) but isn't a standard. Great for human-facing URLs; stick with UUIDs for system-level identification.

Generating UUIDs in Different Languages

// JavaScript (Node.js)
const crypto = require('crypto');
const uuid = crypto.randomUUID();
console.log(uuid); // e.g., 1b9d6bcd-bbfd-4b2d-9b5d-ab8dfbbd4bed

// Browser
const uuid = self.crypto.randomUUID();
# Python
import uuid
print(uuid.uuid4())  # Random UUID
print(uuid.uuid5(uuid.NAMESPACE_DNS, "example.com"))  # Name-based
# Command line
uuidgen  # macOS / Linux
cat /proc/sys/kernel/random/uuid  # Linux alternative

Storing UUIDs Efficiently

UUIDs as strings take 36 bytes. Storing them as binary (16 bytes) saves space but complicates debugging. Modern databases offer native UUID types that handle this transparently.

// PostgreSQL: native UUID type
CREATE TABLE users (
  id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
  name TEXT NOT NULL
);

For MySQL, consider storing as BINARY(16) with conversion functions, or use CHAR(36) for simplicity at the cost of extra storage.

FAQ

Can UUIDs really never collide?

The probability is non-zero but negligibly small. For v4, you'd need to generate about 2.71 × 10¹⁸ UUIDs to have a 50% chance of one collision. For practical purposes, they're unique.

Which UUID version should I use?

Use v4 for simplicity, v7 if you need sortability, or v5 if you need deterministic generation from a name. For most applications, v4 is the default choice.

Are UUIDs safe to expose in URLs?

Yes — v4 UUIDs reveal no information about the system or sequence. This is a major advantage over sequential integer IDs.

How do I generate a UUID without installing anything?

Use our UUID Generator — it runs entirely in your browser and supports v1, v4, v5, and v7 formats.

Conclusion

UUIDs solve the problem of generating unique identifiers across distributed systems without coordination. Whether you need random (v4), time-sortable (v7), or deterministic (v5) identifiers, our UUID Generator has you covered — with batch generation and multiple format options, all client-side.

Ready to try it?

Open Tool →