Guide

UUID v4 vs v7: Which One to Use

Both are 128-bit identifiers written the same way. The difference is what the bits contain: v4 is almost entirely random, while v7 starts with a timestamp.

Updated

Try it now: UUID Parser. It runs in your browser, with no signup.

How the two versions are built

A UUID is written as 32 hexadecimal digits in the 8-4-4-4-12 layout. The first digit of the third group is the version, and the first digit of the fourth group is 8, 9, a or b for the standard variant (RFC 9562, which replaces RFC 4122).

  • Version 4: 122 random bits, with 6 bits fixed for the version and variant. Nothing in it relates to time.
  • Version 7: a 48-bit Unix timestamp in milliseconds, then the version and variant bits, then random bits.
018f3c5e-7b1a-7cc2-8f2e-9a4b3c2d1e0f
^^^^^^^^ ^^^^ ^               version digit = 7
48-bit millisecond timestamp (first 12 hex digits)

Why v7 is friendlier to databases

Random v4 keys land at random positions in a B-tree index, so inserts touch many pages and can cause page splits and a bigger, more fragmented index. Version 7 values created later sort after earlier ones, so new rows are added near the end of the index, much like an auto-increment key, while staying unique across machines. The sort order is by millisecond; two IDs from the same millisecond are ordered by their random bits unless the generator adds a counter.

When v4 is still the right choice

Neither version is a secret. Do not use a UUID as a password, an API key or an authorization token.

  • You do not want the creation time to be visible in the identifier.
  • The ID is used for lookups only and index locality does not matter.
  • Your platform has no v7 support and you want zero extra dependencies.

Read the timestamp out of a v7 UUID

Take the first 12 hex digits (ignore the hyphens), read them as a number, and treat it as Unix milliseconds.

// JavaScript
const id = "018f3c5e-7b1a-7cc2-8f2e-9a4b3c2d1e0f";
const ms = parseInt(id.replace(/-/g, "").slice(0, 12), 16);
console.log(new Date(ms).toISOString());   // 2024-05-03T02:52:55.962Z

# Python
from datetime import datetime, timezone
h = "018f3c5e-7b1a-7cc2-8f2e-9a4b3c2d1e0f".replace("-", "")
print(datetime.fromtimestamp(int(h[:12], 16) / 1000, tz=timezone.utc))

Generating each version

For version 7 in other languages and databases, check whether your runtime or library version already includes it before adding a dependency. You can also generate v4 and v7 values in the UUID Generator and decode any UUID in the UUID Parser.

// JavaScript (browser and Node): version 4
crypto.randomUUID();

// C# (.NET 9 and later)
Guid.NewGuid();            // version 4
Guid.CreateVersion7();     // version 7

# Python: version 4
import uuid
uuid.uuid4()

Frequently asked questions

Can I tell when a v4 UUID was created?

No. A version 4 UUID has no timestamp. Only versions 1, 6 and 7 carry creation time.

Are v7 UUIDs guaranteed to be unique?

In practice yes: the random bits make collisions extremely unlikely, as with v4. Uniqueness is not a guarantee in the mathematical sense for either version.

Is UUID the same as GUID?

They share the same 128-bit format. GUID is the name used in Microsoft environments such as .NET and SQL Server.

Tools used in this guide

onlinedevelopertool.com is a collection of 54 free, browser-based utilities for the small jobs that interrupt real work: formatting a JSON response, decoding a token, converting a timestamp, generating a UUID or checking a hash. Each tool has its own page with a short explanation, a worked example and answers to common questions, so you can use it and learn what it does at the same time.

There is no account to create and nothing to install. Tools run in your browser, so the text you paste is processed on your own device. The one exception is the Website Status Checker, which sends a request from your browser to the address you enter.

Three steps: paste your input, click the tool, copy the result, all inside your browser
Popular developer utilities: JWT decoder, UUID generator, Base64 decoder, SHA-256 hash, regex tester and timestamp converter

What you can do here

  • JSON Tools

    Format, validate, beautify and minify JSON, generate C#, TypeScript, Java, Python, Go, PHP and Kotlin models from it, or convert between JSON, YAML and CSV.

  • Encoders & Decoders

    URL, Base64 and HTML encoding and decoding, plus a JWT decoder for reading token claims.

  • Generators & Hashes

    Generate UUIDs and JWTs, validate UUIDs, and create MD5, SHA-256 and SHA-512 hashes.

  • Web Tools

    Timestamps, color codes, query strings and cron expressions - the small things web work keeps throwing at you.

  • Text & Data

    Format XML and YAML, count text, change case, make slugs, test regex, diff two texts and convert number bases.

  • Website Checking

    Check whether a website or URL is reachable from your browser.

Quick developer reference

  • JSON

    Keys and strings must use double quotes, and trailing commas and comments are not allowed. Those are the three most common reasons a payload fails to parse.

    Validate JSON
  • JWT

    A JSON Web Token is three Base64URL parts joined by dots: header, payload and signature. Decoding shows the claims but does not prove the token is genuine; only signature verification does.

    Decode a JWT
  • Base64

    Base64 is an encoding, not encryption. Anyone can reverse it, and it makes data roughly one third larger, so never use it to hide secrets.

    Decode Base64
  • UUID

    A version 4 UUID is made of random bits and written as 8-4-4-4-12 hexadecimal characters. Collisions are astronomically unlikely, which is why they work well as identifiers.

    Generate a UUID
  • Timestamps

    A Unix timestamp counts time since 1 January 1970 UTC. Ten digits usually means seconds and thirteen digits usually means milliseconds.

    Convert a timestamp
  • Hashes

    MD5 is fine for quick checksums but is not safe for security. Prefer SHA-256 or SHA-512, and remember that hashing is one-way and is not encryption.

    Create a SHA-256 hash

Missing a tool you need? Visit the contact page and tell us what you reach for most often. You can also browse every tool or read the About page to see how the site is built and what it does with your data.