🌐 Blog

What is a UUID v4 and when to use it

by Toolonium Team · · 7 min read

When you need a unique identifier and do not want to ask the database for the next number every time, the UUID solves the problem. This guide explains what a UUID v4 is, how it is built, when to use it, and how it differs from an auto-increment ID.

1. The problem it solves

Imagine two servers creating records at the same time, without talking to each other. How do you guarantee their identifiers do not clash? The UUID lets you generate an identifier that is unique without central coordination: each side creates its own and, in practice, they never match.

2. What a UUID v4 is

A UUID (Universally Unique Identifier) is a 128-bit identifier. It is shown as 32 hexadecimal digits in five groups:

550e8400-e29b-41d4-a716-446655440000

Version 4 is the most used: it is almost completely random. Of its 128 bits, 122 are generated at random; the other 6 set the version and variant.

3. Anatomy

  • 128 bits total.
  • 4 bits indicate the version (the 4 digit in the third group).
  • 2 bits indicate the variant.
  • 122 bits left: random.

That means nothing about your machine or the time is encoded inside: a UUID v4 does not reveal when or where it was created.

4. When to use it

  • Primary keys in distributed databases.
  • Request IDs to trace a request in your logs.
  • File names that are unique without querying anything.
  • Reference tokens that are not secret.

5. Why they almost never collide

With 122 random bits, the space of possibilities is so huge that the probability of generating two equal ones is negligible. You would have to produce billions per second for years for a collision to be even likely.

6. UUID vs auto-increment ID

UUID v4Auto-increment ID
GenerationOn the client, no DBThe DB assigns the next
CoordinationNot neededNeeded
Leaks countNoYes (reveals volume)
Size128 bits32–64 bits
OrderNot orderedOrdered

Generate a UUID v4 instantly — created with your browser’s cryptographic generator, 100% local, nothing is uploaded → open the UUID generator

7. Privacy: generated in your browser

A good generator uses the browser’s cryptographic API (crypto.getRandomValues), which produces quality randomness. Because it is generated locally, the identifier never leaves your device.

If you work with data integrity as well as identifiers, you may want to read what is SHA-256.

8. Summary

A UUID v4 is a 128-bit identifier, almost entirely random, that you can generate without central coordination and that in practice never collides. It is ideal for distributed keys, request IDs and file names, at the cost of more space than an auto-increment and no ordering. To get one instantly and locally, use the generator.

Frequently asked questions

What is a UUID?

A UUID (Universally Unique Identifier) is a 128-bit identifier designed to be unique without central coordination. It is written as 32 hexadecimal digits in 5 groups separated by hyphens, for example 550e8400-e29b-41d4-a716-446655440000.

What is special about version 4?

A UUID v4 is almost entirely random: 122 of its 128 bits are generated at random. It does not depend on the time or the MAC address like other versions, which makes it simple and suitable when you just need an unpredictable unique identifier.

Can UUID v4 values collide?

In theory yes, but the probability is so low it is ignored in practice. With 122 random bits you would have to generate billions of UUIDs per second for years for a collision to be even likely.

UUID or auto-increment ID?

Auto-increment is short and ordered, but it reveals record volume and needs database coordination. A UUID can be generated on the client without querying the DB and leaks no count information, at the cost of more space.

Is it safe to generate a UUID in the browser?

Yes. A good generator uses the browser's cryptographic API (crypto.getRandomValues), which produces quality randomness. And if it is generated locally, the identifier never leaves your device.

Related articles

Back to blog