f47ac10b-58cc-4372-a567-0e02b2c3d479 looks like a strange thing to use as an ID when a plain number like 1, 2, 3 would be so much shorter. But that strangeness is the entire point — UUIDs solve a specific problem that simple counting numbers can't.

What UUID actually stands for

UUID means Universally Unique Identifier — a 128-bit value, conventionally written as 32 hexadecimal characters grouped into five sections separated by hyphens: xxxxxxxx-xxxx-Mxxx-Nxxx-xxxxxxxxxxxx. The "M" position identifies which UUID version was used to generate it, and the "N" position encodes a related detail called the variant.

The problem it solves: generating IDs without central coordination

A traditional auto-incrementing ID (1, 2, 3, 4...) requires one central authority handing out the next number, which works fine for a single database, but breaks down the moment you have multiple independent systems that each need to generate IDs on their own, without checking in with each other first. Imagine three different microservices, each inserting new "order" records into their own local storage before syncing later. If they all used simple incrementing integers starting from 1, you'd get collisions immediately: three different orders, from three different services, all claiming to be "order #1."

UUIDs solve this by making the ID itself carry enough randomness (or, in some versions, enough unique input like a timestamp and machine identifier) that two independently generated UUIDs can be created at the same moment, on opposite sides of the planet, with no coordination between them, and still not collide.

The version that matters most today: UUID v4

There are several UUID versions, each generating the 128 bits differently, but version 4 is by far the most common in modern software. UUID v4 is (almost) pure randomness — of the 128 total bits, 122 are randomly generated, and the remaining 6 are fixed to identify the UUID as version 4 and set the correct variant. That's it. No timestamp, no machine address, no embedded information at all — just 122 bits of randomness.

Just how unlikely is a collision, really?

With 122 random bits, the number of possible UUID v4 values is 2122 — an almost incomprehensibly large number. To put it in perspective: to have even a 50% chance of one single collision occurring anywhere, you'd need to generate roughly 2.7 quintillion UUIDs. Generating a billion UUIDs a second, it would still take a meaningfully long time to reach even a small probability of a single collision. For essentially every real-world application — database keys, session tokens, file names, test data — the probability of an accidental collision is so far below the probability of, say, a hardware failure corrupting your data anyway, that it's not a practical concern.

Other UUID versions, briefly

When a UUID is the right choice

When a simple integer is still the better choice

UUIDs aren't free. They take 16 bytes of storage versus 4 or 8 for a typical integer, they're not naturally sortable by creation order (with v4 specifically), and being 36 characters long makes them slower to type, compare, and index at very large scale compared to a plain number. For a single, non-distributed database where you fully control ID generation and don't need to hide how many rows exist, a simple auto-incrementing integer is often still the simpler, more efficient choice.

The one-sentence version

A UUID trades a small amount of size and readability for the ability to generate a virtually guaranteed-unique ID anywhere, by anyone, with zero coordination required — and that trade is worth it exactly when coordination is the thing you don't have.

Frequently Asked Questions

Mathematically, yes it's possible, but the odds are so astronomically small (you'd need to generate roughly 2.7 quintillion of them for even a 50% chance of one collision) that it's not a realistic concern for virtually any real-world application.
It's a single digit embedded in a fixed position of the UUID (the first character of the third group) that identifies which algorithm generated it — version 4 for random, version 1 for timestamp-and-MAC-address-based, and so on. This lets systems interpret a UUID correctly based on how it was made.
For practical purposes, yes — GUID (Globally Unique Identifier) is Microsoft's name for essentially the same concept, and the two terms are used interchangeably in most contexts, though there are minor historical formatting differences in some implementations.
If you have a single, centrally controlled database and don't need to hide row counts or merge data from independent sources, a plain integer is often simpler and more storage-efficient. Reach for a UUID specifically when you need IDs generated independently, without coordination, across multiple systems.