A UUID (Universally Unique Identifier) is the standard way to generate unique IDs in distributed systems, databases, and APIs. No central coordination required — uniqueness is guaranteed globally by design.

Generate a UUID now →

What Is a UUID?

A UUID is a 128-bit number, typically represented as 5 groups of hexadecimal digits separated by hyphens:

550e8400-e29b-41d4-a716-446655440000
xxxxxxxx-xxxx-Mxxx-Nxxx-xxxxxxxxxxxx
  • M — version number (1, 3, 4, or 5)
  • N — variant bits (8, 9, a, or b)

The standard format is 8-4-4-4-12: 36 characters total (including hyphens), 32 hex characters.

UUID Versions

VersionGeneration methodUse case
v1Timestamp + MAC addressTime-sortable but may leak MAC address
v3Namespace + name (MD5)Deterministic — same input always produces same UUID
v4RandomMost common — pure random, no information leakage
v5Namespace + name (SHA-1)More secure deterministic IDs than v3

v4 is the right choice for the vast majority of use cases.

UUID v4 Collision Probability

Generating 1 billion UUIDs per second, it would take approximately 85 years to reach a 50% chance of a single collision. For all practical purposes, UUIDs are infinitely unique.

Generate UUIDs Online

ZeroTool UUID Generator →

  • Single or bulk generation
  • One-click copy
  • Runs entirely in your browser — nothing sent to a server

Generate UUIDs in Code

JavaScript (Node.js 18+)

import { randomUUID } from 'crypto';

const id = randomUUID();
// 'f47ac10b-58cc-4372-a567-0e02b2c3d479'

Also available in Node.js 14.17+ as crypto.randomUUID().

JavaScript (Browser)

const id = crypto.randomUUID();
// Supported in all modern browsers (Chrome 92+, Firefox 95+, Safari 15.4+)

Using the uuid Library (Legacy Support)

npm install uuid
import { v4 as uuidv4 } from 'uuid';

const id = uuidv4();

Python

import uuid

# v4 (random)
id = uuid.uuid4()
print(str(id))  # 'f47ac10b-58cc-4372-a567-0e02b2c3d479'

# v5 (namespace-based, deterministic)
id = uuid.uuid5(uuid.NAMESPACE_URL, 'https://zerotool.dev')

Go

import "github.com/google/uuid"

id := uuid.New()
fmt.Println(id.String())

SQL (PostgreSQL)

-- Generate a UUID
SELECT gen_random_uuid();

-- Use UUID as a primary key
CREATE TABLE users (
  id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
  name TEXT NOT NULL
);

UUIDs as Database Primary Keys

Advantages

  • Globally unique — no collisions across multiple services or databases
  • No central sequence — clients can generate IDs before writing to the database
  • No information leakage — unlike auto-increment IDs, they don’t expose row counts

Disadvantages

  • Index fragmentation — random UUIDs cause B-tree fragmentation, making inserts slower than sequential integers
  • Storage size — 16 bytes vs 4–8 bytes for integers
  • No natural ordering — v4 UUIDs have no time-based sort order

Solution: UUID v7 (Draft)

UUID v7 places the timestamp in the high bits, combining uniqueness with monotonic ordering. It’s ideal for database primary keys. Some libraries already support it:

// Node.js
import { v7 as uuidv7 } from 'uuid';
const id = uuidv7();
// '017f22e2-79b0-7cc3-98c4-dc0c0c07398f'
// The leading segment is a millisecond-precision timestamp — naturally sortable

Format Variants

Standard:     550e8400-e29b-41d4-a716-446655440000
No hyphens:   550e8400e29b41d4a716446655440000
Uppercase:    550E8400-E29B-41D4-A716-446655440000
URN:          urn:uuid:550e8400-e29b-41d4-a716-446655440000

When storing in a database, prefer the native UUID type (PostgreSQL, MySQL 8.0+) over VARCHAR — it saves storage and speeds up comparisons.

Validating a UUID

// JavaScript
const UUID_REGEX = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
UUID_REGEX.test('550e8400-e29b-41d4-a716-446655440000'); // true
# Python
import uuid

def is_valid_uuid(val):
    try:
        uuid.UUID(str(val))
        return True
    except ValueError:
        return False

Summary

NeedRecommended approach
Quick generationZeroTool UUID Generator
Browser / Node.jscrypto.randomUUID()
Pythonuuid.uuid4()
Database primary key (ordered)UUID v7 or ULID
Deterministic IDUUID v5

UUID v4 works for the overwhelming majority of use cases. If you need database-friendly sequential IDs, consider UUID v7 or ULID.