Skip straight to the UUID v6 generator or keep reading to understand time-ordered UUID generation.
UUID v6 is a modern time-ordered UUID that keeps the timestamp at the front of the identifier without exposing a MAC address. This guide explains how UUID v6 differs from other versions and shows how to use it with popular languages and databases.
What is UUID v6?
UUID Version 6 is a reordered UUID v1 with a timestamp prefix. Instead of the original UUID v1 layout, UUID v6 places the 60-bit timestamp first so UUID values sort naturally when treated as strings. It is defined in RFC 9562 as a backward-compatible way to preserve v1 semantics while improving sortability.
8ace1c11-5b22-6dd1-95b4-682cc3acb675
└───────┘ └──┘ └───┘ └───────────────┘
timestamp ver clock node
(60-bit) 6 seq (48-bit)
Why choose UUID v6?
Time-ordered sorting
UUID v6 orders its timestamp bits at the front of the identifier. That means a simple lexical sort produces creation order, which is ideal for databases and log streams.
Better than UUID v1 for indexing
UUID v1 embeds a timestamp but leaves the low-order time and node fields first, which causes poor index locality. UUID v6 fixes that by moving the timestamp to the top while still preserving the original v1 timestamp and node information.
How it compares to UUID v7
UUID v7 is the newer recommendation for time-ordered UUIDs because it uses a millisecond Unix timestamp and fully random payload bits. UUID v6 can still be useful when you want a more direct upgrade path from v1 or when compatibility with libraries and systems that already understand version 6 is required.
When to use UUID v4 instead
Use UUID v4 when you do not want any timestamp semantics embedded in the value. UUID v6 is best when chronological ordering and index locality are important.
UUID v6 structure
- timestamp: 60 bits from the original UUID v1 time layout.
- version: the version nibble is
6. - clock sequence: 14 bits used to preserve uniqueness when the clock moves backwards.
- node: 48 bits of node information or random data, matching UUID v1 style.
Code examples for UUID v6
uuid npm package
Generate UUID v6 with the popular JavaScript UUID library.
# Install
npm install uuid
import { v6 as uuidv6 } from 'uuid';
const id = uuidv6();
console.log(id);
Browser-friendly helper
Use the same layout as UUID v1 but with re-ordered bytes for sorting.
function formatHex(bytes) {
return [...bytes].map(b => b.toString(16).padStart(2, '0')).join('');
}
function uuidv6() {
const ts = BigInt(Date.now()) * 10000n + 0x01b21dd213814000n;
const bytes = new Uint8Array(16);
const rnd = new Uint8Array(8);
crypto.getRandomValues(rnd);
// timestamp high 48 bits
for (let i = 0; i < 6; i++) {
bytes[i] = Number((ts >> BigInt(40 - 8 * i)) & 0xffn);
}
bytes[6] = 0x60 | ((Number((ts >> 24n) & 0xffn) ) & 0x0f);
bytes[7] = Number((ts >> 16n) & 0xffn);
bytes[8] = 0x80 | (rnd[0] & 0x3f);
bytes.set(rnd.subarray(1), 9);
const h = formatHex(bytes);
return `${h.slice(0,8)}-${h.slice(8,12)}-${h.slice(12,16)}-${h.slice(16,20)}-${h.slice(20)}`;
}
console.log(uuidv6());
uuid6 backport package
For Python versions before 3.12, use a backport that supports v6.
# Install
pip install uuid6
import uuid6
uid = uuid6.uuid6()
print(uid)
# version 6
print(uid.version)
Extract v6 timestamp
import uuid6
from datetime import datetime, timezone
uid = uuid6.uuid6()
ms = (uid.int >> 80) - 0x01b21dd213814000
print(datetime.fromtimestamp(ms / 1000, tz=timezone.utc))
google/uuid v7 support includes v6
This package can generate UUID v6 values with the right constructor.
# Install
go get github.com/google/uuid
package main
import (
"fmt"
"github.com/google/uuid"
)
func main() {
id, err := uuid.NewV6()
if err != nil {
panic(err)
}
fmt.Println(id)
}
java-uuid-generator
Use JUG to generate UUID v6 values in Java.
<!-- Maven dependency -->
<dependency>
<groupId>com.fasterxml.uuid</groupId>
<artifactId>java-uuid-generator</artifactId>
<version>5.1.0</version>
</dependency>
import com.fasterxml.uuid.Generators;
import java.util.UUID;
UUID id = Generators.timeBasedGenerator().generate();
System.out.println(id);
UUIDNext NuGet package
Generate UUID v6 values in .NET using a third-party library.
# Install
dotnet add package UUIDNext
using UUIDNext;
var id = Uuid.NewV6();
Console.WriteLine(id);
// → 8ace1c11-5b22-6dd1-95b4-682cc3acb675
ramsey/uuid
The Ramsey UUID library supports UUID v6 generation in PHP.
# Install
composer require ramsey/uuid
use Ramsey\Uuid\Uuid;
$id = Uuid::uuid6()->toString();
echo $id;
uuidtools gem
Generate UUID v6 in Ruby using the uuidtools gem.
# Install
gem install uuidtools
require 'uuidtools'
puts UUIDTools::UUID.uuid_v6
uuid crate
Create UUID v6 values in Rust with the uuid crate.
# Cargo.toml
[dependencies]
uuid = { version = "1", features = ["v6"] }
use uuid::Uuid;
fn main() {
let id = Uuid::new_v6();
println!("{}", id);
}
Elixir UUID package
Generate UUID v6 values in Elixir using a UUID library with v6 support.
# mix.exs dependencies
{:uuid, "~> 2.0"}
UUID = Elixir.UUID
id = UUID.uuid6()
IO.puts(id)
Erlang uuid library
Generate UUID v6 values in Erlang with a UUID dependency.
% rebar.config
{deps, [{uuid, "*"}]}
UUID = uuid:uuid6().
io:format("~s~n", [UUID]).
PostgreSQL
PostgreSQL does not yet ship a native uuid6 function, but you can store v6 values generated in the application layer.
CREATE TABLE events (
id UUID PRIMARY KEY,
name TEXT
);
-- Insert UUID v6 from your app
INSERT INTO events (id, name) VALUES ('8ace1c11-5b22-6dd1-95b4-682cc3acb675', 'signup');
MySQL
Store UUID v6 as CHAR(36) or BINARY(16) and generate the value in code.
CREATE TABLE events (
id BINARY(16) PRIMARY KEY,
title VARCHAR(200)
);
Frequently asked questions
Is UUID v6 an official standard?
UUID v6 is part of RFC 9562, the same document that formalizes multiple new UUID versions including v7. It is recognized as an IETF standard for time-ordered identifiers.
Should I use UUID v6 or UUID v7?
Use UUID v7 for the cleanest new design with Unix millisecond timestamps. Use UUID v6 when you want a version that is closer to UUID v1 and preserves the traditional node/clock-sequence fields.
Can UUID v6 values be sorted as strings?
Yes. Since UUID v6 moves the timestamp to the highest-order bits, string sorting yields chronological order in most systems.
Ready for hands-on generation? Open the UUID v6 generator →