Skip to content

UUID Generator & Validator

Free · Generators & Security · runs in your browser

By Nayeem, Software Developer of fastsavemedia.comLast reviewed
UUID v4 vs v7: which version to pick
PropertyUUID v4UUID v7
SourceFully randomUnix-millisecond timestamp + random
Random bits12274 (62 in this tool: rand_a is a per-millisecond counter)
Sorts by timeNoYes (millisecond)
Database index localityRandom order can scatter B-tree writesTime order can improve locality; benchmark your workload
Best forOpaque public identifiers, not authentication secretsTime-ordered identifiers and database keys
Order inside one millisecondNot applicableCounter keeps one generator's IDs sorted (RFC 9562 6.2, method 1)
Leaks creation timeNoYes, to the millisecond

UUID Internals, How It Works

Structure of a UUID

A UUID is 128 bits, conventionally formatted as xxxxxxxx-xxxx-Mxxx-Nxxx-xxxxxxxxxxxx where M identifies the version (1–8) and the top bits of N identify the variant (RFC 9562 uses binary 10).

time_low · 32 bits time_mid · 16 bits version + time_hi · 16 bits variant + clock_seq · 16 bits node / random · 48 bits

UUID v1

60-bit 100-ns timestamp since 1582-10-15 + 14-bit clock sequence + 48-bit node ID (often MAC). Leaks host and time.

UUID v3

MD5 of (namespace UUID || name). Deterministic, same inputs always give the same UUID.

UUID v4

122 bits of cryptographic randomness. Fully unordered. The default opaque identifier.

UUID v5

SHA-1 of (namespace UUID || name). Same deterministic behaviour as v3 but stronger hash.

UUID v6

Reorders v1 so the timestamp is in big-endian order, making the UUID sortable.

UUID v7

48-bit Unix ms timestamp + 74 bits random. Time-ordered, RFC 9562 native, ideal for primary keys.

UUID v8

122 bits of user-defined data. Use when you need a custom layout that still claims a UUID slot.

Best practices

  • Consider v7 for primary keys: time ordering can improve index locality, but it does not eliminate page splits.
  • Use v4 for public IDs, no information leakage.
  • Store as native UUID / BINARY(16), never as VARCHAR(36).
  • Always use a cryptographically secure RNG (crypto.getRandomValues, SecureRandom).
  • Pair UUIDs with a monotonically increasing sequence only if you need strict ordering.

Common mistakes

  • Using UUID v1 in public APIs, it leaks the host MAC address.
  • Storing UUIDs as VARCHAR(36) instead of uuid / BINARY(16), 2.25× the storage.
  • Picking UUID v4 as a clustered primary key on a write-heavy table: random order scatters inserts across the B-tree, which can increase page splits and cache misses.
  • Generating UUIDs with Math.random(), not cryptographically secure.
  • Exposing v1 / v6 / v7 IDs externally without considering the embedded timestamp.

Why a UUID fails validation

Most "invalid UUID" errors come from formatting, not from a bad value. This tool's validator accepts the canonical form, UPPERCASE, {braced} GUIDs from .NET and SQL Server, urn:uuid: prefixes and 32-character hex without dashes, then reports the canonical lowercase form. A value is rejected when it has the wrong length, non-hex characters, or a variant nibble (the first character of the fourth group) outside 8, 9, a or b. The variant check catches strings that merely look like UUIDs.

InputResult
{01890B3D-4F6F-7C34-A8D1-2B3C4D5E6F70}Valid v7, normalised to lowercase without braces
urn:uuid:550e8400-e29b-41d4-a716-446655440000Valid v4
00000000-0000-0000-0000-000000000000Nil UUID (RFC 9562 section 5.9), a placeholder rather than an ID
550e8400-e29b-41d4-c716-446655440000Invalid: variant nibble c is not the RFC 9562 variant

Keeping UUID v7 in order inside one millisecond

A v7 UUID only stores milliseconds, so a naive generator that fills the rest with random bits can emit IDs out of order when several are created in the same millisecond. RFC 9562 section 6.2 describes fixes. This tool uses method 1: the 12-bit rand_a field acts as a counter that increases for each ID in the same millisecond, starting from a random low value. Bulk-generated v7 lists therefore come out already sorted. If the counter would overflow, the generator moves to the next millisecond. Ordering holds within one generator; IDs from different machines still interleave by clock.

Key takeaways

  • UUID v7 is a time-ordered option for database primary keys, defined in RFC 9562.
  • UUID v4 remains correct for opaque external identifiers.
  • ULID and v7 are functionally equivalent in ordering guarantees; choose ULID for shorter string form, v7 for native DB UUID type.
  • Snowflake wins on raw size (64-bit) but requires worker-id coordination.
  • NanoID and CUID2 are for URLs and anti-enumeration, not for high-throughput databases.
  • For independent uniform UUID v4 generation, collision probability reaches about 50% at 2.71 × 10¹⁸ IDs. Enforce uniqueness and handle collisions.

Frequently asked questions

What is a UUID?

A UUID (Universally Unique Identifier) is a 128-bit identifier standardised by RFC 9562 that can be generated independently across systems with a negligible probability of collision.

Which UUID version should I use for a database primary key?

Consider UUID v7 when time ordering suits your database. Its leading millisecond timestamp can improve index locality compared with UUID v4, but strict monotonic order within a millisecond depends on the generator, and clock changes can affect ordering.

What is the difference between UUID v4 and UUID v7?

UUID v4 is fully random and unordered, ideal for opaque public IDs. UUID v7 is time-ordered: the first 48 bits are a Unix ms timestamp, so v7 values sort chronologically and index efficiently in databases.

What is ULID?

ULID is a 128-bit identifier with a 48-bit timestamp and 80 bits of randomness, encoded in Crockford Base32 as a 26-character string. It is lexicographically sortable and URL-safe.

How many UUIDs can be generated before a collision?

For random UUID v4 you would need to generate roughly 2.71 quintillion (2.71 × 10^18) UUIDs to reach a 50% collision probability, under independent uniform generation. Collisions remain possible; use a unique constraint and retry strategy.

Why does my UUID show as invalid?

Check the length, that every character is hex, and the first character of the fourth group: RFC 9562 UUIDs use 8, 9, a or b there. Braces, UPPERCASE, a urn:uuid: prefix and missing dashes are accepted and normalised by this validator.

Are bulk UUID v7 values sorted?

Yes, within one batch. The generator uses the 12-bit rand_a field as a counter inside each millisecond (RFC 9562 section 6.2, method 1), so each new v7 ID sorts after the previous one. IDs created on other machines are ordered only by their clocks.

Is the tool free?

Yes. UUID Studio runs entirely in your browser, requires no signup and is 100% free.