Guide

What Is a UUID and How to Generate One

May 2, 2026 · 7 min read · Try the UUID Generator →

If you have spent any time working with databases, APIs, or distributed systems, you have almost certainly encountered a UUID. They look something like this: 550e8400-e29b-41d4-a716-446655440000. That string of 32 hexadecimal digits separated by hyphens is one of the most important tools in modern software engineering — yet many developers reach for them without fully understanding what makes them tick.

This guide explains what a UUID is, the differences between UUID versions, when to use each one, and how to generate UUIDs in every major language and online.

What Does UUID Stand For?

UUID stands for Universally Unique Identifier. It is also sometimes called a GUID (Globally Unique Identifier), particularly in Microsoft and .NET ecosystems — they refer to the same concept. A UUID is a 128-bit label used to uniquely identify information in computer systems without requiring a central authority to manage the assignment of identifiers.

The key word is universally. A properly generated UUID should be unique not just within your database, but across every database, every server, and every application on Earth — all without any coordination between systems. That is an extraordinary property, and it is what makes UUIDs indispensable in distributed systems.

The Structure of a UUID

Every UUID follows the same format: xxxxxxxx-xxxx-Mxxx-Nxxx-xxxxxxxxxxxx, where each x is a hexadecimal digit (0–9 or a–f). The total is 32 hex characters = 128 bits of data.

The M position indicates the UUID version (1–5, or 7 for the newer spec). The N position indicates the variant — for standard UUIDs this is always 8, 9, a, or b.

Breaking down 550e8400-e29b-41d4-a716-446655440000: the 4 tells you this is a version 4 UUID, and the a confirms the standard variant. Everything else is data determined by the generation algorithm.

UUID Versions Explained

There are five original UUID versions defined in RFC 4122, plus a newer version 7 gaining rapid adoption. Each uses a different strategy to achieve uniqueness.

Version 1 — Timestamp + MAC Address

UUID v1 combines the current timestamp (with 100-nanosecond precision) and the MAC address of the generating machine. This guarantees uniqueness as long as the same machine does not generate two UUIDs within the same 100-nanosecond window — almost impossible in practice.

The downside: v1 UUIDs expose your machine's MAC address and the exact time of creation, which is a privacy concern for some applications. They are also not monotonically sortable because the timestamp bytes are spread across the UUID in a non-sequential order.

Version 2 — DCE Security

Version 2 is rarely used in practice. It replaces part of the timestamp with POSIX UID/GID values for distributed computing environments. You will almost never need this version outside of legacy enterprise systems.

Version 3 — Name-Based (MD5)

UUID v3 generates a deterministic UUID from a namespace and a name using MD5 hashing. Given the same namespace and name, you always get the same UUID. This is useful when you need a stable identifier for a specific resource — for example, generating a consistent UUID for a URL.

Version 4 — Random

Version 4 is the most widely used UUID today. It is generated from 122 bits of cryptographically secure random data (the remaining 6 bits encode the version and variant). With 2¹²² possible values — that is roughly 5.3 undecillion — the probability of two randomly generated v4 UUIDs colliding is astronomically small.

To put the collision probability in perspective: generating one billion v4 UUIDs per second for 100 years gives you roughly a 50% chance of finding a single collision. For all practical purposes, treat v4 UUIDs as perfectly unique.

Version 5 — Name-Based (SHA-1)

Like v3, but uses SHA-1 instead of MD5. SHA-1 is stronger than MD5, making v5 the preferred choice whenever you need name-based deterministic UUIDs. Same namespace + same name always produces the same v5 UUID.

Version 7 — Timestamp-Ordered (New)

UUID v7 is defined in the newer RFC 9562 and is rapidly replacing v1 in modern applications. It encodes a Unix millisecond timestamp in the most-significant bits, followed by random data. This makes v7 UUIDs sortable by creation time when stored lexicographically — a major advantage for database indexing performance. Most modern databases can store and index v7 UUIDs far more efficiently than random v4 UUIDs.

UUID vs. Auto-Increment IDs

FeatureUUID v4Auto-Increment Integer
Uniqueness scopeUniversalPer table only
Mergeable across DBs✅ Yes❌ No
Reveals record count✅ No❌ Yes
Index performanceSlower (random)Faster (sequential)
Storage size16 bytes (binary)4–8 bytes
Human readable❌ No✅ Yes

For most modern web applications, UUIDs are the better choice because they allow safe merging of data across databases, prevent enumeration attacks (attackers cannot guess /users/550e8400... like they can guess /users/1001), and work naturally in distributed or microservice architectures.

How to Generate UUIDs

Online — Instantly

The fastest way to generate a UUID is to use ToolPry's free UUID Generator. It generates cryptographically random v4 UUIDs entirely in your browser — no data is sent to any server. You can generate bulk UUIDs, toggle uppercase/lowercase, and copy results with one click.

JavaScript / Node.js

// Browser (modern)
const id = crypto.randomUUID();
// → "550e8400-e29b-41d4-a716-446655440000"

// Node.js 14.17+
import { randomUUID } from 'crypto';
const id = randomUUID();

// npm package (all environments)
import { v4 as uuidv4, v7 as uuidv7 } from 'uuid';
const id = uuidv4();
const sortableId = uuidv7(); // timestamp-ordered

Python

import uuid

# Version 4 (random)
id = uuid.uuid4()
print(str(id))  # 550e8400-e29b-41d4-a716-446655440000

# Version 5 (name-based)
ns = uuid.NAMESPACE_URL
id = uuid.uuid5(ns, 'https://toolpry.com')
print(str(id))

# Version 1 (timestamp)
id = uuid.uuid1()
print(str(id))

PostgreSQL

-- Enable the extension (once per database)
CREATE EXTENSION IF NOT EXISTS "pgcrypto";

-- Generate a UUID v4
SELECT gen_random_uuid();

-- Use as a default column value
CREATE TABLE users (
  id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
  email TEXT NOT NULL
);

MySQL / MariaDB

-- Generate UUID
SELECT UUID();

-- UUID as primary key
CREATE TABLE users (
  id CHAR(36) PRIMARY KEY DEFAULT (UUID()),
  email VARCHAR(255) NOT NULL
);

PHP

// PHP 7+ with ramsey/uuid package composer require ramsey/uuid use Ramsey\Uuid\Uuid; $id = Uuid::uuid4()->toString(); echo $id; // 550e8400-e29b-41d4-a716-446655440000

When Should You Use a UUID?

Use UUIDs when you need identifiers that are unique across systems — for example when merging records from multiple databases, when exposing IDs in public URLs (to prevent enumeration), in event-driven or microservice architectures where services generate IDs independently, and when building offline-first applications where clients generate IDs before syncing to a server.

Stick with auto-increment integers when your data lives in a single database, when index performance is critical (consider UUID v7 if you need both), or when human-readable IDs are important for debugging and support workflows.

Storing UUIDs Efficiently

Never store UUIDs as VARCHAR(36) strings in a database. That wastes space and slows indexing. PostgreSQL's native UUID type stores them as 16 bytes. MySQL should use BINARY(16) with the UUID_TO_BIN() and BIN_TO_UUID() functions. In application memory, store UUIDs as byte arrays or native UUID objects rather than strings whenever the language supports it.

Common Mistakes with UUIDs

The most common mistake is using UUID v1 in user-facing contexts, inadvertently leaking MAC addresses and timestamps. Use v4 for random IDs and v7 when you need sortability. Another frequent error is comparing UUIDs as case-sensitive strings — 550E8400... and 550e8400... are the same UUID; always normalize to lowercase before comparing. Finally, avoid generating UUIDs with Math.random() in JavaScript — it is not cryptographically secure. Always use crypto.randomUUID() or the uuid package.

Try It Now

Ready to generate UUIDs for your project? Use ToolPry's UUID Generator — it runs entirely in your browser, supports bulk generation, and lets you copy results instantly. No sign-up, no data collection, completely free.

Also worth checking out: Hash Generator for SHA-256 and MD5 hashing, and Base64 Encoder if you need to encode UUIDs for transmission in APIs.