You need an identifier for a new record, but you cannot ask a central database for the next number: the record is created offline on a phone, or in several services at once, or you simply do not want the ID to reveal how many customers you have. This is the problem UUIDs were designed to solve. They let any machine create an identifier on its own, with practically no risk of clashing with an identifier created anywhere else.
This guide explains how a UUID is built, what the different versions mean, how small the chance of a collision really is, and when a UUID is the wrong choice. It also shows how to generate them in bulk in a browser and from code.
Anatomy of a UUID
A UUID (Universally Unique Identifier) is a 128-bit number, normally written as 32 hexadecimal digits in five groups separated by hyphens:
585ba5b5-c213-4feb-9a5c-e424dfbc7bfd
xxxxxxxx-xxxx-Mxxx-Nxxx-xxxxxxxxxxxx
Two positions carry metadata:
- M, the first digit of the third group, is the version. In the example it is
4. - N, the first digit of the fourth group, is the variant. For standard UUIDs it is
8,9,aorb.
Everything else depends on the version. "GUID" (Globally Unique Identifier) is Microsoft's name for the same thing; a GUID generated by Windows or .NET is a UUID, sometimes shown in uppercase or wrapped in braces.
The versions you will meet
The current specification is RFC 9562 (2024), which replaced the older RFC 4122 and added new versions.
| Version | How it is made | Typical use |
|---|---|---|
| v1 | Timestamp plus a node ID (historically the MAC address) | Legacy systems |
| v3 / v5 | Hash of a namespace and a name (MD5 / SHA-1) | The same input must always give the same ID |
| v4 | 122 random bits | General-purpose unique IDs |
| v7 | Unix millisecond timestamp followed by random bits | Database keys that should sort by creation time |
Version 4 is by far the most common. It needs no clock, no hardware address and no coordination, just a good random number generator.
How likely is a v4 collision?
Of the 128 bits in a v4 UUID, 6 are fixed (version and variant), leaving 122 random bits: about 5.3 × 10^36 possible values. Using the standard birthday-problem approximation, you would need to generate roughly 2.7 × 10^18 UUIDs before the chance of even one duplicate reached 50%. For any real application, a collision caused by the maths is not a practical concern.
Collisions caused by bugs are a real concern. The guarantee only holds if the random source is good. Generating UUIDs with a weak random function, copying a hard-coded example UUID into test data that later reaches production, or reusing a seeded generator across containers can all create duplicates. Use a cryptographically secure generator and keep a unique constraint in the database anyway.
Generate UUIDs with our tool
The UUID Generator uses the browser's crypto.randomUUID(), which produces version 4 UUIDs from a cryptographically secure random source. Nothing is fetched from a server.
- Open the UUID Generator.
- Enter how many you need in Number of UUIDs. The field is designed for 1 to 100 at a time.
- Click Generate. The list appears under Generated UUIDs.
- Click the copy icon next to any single UUID, or Copy All (shown when you generate more than one) to copy the whole list, one per line, ready to paste into a spreadsheet column or a seed script.
Each click of Generate creates a fresh batch. If you need realistic sample records rather than bare IDs, the Fake Data Generator can produce rows of test data.
Generating UUIDs in code and on the command line
For anything automated, generate IDs where the record is created:
// Browsers (secure contexts) and Node.js 19+
const id = crypto.randomUUID();
// Node.js 14.17+ via the crypto module
const { randomUUID } = require("node:crypto");
randomUUID();
import uuid
str(uuid.uuid4())
uuidgen # macOS and most Linux distributions
New-Guid # Windows PowerShell
[guid]::NewGuid().ToString()
Most databases can generate them too. PostgreSQL provides gen_random_uuid() (built in since version 13), and SQL Server has NEWID(). Check your database documentation for v7 support, which is newer and not yet available everywhere.
When to use a UUID, and when not to
Good fits
- Distributed or offline creation. Mobile apps, microservices and data imports can create IDs without talking to each other.
- Public identifiers. A URL like
/orders/3f1c…does not reveal that you have only 312 orders, and IDs cannot be guessed by incrementing a number. - Merging data sets. Records from different sources keep unique keys when combined.
Trade-offs
- Size. A UUID is 16 bytes in binary and 36 characters as text, versus 4 or 8 bytes for an integer. Store it in a native
uuidtype or as binary where your database supports it, not as a text column. - Index locality. Random v4 values scatter inserts across a B-tree index. On very large, write-heavy tables this can slow inserts and bloat the index. Time-ordered v7 UUIDs were designed largely to fix this.
- Not a secret. A UUID is unique, not confidential. Never use one as a password, session token or password-reset code on its own. For secrets, use a dedicated random token, such as one from the Password Generator.
- Human friendliness. Customers cannot read a UUID over the phone. Use a short reference number for anything people type.
If you need an identifier that is always the same for the same input, for example a stable ID for a URL, use a name-based v5 UUID or a hash from the Hash Generator instead of random values.
Tips and pitfalls
- Compare case-insensitively.
3F1C...and3f1c...are the same UUID. Normalise to lowercase when storing. - Validate the format loosely. A pattern such as
^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$(case-insensitive) checks the shape. Test variations in the Regex Tester. crypto.randomUUID()needs a secure context. In browsers it is available on HTTPS pages and onlocalhost, but not on plain HTTP sites.
Frequently asked questions
Is a GUID the same as a UUID?
Yes. GUID is the name used in Microsoft products for the same 128-bit identifier format. They are interchangeable.
Can two UUIDs ever be the same?
In theory yes, in practice no, provided they come from a proper random source. The risk that matters is software bugs, so keep a unique constraint on the column.
Should I use UUID v4 or v7?
Use v7 when the IDs are database primary keys and you want them roughly sorted by creation time. Use v4 when ordering does not matter or when you do not want the ID to reveal when a record was created.
Are UUIDs safe to show in URLs?
They are safe in the sense that they are hard to guess and reveal nothing about volume. Still, check permissions on every request; an unguessable ID is not access control.
How many UUIDs can I generate at once here?
The generator is designed for batches of up to 100. Click Generate again for another batch.