Generators5 min read

UUID Guide: What They Are, Version Differences, and How to Generate Them

Learn what UUIDs are, the difference between UUID v1, v4, and v7, when to use each, and how to generate UUIDs instantly online without any library.

Try the free online tool mentioned in this guide:UUID / ULID Generator

What is a UUID?

A UUID (Universally Unique Identifier) is a 128-bit label used to uniquely identify information. The standard format is 32 hexadecimal digits in five groups: xxxxxxxx-xxxx-Mxxx-Nxxx-xxxxxxxxxxxx, where M indicates the version and N indicates the variant.

UUIDs are designed so that generating them independently — even across different machines without coordination — produces values that are statistically guaranteed to not collide. This makes them ideal as primary keys in distributed databases, resource IDs in APIs, session tokens, and file names for uploads.

text
// Standard UUID format
"550e8400-e29b-41d4-a716-446655440000"
//  8      4    4    4    12 hex chars
// └─ Groups separated by hyphens ─┘

UUID v4: random (most common)

UUID v4 is generated entirely from random (or pseudo-random) data. It is the default choice for most applications because it requires no state, no coordination, and produces values with an astronomically low collision probability (2^122 possible values).

Used for: database primary keys, API resource IDs, session IDs, file upload names, request correlation IDs.

javascript
// UUID v4 examples
"f47ac10b-58cc-4372-a567-0e02b2c3d479"
"9b1deb4d-3b7d-4bad-9bdd-2b0d7b3dcb6d"

// Node.js
const { randomUUID } = require('crypto')
randomUUID() // → "f47ac10b-58cc-4372-a567-0e02b2c3d479"

// Browser
crypto.randomUUID()

UUID v1: timestamp + MAC address

UUID v1 embeds the current timestamp and the machine's MAC address. This means v1 UUIDs are sortable by creation time and traceable to the host that generated them — both of which can be privacy and security concerns.

Because the MAC address is embedded, v1 UUIDs from the same machine are predictable in pattern. Prefer v4 or v7 for new projects.

UUID v7: time-ordered (recommended for databases)

UUID v7 is a modern UUID format that embeds a Unix timestamp in the most significant bits, making UUIDs naturally sortable by creation order. This is a significant advantage for database performance: sorted UUIDs cause far fewer B-tree page splits than random v4 UUIDs, leading to better index locality and faster inserts at scale.

Used for: database primary keys where you want both uniqueness and sortability without a separate created_at column acting as a tiebreaker.

javascript
// UUID v7 — timestamp in first 48 bits
"018e4b3c-d6ab-7000-8000-000000000001"
// └─ millisecond timestamp ─┘└── random ─┘

// Libraries
// Node: uuidv7 package
// Postgres 17: gen_random_uuid() still v4; use uuid-ossp or a custom function
// Rust: uuid crate with v7 feature

UUID vs ULID vs KSUID

All three are 128-bit unique ID formats, but differ in sortability and encoding:

  • UUID v4 — random, not sortable, hyphenated hex, universally supported.
  • UUID v7 — time-ordered, sortable, same format as UUID, growing support.
  • ULID — Universally Unique Lexicographically Sortable Identifier. Base32-encoded (26 chars), monotonically sortable within the same millisecond, no hyphens. Good for distributed systems that need compact sortable IDs.
  • KSUID — K-Sortable Unique IDentifier. Base62-encoded (27 chars), sortable by second precision.

For most new projects: use UUID v7 for database PKs, ULID when a shorter and URL-friendly format matters.

Frequently asked questions

Can two UUIDs ever be the same?

Theoretically yes, but the probability is negligible. UUID v4 has 2^122 possible values (~5.3 × 10^36). Generating a billion UUIDs per second for 85 years gives a 50% chance of a single collision — effectively impossible in practice.

Should I use UUID v4 or v7 for database primary keys?

UUID v7 is generally better for database primary keys because its time-ordered structure produces sequential inserts that avoid B-tree fragmentation. UUID v4 causes random page splits under high insert load. If your database or ORM does not yet support v7, v4 is still perfectly correct.

Is a UUID the same as a GUID?

Yes. GUID (Globally Unique Identifier) is Microsoft's term for UUID. They use the same 128-bit format and are interchangeable.

How do I generate a UUID without a library in the browser?

Modern browsers expose crypto.randomUUID() which generates a cryptographically secure UUID v4. In Node.js 15+ use require("crypto").randomUUID().

Try UUID / ULID Generator for free

Generate UUID v1–v7 or ULIDs with namespace options and bulk copy or download. No install, no account required to try it.