What Is a UUID?
Updated 8 May 2026
A plain-English guide to UUIDs — what they are, how they are structured, the difference between v4 and v7, and when to use a UUID as a database primary key.
What a UUID is
A UUID (Universally Unique Identifier) is a 128-bit number used to identify things — database rows, API resources, session tokens, files, and anything else that needs a globally unique label. The defining feature is that UUIDs can be generated on any machine at any time without checking a central registry, yet collisions are so statistically rare they are treated as impossible in practice.
UUID vs GUID — the same thing
Microsoft calls them GUIDs (Globally Unique Identifiers). The format and generation algorithm are identical. You will see both terms depending on the technology stack — UUID in Linux/web/database contexts, GUID in Windows/.NET contexts.
UUID versions
| Version | How it is generated | Use today? |
|---|---|---|
| v1 | MAC address + timestamp | Avoid — leaks hardware identity |
| v3 | MD5 hash of namespace + name | Legacy only |
| v4 | Fully random (122 random bits) | Yes — widely supported default |
| v5 | SHA-1 hash of namespace + name | When deterministic IDs needed |
| v7 | Unix timestamp (ms) + random | Yes — preferred for databases |
Why UUID v7 is better for databases
UUID v4 is purely random. When used as a database primary key in a B-tree index, new rows are inserted at random positions — this causes page splits and index fragmentation, which degrades write performance at scale.
UUID v7 embeds a millisecond Unix timestamp in the first 48 bits. This means new UUIDs are always greater than earlier ones, so inserts go to the end of the index — the same pattern as an auto-incrementing integer. You get global uniqueness without the performance penalty.
Common uses
- Database primary keys — UUID v7 is ideal; v4 works but fragments indexes
- API resource identifiers — expose UUIDs rather than sequential integers to avoid enumeration attacks
- Session tokens and correlation IDs — easy to generate, globally unique across distributed systems
- Idempotency keys — generate a UUID client-side so retried requests are deduplicated server-side
- File names — avoid collisions when uploading files from multiple sources
Related guides
Generate UUID v4 and v7 online
Bulk generate, copy all, toggle uppercase or braces — instantly in the browser
Open UUID Generator →