UUID Generator

Generate random version 4 UUIDs for databases, APIs and keys.

A UUID is a 128-bit identifier you can generate anywhere, on any machine, without asking a central authority whether it is taken. That property — no coordination required — is what makes them so useful in distributed systems.

Generating UUIDs

  1. Press generate to produce a new version 4 UUID.
  2. Generate several at once if you need a batch.
  3. Copy the value straight into your code, migration or config.
  4. Use lowercase hexadecimal, which is the conventional format.
  5. Store it as a native UUID type where your database supports one.

Why collisions are not something to worry about

A version 4 UUID has 122 random bits, which yields roughly 5.3 × 10³⁶ possible values. To reach a 50% chance of a single collision you would need to generate about 2.7 × 10¹⁸ of them.

Put in practical terms: generating a billion UUIDs every second for a hundred years leaves the probability of any collision vanishingly small. For any application you are likely to build, treat uniqueness as guaranteed.

The versions you will encounter

  • Version 4 — purely random. The default choice, and what this generator produces.
  • Version 1 — based on timestamp and MAC address. Sortable, but it leaks the machine identity and the time of creation.
  • Version 7 — timestamp-prefixed and random. Sortable like v1 without the privacy problem, and increasingly the recommended choice for database keys.
  • Nil UUID — all zeroes. Used as a placeholder or a null sentinel.
  • GUID — Microsoft’s name for the same thing. The formats are compatible.

Using UUIDs as primary keys: the trade-offs

  • You can generate the ID before the row exists, which simplifies a great deal of application code.
  • IDs do not leak business information the way sequential integers do.
  • Merging data from multiple sources becomes trivial, with no key conflicts.
  • Random v4 keys fragment B-tree indexes, because inserts land in random places.
  • They use 16 bytes against 4 or 8 for an integer, which adds up across large tables and every index that references them.

UUID questions

Are UUIDs guaranteed to be unique?

Not mathematically guaranteed, but the probability of a collision is so small it can be treated as zero for every practical purpose. You are far more likely to hit a hardware failure than a duplicate UUID.

Should I use a UUID or an auto-increment integer for a primary key?

Integers are smaller and index better. UUIDs let you create IDs client-side, avoid exposing row counts, and merge across systems painlessly. If you want both, UUID v7 sorts by time and largely solves the index fragmentation problem.

What is the difference between a UUID and a GUID?

None of substance. GUID is Microsoft’s terminology for the same 128-bit identifier, and the two are interchangeable in practice.

Can a UUID be used as a security token?

A version 4 UUID from a cryptographically secure source is unguessable, but it is not designed as a secret and it is often logged and exposed in URLs. For authentication tokens, use a purpose-built secure random token instead.

Is the UUID generated here random enough?

Yes. It is generated on our server with a cryptographically secure random number generator, the same kind of source used for keys and tokens, rather than a simple pseudo-random function.

Cookie
We care about your data and would love to use cookies to improve your experience.