GeneratePass
Cryptography • 8 min read

What Is a UUID and When Should You Use One?

By GeneratePass Developers | Published: June 15, 2026 | Last Updated: August 19, 2026

The Problem with Simple IDs

For decades, the default way to identify records was simple: auto-incrementing integers. Your first user gets ID 1, the second gets 2, and so on. It works perfectly — until it doesn’t.

Modern applications run across distributed databases, microservices, offline-first mobile apps, and serverless functions. When multiple systems generate records independently, auto-incremented integers break down:

  • Collisions: Two database shards inserting at the same time produce duplicate IDs.
  • Enumeration attacks: If your account page is /users/102, an attacker can try /users/103, /users/104, and so on.
  • Offline creation: A mobile app can’t assign a server-side ID when the user is offline.
  • Cross-service conflicts: Multiple microservices generating IDs independently will inevitably create duplicates.

UUIDs (Universally Unique Identifiers) solve all of these problems.


What Is a UUID?

A UUID is a 128-bit value designed to be globally unique. You can generate one on any device, at any time, without coordinating with anyone — and the chance of creating a duplicate is essentially zero.

A UUID looks like this:

550e8400-e29b-41d4-a716-446655440000

That’s 36 characters: 32 hexadecimal digits split into five groups by hyphens. The 128-bit value gives you 340 undecillion possible combinations ($3.4 \times 10^{38}$). To put that in perspective, you could generate a billion UUIDs every second for 85 years and still have only a 50% chance of seeing one duplicate.

You can generate UUIDs right now using our browser-based UUID Generator — everything runs locally in your browser, nothing is sent to a server.


When Should You Use a UUID?

UUIDs aren’t always the right choice, but they shine in specific scenarios:

Distributed databases and microservices

When independent services produce records that later merge into a central data warehouse, UUIDs guarantee no conflicts. Each service generates IDs locally with zero coordination.

Client-side and offline-first apps

Note-taking apps, field-service tools, and progressive web apps often let users create records offline. UUIDs let the client assign a unique ID immediately, with sync happening later.

Public-facing URLs and API resources

Using UUIDs in URLs like /orders/3482a5a1-5d2f-4c5e-881c-0b82f09d84bf prevents ID enumeration. Attackers can’t guess or iterate through UUIDs to access other users’ data.

Database sharding

When your database is split across multiple servers, UUIDs ensure records on different shards never collide.

Session tokens and API keys

Random UUIDs (version 4) work well as session identifiers and API keys. For stronger key generation, see our Password Generator or Secret Token Generator.


When Should You Avoid UUIDs?

UUIDs aren’t a universal solution. Consider the tradeoffs:

Database performance. Random UUIDs (v4) cause B-Tree index fragmentation in MySQL and PostgreSQL, slowing inserts by 30-50%. If insertion speed matters, use UUID v7 or sequential identifiers instead.

Storage overhead. A UUID takes 16 bytes as binary or 36 bytes as a string. An integer takes 4 bytes. At scale, this adds up.

Readability. UUIDs are long and hard for humans to read. If you need to read IDs aloud on a support call or type them manually, consider shorter formats.

No built-in ordering. UUID v4 tells you nothing about when a record was created. If you need chronological sorting, use UUID v7 (which embeds a timestamp) or store a separate timestamp column.


UUID vs. Other ID Formats

UUIDs are one option among many. Here’s how they compare to other popular ID formats:

FormatSizeSortableCollision ResistantOfflineHuman-Friendly
UUID (v4)128 bits (36 chars)NoYesYesLow
UUID (v7)128 bits (36 chars)Yes (lexicographic)YesYesLow
ULID128 bits (26 chars)Yes (lexicographic)YesYesMedium
NanoIDConfigurable (default 21 chars)OptionalYesYesHigh
CUID2ConfigurablePartialYesYesMedium
Auto-Increment INT32 bitsYesSingle DB onlyNoHigh

When to pick each one

Use UUID v4 when you need maximum randomness and don’t care about ordering — session tokens, API keys, and general-purpose identifiers.

Use UUID v7 when you need time-ordered IDs that also improve database insertion performance. It’s the modern default for new projects.

Use ULID when you want time-ordered IDs in a shorter, more readable format (26 characters vs. 36). ULIDs are case-insensitive and URL-friendly without needing hyphens. Try our ULID Generator.

Use NanoID when you need shorter, more readable IDs for user-facing contexts — URL shorteners, invite codes, referral links. The default is 21 characters but it’s configurable. Try our NanoID Generator.

Use CUID2 when you want a collision-resistant ID with some natural ordering properties and slightly better readability than UUIDs.

Use Auto-Increment when you have a single database, don’t need offline generation, and want the simplest, fastest, most storage-efficient option.

The key takeaway

There’s no single “best” ID format. The right choice depends on whether you need time ordering, how important readability is, whether you generate IDs offline, and how much storage overhead you can tolerate. For most new distributed applications, UUID v7 or ULID gives you the best balance of uniqueness, ordering, and compatibility.


Common UUID Mistakes

Even experienced developers make these mistakes when working with UUIDs:

Using UUID v1 in public-facing systems

UUID v1 embeds your server’s MAC address and exact creation timestamp. If exposed in API responses or URLs, this leaks infrastructure details and creation times to attackers. Use UUID v4 or v7 for anything public.

Treating UUIDs as secrets

A UUID is an identifier, not a secret. UUID v4 has enough entropy to resist brute-force guessing, but it’s not a replacement for proper authentication. Never use a UUID as a password, API secret, or encryption key. If you need a secret token, use our Secret Token Generator designed for that purpose.

Using UUIDs as authentication tokens

A UUID in a URL like /dashboard?session=550e8400-e29b-41d4-a716-446655440000 identifies a session — but it doesn’t authenticate the user. Always pair UUIDs with proper auth mechanisms (cookies, JWTs, OAuth). A UUID is a name, not a password.

Storing UUIDs as strings

Storing UUIDs as VARCHAR or TEXT columns wastes 2.25x more space than binary storage and slows down index lookups. Use your database’s native UUID type or BINARY(16). See our guide on UUID storage best practices for details.

Ignoring index fragmentation with UUID v4

If you use random UUIDs as primary keys in a high-write database, expect B-Tree page splits to slow down inserts. Switch to UUID v7, ULID, or store a separate sequential key alongside the UUID.


Want the Full Technical Deep Dive?

This guide covered the practical essentials — what UUIDs are, when to use them, and how they compare to alternatives. If you need the technical details, read our Complete UUID Guide which covers:

  • All eight UUID versions (v1 through v8) with structure breakdowns
  • Collision probability math with the birthday paradox
  • Entropy analysis and version comparison tables
  • Storage efficiency benchmarks
  • Implementation code samples in JavaScript, Python, Go, and SQL
  • Production best practices

See Also

  • UUID Guide — Deep dive into UUID versions v1 through v8, with comparisons, use cases, and generation tools.
  • UUID Generator — Generate UUID v4 and v7 instantly in your browser.
  • ULID Generator — Generate time-ordered unique identifiers.
  • NanoID Generator — Generate shorter, URL-friendly IDs.
  • Username Generator — Generate unique usernames for professional, gaming, and developer use cases.

GeneratePass Developers

Developers of GeneratePass, building client-side security tools and educational content focused on local execution, zero-trust patterns, and client-side data sovereignty.

Focus: Cryptography • Standard: zero-trust