# What Is a UUID? v4 vs v7 and When to Use Each

> How UUIDs are structured, the versions you'll meet (v1, v4, v5, v7), the real odds of a collision, UUIDs as database keys, and how they relate to GUIDs.

Source: https://widgetpantry.com/en/what-is-a-uuid · Türkçe: https://widgetpantry.com/tr/uuid-nedir

Published 2026-11-16

A UUID (Universally Unique Identifier) is a 128-bit ID you can generate anywhere without asking a central counter, yet it's practically guaranteed to be unique. You'll find them as record IDs, file names, session and order numbers. Here's how they work and which version to pick. To make some right now, use the [UUID Generator](https://widgetpantry.com/en/uuid-generator).

## Anatomy of a UUID

A UUID is written as 32 hex characters in an 8-4-4-4-12 pattern: 550e8400-e29b-41d4-a716-446655440000 — 36 characters with the hyphens.

The first character of the third group is the version (4 above) and the first of the fourth group is the variant (a here), so you can tell how a UUID was made just by looking at it.

## The versions

RFC 9562 defines eight versions; four come up in practice:

| Version | Contents | Pros | Cons |
| --- | --- | --- | --- |
| v1 | Timestamp + node ID | Time-ordered | Can leak the machine's MAC |
| v4 | 122 random bits | Simple, unguessable | Unordered; scattered in indexes |
| v5 | SHA-1 of namespace + name | Same input → same UUID | Not random |
| v7 | Millisecond time + random | Ordered and unguessable | Reveals creation time |

## Can two UUIDs collide?

A v4 UUID has 2¹²² ≈ 5.3 × 10³⁶ possible values. By the birthday problem you'd need about 2.7 × 10¹⁸ of them for a 50% chance of one duplicate — roughly 85 years at a billion UUIDs per second. With a proper random source, collisions are not a practical concern.

What matters is the generator: this site's tool uses the browser's cryptographic crypto.randomUUID().

## Database primary keys: v4 or v7?

Random v4 keys land all over a B-tree index, which on large, write-heavy tables means page splits and poor cache use. v7 keys are time-ordered, so new rows append at the end of the index — close to the performance of auto-increment integers, while still generated anywhere.

Rule of thumb: v4 for public-facing IDs where order doesn't matter, v7 for primary keys of busy tables. Remember that v7 exposes when a record was created.

## Are UUIDs safe as secrets?

A UUID is an identifier, not a secret — it ends up in URLs, logs and screenshots. For password-reset links or API keys, use purpose-built random tokens of sufficient length. For strong passwords there's the [Password Generator](https://widgetpantry.com/en/password-generator), and to fingerprint data, the [Hash Generator](https://widgetpantry.com/en/hash-generator).

## Frequently asked questions

### Is a GUID the same as a UUID?

Yes. GUID is Microsoft's name for a UUID; the format and size are the same.

### Is a UUID without hyphens valid?

It carries the same 128 bits, and many systems accept the 32-character form. The generator can drop the hyphens for you.

### Should UUIDs be uppercase or lowercase?

The standard recommends lowercase output, but comparisons are case-insensitive. Some Microsoft tools print uppercase.

## Use the tool

- [UUID Generator](https://widgetpantry.com/en/uuid-generator): Create up to 100 UUID v4 or v7 values at once using your browser's secure random generator. Uppercase and no-hyphen formats, one-click copy.
