Skip to content
Software and the Internet

What is UUID (GUID): versions, generation, and collisions

AuthorEditorial team 9-07-2026, 00:09 824
What is UUID (GUID): versions, generation, and collisions
Advertising
In brief
  • UUID (also known as GUID) is a 128-bit identifier consisting of 32 hexadecimal characters, written as 8-4-4-4-12, for example 550e8400-e29b-41d4-a716-446655440000.
  • The main point is to generate unique keys locally, without referring to a server or a global counter, which is convenient for distributed systems, APIs, and offline clients.
  • The most popular versions are: v4 (random), v1 (time and MAC), v5 (name and SHA-1 hash), as well as the new v7 (time-sortable) and ULID-like variants.
  • The probability of collision for v4 is astronomically low: to have one chance of a match, billions of identifiers need to be generated every second for decades.

When multiple servers appear in the application, mobile clients work offline, and data merges from different sources, the usual auto-incrementing id in the database quickly becomes a bottleneck: two nodes can easily assign the same number to two different records. UUID solves this problem radically — it allows any participant in the system to create a guaranteed unique identifier right on their end, without asking for permission from the central database. In this article, we will discuss what UUID and GUID are, how the versions differ, where to apply them, how to generate the required variant, and why collisions can be virtually ignored.

UUID generator
Generate UUID/GUID online — for free
Open the generator →

What is UUID and GUID

UUID (Universally Unique Identifier) is a 128-bit value described in the RFC 4122 standard and updated in RFC 9562. GUID (Globally Unique Identifier) is the same thing, just historically referred to as such by Microsoft in the Windows and .NET ecosystem. There is no difference in format: both consist of 128 bits and are usually represented as 36 characters — 32 hexadecimal digits, separated by hyphens into groups. 8-4-4-4-12.

Example: 3f2504e0-4f89-41d3-9a0c-0305e82c3301. Inside the string, there are encoded fields — the version number (which indicates how the identifier was generated) and the variant (how to interpret the bits). In total, the UUID space contains 2 to the power of 128 values — approximately 3.4 × 10 to the power of 38 combinations, a number that is hard to even imagine.

Why UUID is needed: databases and APIs

The main value of UUID is generation independence. An identifier can be created on the client, on any of the servers, or in a background task, and it will not collide with another. This provides several practical benefits:

В distributed databases and sharded tables do not require a single counter — each node generates keys on its own. In REST and GraphQL API the client can form id create a new entity in advance and send it along with the request for creation, which simplifies idempotency and retries. When merging data from different systems (migration, synchronization, import), records do not conflict by key. UUID also does not reveal the order and number of records: you cannot guess that there were exactly 42 orders in the database before you, unlike a sequential numeric id.

UUID versions and how they differ

The standard describes several versions, and the choice affects performance and predictability:

Version 4 (random) — is the most popular. 122 bits are taken from a cryptographically secure random number generator. Simple, environment-independent, does not reveal the creation time. The downside is that values are scattered randomly, which hinders indexing in some DBMS.

Version 1 (time-based) — is built from the current time and the MAC address of the network card. Practically unique and contains a timestamp, but may reveal information about the device and the moment of generation.

Versions 3 and 5 (by name) — deterministic: the same input name and namespace always produce the same UUID (v3 via MD5, v5 via SHA-1). Useful when a stable identifier for a known string is needed, for example for a URL.

Version 7 (time-sortable) — a new feature from RFC 9562. The higher bits contain Unix time in milliseconds, followed by randomness. This UUID increases over time, making it well-suited for B-tree indexes and replacing custom schemes like ULID. For new projects with UUID as the primary key, v7 is often the best choice today.

How to generate a UUID

Ready-made functions are available almost everywhere, there's no need to invent your own:

JavaScript (browser and Node): crypto.randomUUID() — will return a v4 string. Python: module uuid — uuid.uuid4(), uuid.uuid1(), uuid.uuid5(ns, name). PHP: library ramsey/uuid — Uuid::uuid4(). Java: UUID.randomUUID(). PostgreSQL: type uuid and function gen_random_uuid(). Linux command line: utility uuidgen. Windows PowerShell: [guid]::NewGuid().

If a UUID is needed once — for testing, configuration, record key, or database seeding — the fastest way is to take a ready-made value from an online generator and copy it. An important rule: always use a cryptographically secure source for random versions (that's why crypto.randomUUID preferred Math.random).

Collision probability: should you be worried?

A collision occurs when two independently generated UUIDs happen to match. For version 4, there are 2 to the power of 122 possible values, and the probability is estimated through the birthday paradox. To reach a 50% chance of at least one match, about 2.7 × 10 to the power of 18 identifiers need to be generated. In practice, this means that even if a billion UUIDs are created per second, it would take decades of continuous operation to accumulate such a number. For the vast majority of systems, the risk of collision is negligibly small and can be safely ignored.

Real problems usually lie not in the mathematics but in the implementation: a weak random number generator (non-cryptographic), reused seed, copying the same UUID due to a coding error. If the source of randomness is of high quality, you won't see duplicates under normal conditions.

Frequently Asked Questions

Are UUID and GUID the same thing?
Yes, essentially they are synonyms. GUID is the name used in the Microsoft and .NET world, while UUID is a term from RFC standards. Their format and length (128 bits, represented as 8-4-4-4-12) are identical, and there are no differences in structure.

Which version of UUID should be chosen for a primary key in a database?
For new projects, version 7 is convenient: it is time-sorted and friendly to indexes. If such support is not available, version 4 is chosen for its simplicity and lack of metadata leakage. Versions 1, 3, and 5 are used for specific tasks.

Can two UUIDs collide?
Theoretically yes, practically — almost never. With a proper cryptographic generator, the collision probability for v4 is so low that it is disregarded for real data volumes. Problems only arise with a weak source of randomness.

Is it possible to generate a UUID manually or online?
Yes. Every programming language has a built-in function (crypto.randomUUID(), uuid4(), gen_random_uuid()), and for a one-time task, it's easier to use an online generator and copy the ready-made value. The main thing is not to invent bits by hand to maintain uniqueness.

UUID generator
Generate UUID/GUID online — for free
Open the generator →

Updated: July 9, 2026. Edition of MegaInet.art.

How useful is the material?Evaluation helps us choose topics
00 ratings

Discussion

No one has spoken yet — be the first.

Comments are written by participants Log in to the site — it's free and takes a minute. Comments are moderated.
Log in
Advertising