Skip to content
HandyKit

UUID v4 vs v7: Which Version Should You Use?

· 3 min read

A UUID is a 128-bit identifier written as 32 hexadecimal digits in five groups: 8-4-4-4-12. When you choose IDs for a database or an API, the two versions worth comparing are v4 and v7.

This guide explains how each one works and gives a simple rule for choosing. You can create both, and inspect any UUID, with the UUID Generator.

Reading a UUID

The first digit of the third group is the version. Here is a version 7 UUID:

0192f1c4-5a3e-7b2d-8f61-3c9e2a7d4b10

The 7 at the start of the third group marks version 7. Its first 48 bits are a Unix timestamp in milliseconds: the generator's inspector reads this one as 3 November 2024 at 11:23:50 UTC. A v4 UUID has a 4 in the same place and carries no time.

How v4 works

A v4 UUID is 122 random bits plus the version and variant markers. Duplicates are possible in theory, but you would need to make about 2.7 quintillion (2.7 × 10^18) of them before there is even a 50% chance of one.

Because the bits are random, v4 IDs have no order: a new ID can land anywhere when you sort.

How v7 works, and why it suits database keys

A v7 UUID starts with a timestamp and fills the rest with random bits, so new IDs sort after old ones.

That matters for database primary keys. With v4, each new row goes into a random place in a B-tree index. With v7, new rows go at the end, which keeps the index compact and fast.

The trade-off is that a v7 ID reveals when it was created, and is partly predictable.

Which to choose

  • Use v4 when you just need a unique ID, especially one that should reveal nothing.
  • Use v7 for database keys and anything you want to sort by creation time.

Other versions and ULIDs

The standard is RFC 9562. The other versions you may meet:

  • v1: time and node (a MAC address).
  • v3: name-based, using MD5.
  • v5: name-based, using SHA-1. The same namespace and name always give the same UUID.
  • v6: v1's time, reordered so it sorts.
  • v8: custom.

The generator makes v4, v7, v1 and v5 UUIDs, the nil UUID (all zeros), the max UUID (all f) and ULIDs. A ULID is another sortable 128-bit ID, written as 26 characters; v7 gives you the same kind of ordering in the standard UUID format.

Case, GUIDs and secrets

UUIDs are not case-sensitive. The standard says to write them in lowercase and accept either case, so compare them case-insensitively or normalise to lowercase first.

GUID is Microsoft's name for the same format, often shown in uppercase with braces. The generator's format options can match that.

UUIDs are identifiers, not secrets. For password-reset links, API keys and session tokens, use a dedicated token with at least 128 random bits.

Try it

Open the UUID Generator to make up to 1000 UUIDs at once as lines, JSON or CSV, or paste a UUID to see its version and, for time-based ones, when it was made. It uses crypto.getRandomValues in your browser, and nothing is sent to a server.

Tools in this guide

  • UUID Generator

    Create random v4, time-ordered v7, v1 or name-based v5 UUIDs, or ULIDs, one or a thousand at a time, and inspect any UUID or ULID to see its version and creation time.

  • · 5 min read

    Cron Expression Examples, Explained

    Ready-to-use cron expressions for every 5 minutes, hourly, daily, weekday and monthly jobs, how each field works, and the mistakes that catch people out.

  • · 3 min read

    How to Find and Replace Many Words at Once

    Replace a whole list of words in one go: write find => replace pairs or paste them from a spreadsheet, swap words safely, and check every change afterwards.