What is a UUID / GUID?
A complete guide to Universally Unique Identifiers, why databases use them instead of auto-incrementing integers, and the different versions available.
The Basics of UUIDs
A Universally Unique Identifier (UUID), also frequently known as a Globally Unique Identifier (GUID) in the Microsoft ecosystem, is a 128-bit label used for information in computer systems. When generated according to standard methods, UUIDs are, for practical purposes, absolutely unique. Their uniqueness does not depend on a central registration authority or coordination between the parties generating them, unlike most other numbering schemes.
A standard UUID is a 36-character alphanumeric string that uses hyphens to separate the characters into five distinct groups. It typically looks like this:
123e4567-e89b-12d3-a456-426614174000Why Use UUIDs Instead of Auto-Incrementing IDs?
Historically, relational databases used auto-incrementing primary keys (e.g., User 1, User 2, User 3). While this is simple, it presents massive scale and security issues in modern distributed architectures.
- Security (Insecure Direct Object Reference): If a hacker knows their User ID is
100, they can easily guess that user99and101exist. If your API endpoint allows them to query/api/users/99without proper auth, they can scrape your entire database. A UUID is completely unguessable. - Distributed Generation: If you have 5 server clusters handling signups globally, they cannot securely assign an auto-incremented ID without constantly querying a central bottleneck server to find out what the "next" ID is. Because UUIDs are practically universally unique, each distributed server can instantly generate a UUID locally and save it, resulting in enormous performance gains.
The Different Versions of UUID
While they look similar, not all UUIDs are generated the same way. The specification (RFC 4122) defines several versions:
- Version 1 (Time-based): Generates the UUID using the MAC address of the computer generating it and the current timestamp. Rarely used today due to privacy concerns (the MAC address leaks the machine's identity).
- Version 3 (Name-based with MD5): Generates the UUID using an MD5 hash of a namespace identifier and a name. This means identical names in identical namespaces will always produce the exact same UUID.
- Version 4 (Randomly Generated): Generates the UUID entirely via pseudo-random numbers. This is the overwhelmingly most common standard for databases and software. The chance of a collision (generating the same ID twice) is statistically indistinguishable from zero.
- Version 5 (Name-based with SHA-1): Functionally identical to Version 3, but uses the more secure SHA-1 hashing algorithm instead of MD5.
Generate UUIDs instantly
Need to generate secure Version 4 UUIDs for your database or testing? Our free generator allows you to create bulk UUIDs with a single click.
Open UUID Generator