๐Ÿ†” UUID: The Complete Guide to Universally Unique Identifiers

From theory to practice โ€” understand every UUID version and how to use them correctly

What Is a UUID?

UUID stands for Universally Unique Identifier. It's a 128-bit number, typically displayed as 32 hexadecimal characters with 4 hyphens:

550e8400-e29b-41d4-a716-446655440000

Its core promise: every UUID you generate is globally unique โ€” no central server needed to coordinate, no collision checking required, generate and use. That's what "universally" unique means.

TL;DR: UUIDs are globally unique IDs that don't require central coordination. They're the standard choice for distributed systems.

UUID Versions: v1, v4, v5 โ€” What's the Difference?

UUID has multiple versions, each with a different generation algorithm. In practice, you only need to know these three:

VersionGeneration MethodCharacteristicsBest For
UUID v1 Timestamp + MAC address Sortable, leaks machine info Database primary keys (ordered), logging
UUID v4 Pure random Fully random, most common General-purpose unique IDs, session IDs, filenames
UUID v5 SHA-1 hash of namespace + name Deterministic โ€” same input = same UUID Generating fixed UUIDs from existing names

UUID v1: Timestamp Reveals When and Where

UUID v1's first half is a timestamp; the second half is your machine's MAC address. The upside: naturally ordered (database-index friendly). The downside: privacy โ€” anyone can reverse-engineer your MAC address and generation time from a v1 UUID. Avoid v1 unless you specifically need ordered IDs.

UUID v4: The Most Popular Choice

UUID v4 uses 122 random bits (6 bits are reserved for version and variant markers). This is the UUID you see everywhere:

a3bb189e-8bf9-4388-b5d3-0af2a0b8e1d1

This is the version our online tool generates. For the vast majority of use cases, v4 is the right choice โ€” simple, secure, and unique enough.

UUID v5: Deterministic UUIDs

UUID v5 uses SHA-1 hashing. You provide a namespace UUID + a name string, and it outputs a fixed UUID. Same input always produces the same output. Useful for "generate a stable UUID from an email address or URL" scenarios.

UUID Collision Probability: Can They Really Be Unique?

This is the #1 question. UUID v4 has 122 random bits, for a total of 2122 โ‰ˆ 5.3 ร— 1036 possible values.

Using the birthday paradox, to reach a 50% collision probability you'd need to generate 1 billion UUIDs per second, continuously, for 85 years.

The bottom line: In any real-world system, the chance of a UUID v4 collision is far lower than the chance of your server being struck by a meteorite. If you actually encounter a collision, check your random number generator for bugs before buying a lottery ticket.

When Should You Use UUIDs?

UUID vs Auto-Increment ID: How to Choose

AspectUUIDAuto-Increment ID
Global uniquenessโœ… GuaranteedโŒ Requires central coordination
Distributed-friendlyโœ… Generate anywhereโŒ Needs locks or sequences
Storage size16 bytes (128 bits)4โ€“8 bytes
Index performanceWorse (random writes)Excellent (sequential writes)
Info securityโœ… Doesn't reveal countโŒ Reveals data volume
ReadabilityPoor (long string)Good (short number)

Simple rule: Monolithic app, performance-sensitive โ†’ auto-increment. Distributed system, public-facing IDs โ†’ UUID. If you need both, check out ULID or Snowflake IDs (ordered and globally unique).

With or Without Hyphens?

Standard UUID format includes 4 hyphens: 550e8400-e29b-41d4-a716-446655440000. In storage, many people strip hyphens to 32 characters: 550e8400e29b41d4a716446655440000 โ€” saving 4 bytes and simplifying database indexing.

Our tool lets you toggle with one click: check "Keep hyphens" for standard format, uncheck for compact format.

๐Ÿ‘‰ Generate your UUIDs now

One-click UUID v4 generation, batch mode (1/5/10/20), hyphen toggle, one-click copy

๐Ÿ†” Open UUID Generator

FAQ

Q: How are UUID v4 random numbers generated?

In browsers, crypto.getRandomValues() (a cryptographically secure PRNG) is used. In Node.js, it's crypto.randomBytes(). Neither is truly "random," but both are more than secure enough for UUID generation.

Q: Why does the third group of a UUID always start with 4?

Because 4 is the UUID v4 version identifier. Similarly, the first character of the fourth group is always 8, 9, a, or b โ€” the variant identifier. If your UUID doesn't follow this pattern, it's not a standard v4 UUID.

Q: Can UUIDs be used as database primary keys? Is there a performance hit?

Yes, but with trade-offs. UUID randomness causes B+Tree index page splits and fragmentation, hurting write performance compared to auto-increment. If you must use UUIDs as primary keys, consider UUID v1 (time-ordered) or ULID. MySQL 8.0+ offers UUID_TO_BIN() to optimize UUID storage.

Q: What's the difference between UUID and GUID?

They're essentially the same thing. GUID (Globally Unique Identifier) is Microsoft's term for UUID. Technically identical โ€” 128 bits, same format, same version definitions.