Blog / Tool Tips & Guides

What Is a UUID and Why Does Your Database Need One?

By Abid · August 12, 2026

A UUID is a 128-bit identifier written as thirty-two hexadecimal digits in five hyphenated groups. The point of it is that two systems with no knowledge of each other can each create one and be confident they will never clash. The UUID Generator produces version 4 UUIDs, one or in bulk.

Why not just count

An auto-incrementing number is smaller, faster to index and easier to read. It is also only unique within the one table that issues it, and it requires something central to hand out the next value.

That breaks as soon as there is more than one source. Two database servers accepting writes, an offline mobile app creating records before it can sync, data merged from two systems after an acquisition - in each case counters collide, because both sides issued a 1,847. A UUID is generated locally from randomness, so no coordination is needed at all.

It also stops identifiers being guessable. Sequential ids in a URL invite someone to try the next number, and far too many systems return the record when they do. A UUID makes enumeration pointless, though it is not access control - it hides the door rather than locking it.

What version 4 means, and what the odds are

Version 4 is simply random: 122 random bits with six reserved to record the version. The collision probability is the part people find hard to believe. You could generate a billion UUIDs a second for a century and still have a vanishingly small chance of a single duplicate. For practical purposes, treat it as never.

What it costs

Sixteen bytes against four, and in a database that is not the real cost. The real cost is index locality. Sequential ids are inserted at the end of the index, which is cheap. Random UUIDs land anywhere, which fragments the index, and on a large table that is measurable.

Readability is the other cost. A support ticket referring to order 4873 is workable; one referring to a thirty-six character string is not. Plenty of systems keep both: a UUID as the real identity and a short sequential number for humans to say out loud.

Common questions

Should every table use UUIDs?

No. If a table is written by exactly one database and the ids are never exposed in a URL, a plain counter is simpler and faster.

Can I shorten a UUID?

You can encode the same bits more densely, which makes it shorter to look at but no easier to say. It is still thirty-six characters of entropy.

Are UUIDs sortable by creation time?

Version 4 is not, which complicates pagination. Newer time-ordered variants exist precisely to fix this while keeping independent generation.

Do I need to store the hyphens?

No, they carry no information. Store the sixteen bytes if your database has a type for it, and add the hyphens when displaying.

Is a UUID secret?

No. It is unguessable, which is not the same thing. Check permissions as well.

Need an identifier that will not collide?

Generate a UUID