ToolPopToolPop
Back to BlogGuides

The Complete Developer's Guide to UUIDs and GUIDs

UUIDs are fundamental to distributed systems and modern databases. This guide covers everything developers need to know about generating and using unique identifiers.

ToolPop TeamMarch 1, 202516 min read

Understanding Unique Identifiers

UUIDs (Universally Unique Identifiers) and GUIDs (Globally Unique Identifiers) are 128-bit numbers used to uniquely identify information in computer systems. While technically identical, UUID is the term used in the official RFC specification, while GUID is Microsoft's terminology.

Why UUIDs Matter

In distributed systems, databases, and modern architectures, the need for unique identifiers that can be generated independently across different systems is critical:

  • Database primary keys that don't conflict when merging data
  • Distributed systems where nodes generate IDs without coordination
  • API resources that need permanent, unique identifiers
  • Session and transaction tracking across microservices
  • File and object naming in cloud storage

The Format

A UUID is a 128-bit number represented as 32 hexadecimal digits, displayed in five groups separated by hyphens:

xxxxxxxx-xxxx-Mxxx-Nxxx-xxxxxxxxxxxx

Where:

  • M indicates the UUID version (1-5)
  • N indicates the variant (typically 8, 9, A, or B for RFC 4122)
Example: 550e8400-e29b-41d4-a716-446655440000

UUID Versions Explained

Version 1: Timestamp + MAC Address

Version 1 UUIDs combine the current timestamp with the MAC address of the generating computer.

Structure:

  • 60-bit timestamp (100-nanosecond intervals since October 15, 1582)
  • 14-bit clock sequence (for uniqueness if clock moves backward)
  • 48-bit node ID (typically MAC address)
Characteristics:
  • Time-based: Yes
  • Sortable: Partially (not naturally due to byte ordering)
  • Privacy: Low (exposes MAC address and generation time)
  • Collision risk: Very low
  • Generation: Can be sequential from same machine
Use Cases:
  • Legacy systems requiring timestamp ordering
  • Systems where generation source tracking is beneficial
  • Single-machine batch processing
Concerns:
  • Exposes MAC address (privacy/security risk)
  • Reveals generation time
  • Not ideal for user-facing IDs

Version 4: Random

Version 4 UUIDs are generated using random or pseudo-random numbers.

Structure:

  • 122 random bits
  • 4 version bits
  • 2 variant bits
Characteristics:
  • Time-based: No
  • Sortable: No
  • Privacy: High (reveals nothing)
  • Collision risk: 2.71 quintillion UUIDs for 50% collision chance
  • Generation: Random, unpredictable
This is the most commonly used version.

Use Cases:

  • Database primary keys
  • API resource identifiers
  • Session IDs
  • General-purpose unique identification
Collision Probability:
  • Generating 1 billion UUIDs per second
  • Would take 85 years for 50% collision probability
  • In practice, collisions are negligible

Version 5: SHA-1 Hash

Version 5 generates UUIDs by hashing a namespace identifier and name using SHA-1.

Characteristics:

  • Time-based: No
  • Deterministic: Yes (same input = same output)
  • Collision risk: Lower than V3 (SHA-1 > MD5)
  • Generation: Reproducible
Preferred over V3 for new applications.

Version 7: Unix Timestamp + Random

RFC 9562 introduced Version 7, optimized for modern needs:

  • 48-bit Unix timestamp (milliseconds)
  • 74 random bits
  • Naturally sortable by time
  • No privacy concerns
Version 7 is recommended for new applications requiring sortable UUIDs.

Choosing the Right UUID Version

Decision Matrix

RequirementRecommended Version
General purposeVersion 4
Time-sortableVersion 7
Deterministic from nameVersion 5
Legacy compatibilityVersion 1
Maximum randomnessVersion 4
Database optimizationVersion 7

Database Considerations

UUID v4 in Databases:

  • Random distribution
  • Poor index locality (B-tree fragmentation)
  • Higher storage than integer IDs
  • Good for security (unpredictable)
UUID v7 in Databases:
  • Sequential-ish ordering
  • Better index performance
  • Natural time ordering
  • Recommended for new applications

UUID Best Practices

Storage

Storage Size Comparison:

FormatSize
String (with hyphens)36 bytes
String (without hyphens)32 bytes
Binary16 bytes
For databases, store as binary (16 bytes) when possible for efficiency. PostgreSQL has a native UUID type. MySQL 8+ has UUID_TO_BIN and BIN_TO_UUID functions.

Validation

UUID regex pattern validates the format: 8-4-4-4-12 hexadecimal digits with version 1-7 and variant 8, 9, A, or B.

URL-Safe UUIDs

Remove hyphens for compact representation, or use Base64 encoding (22 characters) for even shorter URLs.

Nil UUID

The nil (or empty) UUID consists of all zeros: 00000000-0000-0000-0000-000000000000

Use for representing "no value" or as a placeholder.

UUID vs. Alternatives

Auto-Increment IDs

Advantages of Auto-Increment:

  • Smaller storage (4-8 bytes)
  • Natural ordering
  • Simple to understand
  • Better index performance (traditionally)
Disadvantages:
  • Requires central coordination
  • Reveals count/order information
  • Difficult to merge databases
  • Sequential = predictable

ULIDs

ULID (Universally Unique Lexicographically Sortable Identifier):

  • 128-bit compatible with UUID
  • Lexicographically sortable
  • Case-insensitive
  • No special characters
  • 26 characters (Crockford Base32)

NanoID

  • URL-safe by default
  • Customizable length
  • 21 characters default
  • Smaller than UUID
  • Not UUID-compatible

Comparison Table

FeatureUUID v4UUID v7ULIDSnowflakeNanoID
Size128-bit128-bit128-bit64-bitVariable
SortableNoYesYesYesNo
Time infoNoYesYesYesNo
Collisions~0~0~0Coordinated~0
URL-safeNoNoYesYesYes

Security Considerations

When UUIDs Are Not Enough

UUIDs should not be considered secrets:

  • V1 exposes MAC address and time
  • V4 randomness depends on entropy source
  • Guessing a specific UUID is hard, but checking if one exists may not be
For sensitive operations, combine UUIDs with:
  • Authentication/authorization checks
  • Rate limiting
  • Additional secret tokens
  • Audit logging

Timing Attacks

UUID v1 and v7 expose generation time. Consider this when choosing UUID versions for sensitive applications.

ToolPop UUID Generator

Generate UUIDs instantly with ToolPop:

  • Choose version (v1, v4, v5, or v7)
  • Generate single or bulk UUIDs
  • Copy or download results
  • Validate existing UUIDs

Features

  • Multiple UUID versions
  • Bulk generation (up to 1000)
  • Format options (standard, compact, base64)
  • Validation tool
  • Timestamp extraction (v1, v7)

Conclusion

UUIDs are foundational to modern distributed systems. Understanding the different versions and their characteristics helps you make informed decisions:

  • Use UUID v4 for general-purpose, random identifiers
  • Use UUID v7 for sortable, time-ordered identifiers
  • Use UUID v5 for deterministic generation from names
  • Consider alternatives like ULID or NanoID for specific requirements
The right choice depends on your specific needs: sortability, storage efficiency, security requirements, and system architecture.

Generate UUIDs instantly with ToolPop's UUID Generator—supporting all versions with bulk generation and validation.

Tags
UUIDGUIDunique identifierUUID generatorUUID versionsdistributed systemsdatabase IDs
Share this article

Try Our Free Tools

Put these tips into practice with our free online tools. No signup required.

Explore Tools