How to Generate UUIDs

March 22, 2026 · 6 min read

UUIDs (Universally Unique Identifiers) are 128-bit identifiers used everywhere in software — database primary keys, API request IDs, session tokens, distributed systems, and more. They're designed to be unique across time and space without a central authority.

In this guide, you'll learn what UUIDs are, the differences between UUID versions, and how to generate them in every major language and environment — or just use our free UUID generator.

What Is a UUID?

A UUID is a 128-bit number typically displayed as 32 hexadecimal digits in five groups separated by hyphens:

550e8400-e29b-41d4-a716-446655440000

The format is 8-4-4-4-12 characters. With 2128 possible values (over 340 undecillion), the probability of generating two identical UUIDs is astronomically small — you'd need to generate 1 billion UUIDs per second for about 85 years to have a 50% chance of a single collision.

UUID Versions Explained

Not all UUIDs are created the same way. The version number is encoded in the UUID itself (the 13th character):

UUID v1 — Timestamp + MAC Address

Generated from the current timestamp and the machine's MAC address. Guarantees uniqueness but leaks information about when and where it was created.

6ba7b810-9dad-11d1-80b4-00c04fd430c8 ^ v1

Use when: You need time-sortable IDs and don't care about privacy.

UUID v4 — Random

Generated from random (or pseudo-random) numbers. The most commonly used version — simple, fast, and doesn't leak any information.

f47ac10b-58cc-4372-a567-0e02b2c3d479 ^ v4

Use when: You need a unique ID and don't have special requirements. This is the default choice for most applications.

UUID v5 — Name-Based (SHA-1)

Generated by hashing a namespace UUID and a name with SHA-1. Always produces the same UUID for the same namespace + name combination — deterministic and reproducible.

886313e1-3b8a-5372-9b90-0c9aee199e5d ^ v5

Use when: You need the same UUID for the same input every time (e.g., generating an ID from a URL or email address).

UUID v7 — The Modern Choice

A newer standard (RFC 9562) that combines a Unix timestamp with random bits. Time-sortable like v1 but without leaking a MAC address. Increasingly the recommended default for databases.

Use when: You need database-friendly, time-sortable IDs (many new projects are adopting v7 over v4).

Generate UUIDs instantly

Generate UUID v1, v4, or bulk UUIDs with one click.

Open UUID Generator

How to Generate UUIDs

Method 1: Online Generator

The fastest way — use our UUID generator tool to create single or bulk UUIDs instantly. Supports v1 and v4 with one-click copy.

Method 2: JavaScript / Node.js

Modern browsers and Node.js have built-in UUID generation:

// Browser (Web Crypto API) — built-in, no library needed const uuid = crypto.randomUUID(); console.log(uuid); // "3b241101-e2bb-4d55-af19-a2b3c4d5e6f7" // Node.js (v14.17+) const { randomUUID } = require('crypto'); console.log(randomUUID()); // Using the 'uuid' npm package (for v1, v5, etc.) const { v1, v4, v5 } = require('uuid'); console.log(v4()); // Random UUID console.log(v1()); // Timestamp-based UUID

Method 3: Python

import uuid # UUID v4 (random) — most common print(uuid.uuid4()) # e.g., "a8098c1a-f86e-11da-bd1a-00112444be1e" # UUID v1 (timestamp + MAC) print(uuid.uuid1()) # UUID v5 (name-based, deterministic) print(uuid.uuid5(uuid.NAMESPACE_URL, "https://utilshed.com")) # Always produces the same UUID for the same input

Method 4: Command Line

# Linux uuidgen # macOS uuidgen | tr '[:upper:]' '[:lower:]' # PowerShell [guid]::NewGuid() # Using Python one-liner python3 -c "import uuid; print(uuid.uuid4())"

Method 5: SQL

-- PostgreSQL (built-in) SELECT gen_random_uuid(); -- MySQL 8+ SELECT UUID(); -- SQLite (with extension) SELECT lower(hex(randomblob(4))) || '-' || lower(hex(randomblob(2))) || '-4' || substr(lower(hex(randomblob(2))),2) || '-' || substr('89ab',abs(random()) % 4 + 1, 1) || substr(lower(hex(randomblob(2))),2) || '-' || lower(hex(randomblob(6)));

UUID vs. Other ID Formats

Best Practices

Generate UUIDs Now

Need a UUID right now? Use the free UUID generator on UtilShed — generate single or bulk UUIDs with one click.

You might also find these tools useful: