A UUID (Universally Unique Identifier) is a 128-bit number used to uniquely identify something — a database record, a file, a session, a device — without requiring central coordination. Two systems can each generate a UUID completely independently and the chance they produce the same value is astronomically small.

What a UUID looks like

UUIDs are displayed as 32 hexadecimal digits split into five groups by hyphens:

550e8400-e29b-41d4-a716-446655440000

The format is always 8-4-4-4-12 characters. The total length is always 36 characters including hyphens, or 32 hex characters without them. The third group contains a version digit — the 4 in 41d4 above indicates UUID version 4.

UUID and GUID mean the same thing. GUID (Globally Unique Identifier) is Microsoft's name for the same standard. They are interchangeable terms — the format and generation rules are identical.

UUID versions — what is the difference?

There are five UUID versions (v1–v5), each using a different generation strategy. You will mostly encounter v1 and v4 in practice:

VersionHow it is generatedUse when
v1Current timestamp + MAC address of the machineYou want IDs that sort chronologically or need to trace which machine generated them
v3MD5 hash of a namespace + nameYou need deterministic IDs from a name (same input always produces same UUID)
v4Randomly generated (122 random bits)Most use cases — fast, simple, no coordination needed, no information leakage
v5SHA-1 hash of a namespace + nameSame as v3 but with a stronger hash function

UUID v4 is what most developers use. It is purely random, requires no knowledge of the machine or timestamp, and contains no identifiable information about when or where it was created.

UUID vs auto-increment: when to use which

Auto-increment integers (1, 2, 3…) are the default primary key in most databases. They are compact, fast to index, and easy to read. So why use UUIDs?

The tradeoffs: UUIDs are larger (16 bytes vs 4 bytes for an integer), harder to type or remember, and random UUIDs (v4) fragment database index pages because insertions are non-sequential.

Tip: If you need both the uniqueness of UUIDs and the sequential ordering benefit for database indexing, consider UUID v7 — a newer standard that encodes a timestamp in the most significant bits, making UUIDs naturally sortable by creation time.

Generating UUIDs in code