OhMyApps
Back to Blog
Tools Developer UUID Database Tutorial

UUID Generator: Create Unique Identifiers Instantly

4 min read By OhMyApps

UUIDs (Universally Unique Identifiers) are 128-bit identifiers that are practically guaranteed to be unique across space and time. They’re used everywhere — database primary keys, API request IDs, session tokens, file names, and distributed system identifiers.

What is a UUID?

A UUID is a 128-bit number typically displayed as 32 hexadecimal characters separated by hyphens:

550e8400-e29b-41d4-a716-446655440000
    |      |    |    |        |
    8     4    4    4       12 characters

The format is 8-4-4-4-12 for a total of 36 characters (32 hex digits + 4 hyphens).

UUID Versions

Version 4 (Random)

The most commonly used version. Generated from random numbers using a cryptographically secure random number generator.

xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx
                ^   ^
                |   └── y is 8, 9, a, or b (variant)
                └── Always 4 (version)
  • Pros: Simple, no dependencies, no coordination needed
  • Cons: No inherent ordering, not sortable by creation time
  • Use when: You need a unique ID and don’t care about ordering

Version 1 (Timestamp + MAC)

Based on the current timestamp and the machine’s MAC address.

  • Pros: Sortable by time, guaranteed unique per machine
  • Cons: Exposes MAC address and creation time (privacy concern)

Version 7 (Unix Timestamp, newest)

A newer standard (RFC 9562) that embeds a Unix timestamp in the first 48 bits, followed by random data.

  • Pros: Time-sortable, database-friendly, privacy-safe
  • Cons: Newer standard, not yet universally supported
  • Use when: You need sortable IDs for database primary keys

Why Use UUIDs?

Database Primary Keys

UUIDs allow generating IDs on the client side without coordinating with the database:

INSERT INTO users (id, name) VALUES ('550e8400-e29b-41d4-a716-446655440000', 'Alice');

No auto-increment conflicts in distributed systems.

API Idempotency Keys

Include a UUID with each API request to prevent duplicate processing:

POST /api/payments
X-Idempotency-Key: 7c9e6679-7425-40de-944b-e07fc1f90ae7

Distributed Systems

When multiple services generate IDs independently, UUIDs prevent collisions without a central coordinator.

File Names

Ensure uploaded files never overwrite each other:

uploads/7c9e6679-7425-40de-944b-e07fc1f90ae7.png

UUID vs Other ID Strategies

StrategyProsCons
Auto-incrementSimple, sortable, compactCentralized, predictable, exposes count
UUID v4Distributed, unpredictableLarge (36 chars), not sortable
UUID v7Distributed, sortable36 characters, newer standard
ULIDSortable, compact (26 chars)Less widely supported
Snowflake IDSortable, 64-bitRequires coordination (machine ID)
NanoIDCompact, customizableNot standardized

How to Use Our UUID Generator

  1. Click Generate to create a new UUID v4
  2. Copy the UUID with one click
  3. Choose a format: lowercase, uppercase, with braces, or without hyphens
  4. Generate in bulk — specify a count to generate multiple UUIDs at once

Format Options

FormatExample
Lowercase (default)550e8400-e29b-41d4-a716-446655440000
Uppercase550E8400-E29B-41D4-A716-446655440000
With braces{550e8400-e29b-41d4-a716-446655440000}
No hyphens550e8400e29b41d4a716446655440000

Bulk Generation

Need multiple UUIDs? Set the count (up to 100) and generate them all at once. Each one is cryptographically random and unique.

UUID Collision Probability

With UUID v4, the probability of generating a duplicate is astronomically low. You’d need to generate:

  • 1 billion UUIDs per second
  • For 86 years
  • To reach a 50% probability of a single collision

In practical terms: UUID collisions don’t happen.

Frequently Asked Questions

Are UUIDs truly unique? UUID v4 uses 122 random bits, giving 5.3 × 10³⁶ possible values. While collisions are theoretically possible, the probability is negligible for any real-world application.

Should I use UUIDs as database primary keys? UUIDs work well as primary keys, especially in distributed systems. However, random UUIDs (v4) can cause index fragmentation in B-tree databases. Consider UUID v7 or ULID for better index performance.

Can someone guess a UUID? UUID v4 uses cryptographically secure random numbers. Guessing a specific UUID is computationally infeasible — there are more possible UUIDs than atoms in the observable universe.

What’s the storage size? As a string: 36 bytes. As binary (16 bytes): more efficient for databases. Most databases have a native UUID type that stores them as 16 bytes.


Try our free UUID Generator to create unique identifiers instantly.

Try Ghost Image Hub

The Chrome extension that makes managing your Ghost blog images a breeze.

Learn More