How to Generate UUID/GUID: Complete Guide

Utilko Team 4 min read Developer

What Is a UUID?

A UUID (Universally Unique Identifier), sometimes called a GUID (Globally Unique Identifier), is a 128-bit number used to uniquely identify information in computer systems. A standard UUID looks like this:

550e8400-e29b-41d4-a716-446655440000

It is composed of 32 hexadecimal digits displayed in five groups separated by hyphens, following the 8-4-4-4-12 format. The total number of possible UUIDs is approximately 3.4 × 1038, making collisions virtually impossible.

Why Use UUIDs?

UUIDs solve a fundamental problem in distributed systems: generating unique identifiers without a central authority. They are used for:

  • Database primary keys — especially in distributed databases where auto-increment IDs can collide across nodes.
  • Session and token identifiers — ensuring each session or API key is unique.
  • File and resource naming — uploaded files, cache keys, and temporary resources.
  • Message and event IDs — deduplication in event-driven architectures and message queues.

UUID Versions Explained

UUID v1 — Timestamp + MAC Address

Combines the current timestamp with the MAC address of the generating machine. It guarantees uniqueness but reveals the time and hardware identity, which may be a privacy concern.

UUID v4 — Random

Generated from random or pseudo-random numbers. This is the most commonly used version because it is simple, fast, and does not leak any information. The probability of a collision is astronomically low.

UUID v5 — Name-Based (SHA-1)

Deterministically generated from a namespace and a name using SHA-1 hashing. Given the same inputs, you always get the same UUID, which is useful for reproducible identifiers.

UUID v7 — Timestamp-Ordered Random

A newer format (RFC 9562) that embeds a Unix timestamp in the most significant bits, making UUIDs sortable by creation time while still being random enough to avoid collisions. This is gaining popularity for database keys because it preserves insert order.

How to Generate a UUID

Online

The fastest way is to use a free online generator. Paste the result directly into your code, database, or configuration file.

Try It Now

Use our free UUID Generator to create v4 UUIDs instantly in your browser.

UUID Generator →

In Code

  • JavaScript: crypto.randomUUID() (built-in since Node 19+ and modern browsers)
  • Python: import uuid; str(uuid.uuid4())
  • Java: UUID.randomUUID().toString()
  • Command line: uuidgen (available on macOS and Linux)

UUID vs Auto-Increment IDs

Auto-increment integers are smaller (4–8 bytes vs 16 bytes) and human-readable, but they require a central sequence and expose record counts. UUIDs are larger but work in distributed environments without coordination. Choose based on your architecture needs.

Best Practices

  1. Use UUID v4 as the default for most applications.
  2. Consider UUID v7 if you need time-ordered keys for database performance.
  3. Store UUIDs as binary(16) in databases rather than varchar(36) to save space and improve indexing.
  4. Always generate UUIDs using a cryptographically secure random source.

Conclusion

UUIDs are an essential tool for generating unique identifiers in modern software. Whether you need a quick one-off ID or millions of keys for a distributed database, understanding UUID versions helps you pick the right one. Generate yours instantly with our UUID Generator.

Tools Mentioned in This Article