UUID Generator

Generate random UUIDs (Universally Unique Identifiers) for use in databases, APIs, and software development.

Generator Settings

Generated UUIDs

Click "Generate UUIDs" to create new UUIDs

UUIDs Generated
0
Version
V4

What Is a UUID?

A UUID (Universally Unique Identifier) is a 128-bit label used to uniquely identify objects or entities in computer systems. Standardized by RFC 4122 and ISO/IEC 9834-8, a UUID is represented as 32 lowercase hexadecimal digits grouped into five segments separated by hyphens, following the pattern 8-4-4-4-12 (for example: 550e8400-e29b-41d4-a716-446655440000). The total identifier encodes 128 bits of data in a compact, human-readable text format.

The key property of a UUID is practical uniqueness: when generated correctly, the probability of two independently created UUIDs colliding is so astronomically small that it is treated as impossible for virtually all engineering purposes. This makes UUIDs ideal for distributed systems where multiple nodes must create unique identifiers without any central coordination or locking mechanism.

UUIDs appear everywhere in modern software: database primary keys, REST API resource identifiers, session tokens, file system objects, message queue message IDs, configuration values, and more. Because they carry no sequential or geographical information by design (in the random versions), they also help prevent certain classes of data enumeration attacks in web APIs.

The identifier space contains 2128 possible values — approximately 3.4 × 1038 — a number so large that even generating one billion UUIDs per second for the entire lifetime of the universe would consume only a negligible fraction of the available space.

UUID v4: Random Generation Algorithm

UUID version 4 is the most widely used UUID type in modern software development. It is generated almost entirely from random (or pseudo-random) bits, making it the right choice whenever you need a quick, self-contained unique identifier that carries no time or node information.

The algorithm fills a 128-bit template with random hex digits, then fixes two specific fields to mark the version and variant. The version nibble (bits 12–15 of the third group) is set to 4, and the two most significant bits of the fourth group's first byte are set to 10 in binary (producing a hex digit of 8, 9, a, or b). All remaining 122 bits are independently random, giving each generated UUID an astronomically low collision probability.

In this generator, UUID v4 values are created using JavaScript's Math.random() function seeded by the browser's internal PRNG, then formatted according to the RFC 4122 template. For cryptographically sensitive use cases (such as security tokens), a cryptographically secure RNG like crypto.randomUUID() is recommended instead.

UUID v4 Generation Formula

Template: xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx

Where:

  • x= Random hexadecimal digit 0–f, computed as (Math.random() * 16 | 0).toString(16)
  • 4= Fixed version digit — marks this as UUID version 4 (random)
  • y= Variant digit computed as (r & 0x3 | 0x8).toString(16), constrained to {8, 9, a, b} (sets top 2 bits to 10 binary, RFC 4122 variant)
  • 128 bits= Total identifier size: 122 random bits + 4 version bits + 2 variant bits

UUID v1: Time-Based Identifiers

UUID version 1 generates identifiers by combining the current timestamp with additional random data. The version field in the third segment is set to 1, and the timestamp from Date.now() is mixed into the random hex computation using the formula (now + Math.random() * 16) % 16 | 0. This creates identifiers that are temporally correlated — UUIDs generated closer together in time will share some structural similarity in their lower bits.

The original RFC 4122 UUID v1 specification intended to embed the full 60-bit Gregorian timestamp (in 100-nanosecond intervals since October 15, 1582) plus the MAC address of the generating node. This generator uses a simplified time-based approach that mixes Date.now() (millisecond precision) with random noise, making it suitable for most development and testing purposes while avoiding the privacy concerns of exposing your MAC address.

UUID v1 is useful when you want generated identifiers to be roughly sortable by creation time, which can improve database index locality. However, many teams avoid true v1 UUIDs in public APIs because the embedded timestamp and MAC address can reveal when and where a record was created. UUID v4 or UUID v7 (a newer monotonic time-ordered standard) are generally preferred for new projects.

Nil UUID: The Zero UUID

The Nil UUID is a special-case UUID defined in RFC 4122 as all 128 bits set to zero: 00000000-0000-0000-0000-000000000000. It is not randomly generated — it is a fixed constant used as a sentinel value or placeholder in software systems.

Common uses for the nil UUID include representing "no value" or "not yet assigned" in a UUID-typed database column, serving as a default value in data structures before a real UUID is assigned, acting as a null check in APIs that always return a UUID field (returning nil instead of null), and testing or seeding scenarios where a known, predictable UUID value is needed.

The nil UUID is always identical regardless of when or where it is generated, which distinguishes it completely from v1 and v4 UUIDs. If you need to check whether a UUID slot has been populated with a real identifier, comparing against the nil UUID is a clean, standards-compliant approach.

When and Why to Use UUIDs

UUIDs solve one of the fundamental challenges in distributed computing: generating unique identifiers without a central authority. Any node in a distributed system can generate a UUID independently and be confident it will not clash with identifiers created by other nodes, past or future.

In databases, UUIDs serve as primary keys when auto-incrementing integers are problematic. They prevent enumeration attacks (sequential integer IDs let attackers guess adjacent record IDs), enable safe database sharding across multiple servers, and allow records to be created client-side before they are persisted. The tradeoff is slightly larger storage (16 bytes vs. 4–8 bytes for integers) and potential index fragmentation with random UUIDs.

In REST APIs, UUIDs are the standard choice for resource identifiers. A URL like /api/orders/3f2a1b4c-... carries no sequential information that would let a client guess other order IDs. Version 4 UUIDs are especially appropriate here because they are purely random.

For session tokens and security contexts, UUID v4 values (ideally from a CSPRNG) provide sufficient entropy for non-security-critical tokens. For authentication tokens and cryptographic credentials, purpose-built token generators or libraries like crypto.randomUUID() are preferred.

UUIDs also appear in event sourcing (each event gets a UUID), message queues (deduplication by message ID), file uploads (UUID-named files avoid collisions on shared storage), and configuration management (unique IDs for deployed services, containers, and VMs).

UUID Version Based On Best Use Case Privacy
v4 (Random) 122 random bits API IDs, DB keys, general use High — no info leaked
v1 (Time) Timestamp + random Time-sortable records Lower — time info embedded
Nil All zeros (constant) Placeholder / null sentinel N/A — not unique

UUID Structure: Reading the Hex Segments

Every UUID string follows the same 8-4-4-4-12 hexadecimal format, and each segment carries specific meaning. Understanding the structure helps you validate UUIDs, debug issues, and choose the right version for your needs.

The first segment (8 hex digits = 32 bits) in UUID v4 is entirely random. In UUID v1 it encodes the low 32 bits of the timestamp. The second segment (4 hex digits = 16 bits) holds the middle portion of timing data in v1, or more random bits in v4. The third segment (4 hex digits = 16 bits) is where the version digit lives: the first hex digit is always 4 for v4 or 1 for v1. The remaining 12 bits are random or time-derived. The fourth segment (4 hex digits = 16 bits) always begins with the variant bits: for RFC 4122-compliant UUIDs, the first digit is always 8, 9, a, or b (binary 10xx). The fifth segment (12 hex digits = 48 bits) is fully random in v4, or encodes a node identifier (typically a MAC address or random node ID) in v1.

When integrating a UUID generator into your workflow, always validate that third and fourth segment prefixes match the expected version and variant. Malformed UUIDs that fail this check may cause silent failures in databases or API parsers that strictly validate UUID format.

Worked Examples

Generate a Single UUID v4

Problem:

You need one random UUID to use as a new database record's primary key.

Solution Steps:

  1. 1Select 'UUID v4 (Random)' from the version dropdown — v4 is the most widely compatible choice for database keys.
  2. 2Set the count to 1 in the 'Number of UUIDs' field.
  3. 3Click 'Generate UUIDs'. The algorithm fills the template xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx with random hex digits, fixing the '4' version nibble and computing y as (r & 0x3 | 0x8) to get a variant digit of 8, 9, a, or b.
  4. 4A result such as 'a3f2b1c4-7e8d-4a9b-8c2d-1f0e3a4b5c6d' appears. The '4' in position 15 confirms version 4, and the '8' in position 20 confirms the RFC 4122 variant.
  5. 5Click 'Copy' next to the UUID to copy it to your clipboard for immediate use.

Result:

One RFC 4122-compliant UUID v4, ready to insert as a primary key or resource ID.

Bulk Generate 10 UUIDs for an Import Script

Problem:

You are writing a data migration script and need 10 pre-generated UUIDs to seed a test dataset.

Solution Steps:

  1. 1Select 'UUID v4 (Random)' from the version dropdown.
  2. 2Enter 10 in the 'Number of UUIDs' field (valid range is 1 to 100).
  3. 3Click 'Generate UUIDs'. The generator runs the v4 algorithm in a loop: for each of the 10 iterations, it independently fills the xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx template with fresh random values.
  4. 4Ten unique UUIDs appear in the output panel, each on its own line.
  5. 5Click 'Copy All' to copy all 10 UUIDs as a newline-separated list for pasting directly into your script or CSV file.

Result:

10 independent UUID v4 strings, each with 122 bits of randomness, copied to clipboard as a newline-delimited list.

Generate a Nil UUID as a Placeholder Value

Problem:

Your API schema requires a UUID field to always be present, but you need a safe 'empty' value for records where no real UUID has been assigned yet.

Solution Steps:

  1. 1Select 'Nil UUID' from the version dropdown.
  2. 2The count setting does not matter for nil UUIDs since they are all identical — leave it at any value.
  3. 3Click 'Generate UUIDs'. The generator returns the fixed constant '00000000-0000-0000-0000-000000000000' — all 128 bits set to zero.
  4. 4This value is defined in RFC 4122 as the nil UUID and is universally recognized as a sentinel 'not assigned' value.
  5. 5Copy the nil UUID and use it as the default value in your database column definition or API response schema.

Result:

'00000000-0000-0000-0000-000000000000' — the RFC 4122 nil UUID, suitable as a null-equivalent placeholder in UUID-typed fields.

Generate UUID v1 for Time-Correlated Records

Problem:

You want to generate identifiers for log entries where approximate creation time is embedded in the ID itself.

Solution Steps:

  1. 1Select 'UUID v1 (Time-based)' from the version dropdown.
  2. 2Set the count to the number of log entry IDs you need, for example 5.
  3. 3Click 'Generate UUIDs'. Each v1 UUID is built using the template xxxxxxxx-xxxx-1xxx-yxxx-xxxxxxxxxxxx, where the version digit '1' is fixed and the hex digits are derived from (Date.now() + Math.random() * 16) % 16 | 0, mixing the current millisecond timestamp with random noise.
  4. 4The third segment of each result begins with '1', confirming version 1.
  5. 5Because all five are generated in rapid succession they share similar timing components, giving them a degree of temporal correlation while remaining unique.

Result:

Five UUID v1 strings whose generation incorporates the current timestamp, making them loosely time-sortable.

Tips & Best Practices

  • Use UUID v4 for most new projects — it requires no coordination, leaks no timing data, and is supported by virtually every database, ORM, and programming language.
  • When storing UUIDs in a relational database, use a native UUID column type (available in PostgreSQL, MySQL 8+, SQL Server) rather than VARCHAR(36) to save storage and speed up index lookups.
  • The 'Copy All' button outputs UUIDs as a newline-separated list, which can be pasted directly into spreadsheets, SQL INSERT statements, or JSON arrays after light formatting.
  • If your database shows index fragmentation or slow inserts with UUID v4 keys, consider UUID v7 or ULID — both are time-ordered and monotonically increasing, which keeps B-tree indexes efficient.
  • Never use the nil UUID (all zeros) as an actual record identifier in production — it is a sentinel value, and storing it means you cannot distinguish 'not assigned' from a real record.
  • For client-generated UUIDs in a browser, modern browsers support crypto.randomUUID() which uses the Web Crypto API's CSPRNG — prefer it over Math.random()-based generators for any security-sensitive token.
  • UUID case is not significant — 'A3F2B1C4-...' and 'a3f2b1c4-...' refer to the same identifier. Canonicalize to lowercase before storing or comparing to avoid subtle bugs.
  • When generating large batches (close to the 100 UUID limit), verify your application can handle bulk inserts efficiently — inserting 100 random UUID primary keys in a single transaction is generally faster than 100 individual inserts.

Frequently Asked Questions

UUID v1 incorporates the current timestamp into its generation, meaning UUIDs created closer together in time share some structural similarity. UUID v4 is generated entirely from random bits (except for 6 fixed bits marking version and variant), making each UUID completely independent of when it was created. For most modern applications, UUID v4 is preferred because it leaks no timing information and is simpler to implement correctly.
Practically, yes. A UUID v4 encodes 122 random bits, giving 2^122 (approximately 5.3 × 10^36) possible values. The probability of generating even one collision among one trillion UUIDs is roughly 1 in 10^12 — far smaller than hardware failure rates. For engineering purposes, UUID v4 collisions are treated as impossible, though for cryptographic key material you should use a purpose-built cryptographically secure random number generator rather than Math.random().
Yes, and it is a common and well-supported pattern. UUID primary keys prevent sequential ID enumeration attacks, work seamlessly across database shards, and allow records to be created client-side before insertion. The main tradeoffs are slightly larger storage (16 bytes vs. 4–8 bytes for integers) and potential B-tree index fragmentation with random UUIDs, since inserts land in random positions. UUID v7 (monotonic time-ordered) or ULID are alternative formats that preserve insert order while retaining uniqueness.
In the UUID v4 template xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx, the 'y' position must be one of {8, 9, a, b} in hexadecimal. This is because RFC 4122 requires the two most significant bits of the clock_seq_hi_and_reserved byte to be set to '10' in binary — known as the 'variant' field. The generator implements this as (r & 0x3 | 0x8): masking the random value to 2 bits then OR-ing with 0x8 (1000 in binary) produces values 1000, 1001, 1010, or 1011 — which are 8, 9, a, and b in hex.
For most development, testing, and non-security-critical application uses, browser-generated UUIDs are perfectly fine. This generator uses JavaScript's Math.random(), which is a high-quality PRNG suitable for unique identifiers. For security-sensitive use cases such as authentication tokens or session IDs, use crypto.randomUUID() (available in all modern browsers) or generate UUIDs server-side using a cryptographically secure source of randomness.
The nil UUID (00000000-0000-0000-0000-000000000000) is a special constant defined in RFC 4122 representing the absence of a real UUID. It is typically used as a default value in UUID-typed database columns, a sentinel indicating 'not yet assigned' in data structures, or a safe stand-in when an API requires a UUID field but no real identifier exists yet. Unlike v1 or v4 UUIDs, the nil UUID is not unique — every system that generates it produces the same value.
A valid RFC 4122 UUID matches the regular expression /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i. The third segment's first character must be 1–5 (indicating version), and the fourth segment's first character must be 8, 9, a, or b (indicating RFC 4122 variant). Nil UUIDs pass a simpler all-zeros check. Most languages provide UUID parsing libraries that perform this validation automatically.

Sources & References

Last updated: 2026-06-05

💡

Help us improve!

How would you rate the UUID Generator?

<>

Editorial Note

MyCalcBuddy Editorial Team

This page is maintained as an educational calculator reference.

Source

Formula Source: Standard Mathematical References

by Various

UpdatedLast reviewed: May 2026
CheckedFormula checks are based on standard references and internal QA review.