---
title: "UUID Generator (v4 & v7)"
description: "UUID v4 (random) and v7 (time-ordered) generator. One at a time or in bulk."
url: https://sade.dev/en/tools/uuid/
lang: en
author: "Muhammet Şafak"
published: 2026-04-05
updated: 2026-08-30
section: Tool
tags: ["uuid","identifier"]
---

# UUID Generator (v4 & v7)

> UUID v4 (random) and v7 (time-ordered) generator. One at a time or in bulk.

A UUID (Universally Unique Identifier) is a 128-bit identifier whose chance of
collision is practically zero. There are several versions; in practice two stand
out: **v4** and **v7**.

## UUID v4

122 of the 128 bits are random — the 4-bit version and 2-bit variant fields
are fixed. Generated with `crypto.randomUUID()`.

```
123e4567-e89b-42d3-a456-426614174000
              ^
              version (4)
```

The upside: in a distributed system you can generate unique IDs with no coordination.

The downside: there is no temporal ordering. Used as a database primary key, v4
keeps the B-tree index writing to scattered pages — **insert performance degrades**,
especially on high-volume tables.

## UUID v7

RFC 9562 (2024). The first 48 bits are a Unix millisecond timestamp; 74 of the
remaining 80 bits are random. Still unique, but **time-ordered**.

```
01876d10-1b21-7000-8000-000000000000
^^^^^^^^^^^^^ ^
timestamp ms  version (7)
```

Why v7 is better for a database primary key:

- New rows land at the end of the B-tree.
- Index splits drop.
- Cache locality improves.
- Date-based queries can use the index.

## Which one, when?

| Case | Choice |
|---|---|
| Database primary key | **v7** |
| General-purpose IDs generated in an API | **v7** or v4 |
| Where unpredictability is critical (e.g. session token) | v4 |
| Compatibility with an older system | v4 (supported everywhere) |

## What about v1, v3, v5?

- **v1**: MAC address + timestamp. A privacy hole (it leaks the device). Don't use it.
- **v3, v5**: the hash of a namespace plus a name. For a specific use case (e.g. when
  you need a deterministic ID); otherwise prefer v4/v7.

## Collision probability

For UUID v4: even if you generated 1 billion UUIDs a second, you would have to wait
about 85 years to see a collision. For v7, the time part requires two UUIDs to be
generated in the same millisecond — and the collision probability in the random
part is still negligible.

## Privacy

UUIDs are generated in your browser with the Web Crypto API — `crypto.randomUUID()`
for v4, `crypto.getRandomValues` for v7. Nothing leaves your browser.
