BuildUtilities

UUIDs Explained

What is a UUID?

A UUID (Universally Unique Identifier) is a 128-bit identifier formatted as 32 hex digits separated by hyphens: 550e8400-e29b-41d4-a716-446655440000. UUIDs are designed to be unique across space and time without a central registry.

UUID Versions

v1. Time-based

Uses timestamp + MAC address. Predictable but sortable.

v4. Random

122 random bits. Most widely used. Collision probability is negligible.

v7. Time-ordered Random

Unix timestamp prefix + random. Sortable by creation time, ideal for database primary keys.

When to Use UUIDs

  • Primary keys in distributed databases
  • API resource identifiers
  • Session tokens and correlation IDs
  • File naming to avoid collisions

Common Mistakes

  • Using UUIDs as security tokens: v1 UUIDs are predictable. Use cryptographic random tokens instead.
  • Performance in databases: Random v4 UUIDs cause index fragmentation. Consider v7 or ULID for sorted inserts.

Generate UUIDs instantly with our UUID Generator.

FAQ

Can two UUIDs collide?

For v4, you'd need to generate 2.71 × 10¹⁸ UUIDs for a 50% collision probability. In practice, collisions don't happen.

UUID vs ULID vs nanoid?

UUIDs are standardized and widely supported. ULIDs are sortable and URL-safe. Nanoid is smaller and faster for non-standard use cases.

Can I just ask an AI model for a UUID?

Not safely. A language model has no entropy source, so it produces text shaped like a UUID drawn from patterns it has seen — which means the same value can come back in different sessions, and some are lifted from public code samples. Anything relying on uniqueness needs a real random source. Our MCP server exists partly for this: it lets an AI agent call the OS random generator instead of guessing.

Try These Tools

Related Documentation

Tip Jar