UUID generator and decoder (v4, v7)

Generate reproducible UUID v4 and v7 values from a seed, or validate any UUID or GUID and decode its version, variant and embedded timestamp.

Обновлено Проверенные примеры: 8

Upper or lower case, with or without hyphens, braces or a urn:uuid: prefix.
Попробовать
Type
Unix Epoch time-based
Type: Unix Epoch time-based
UUID
017f22e2-79b0-7cc3-98c4-dc0c0c07398f
Version
7
Variant
RFC 9562
Embedded time
2022-02-22 19:22:22.000 UTC
Unix time
1645557742000ms

017f22e2-79b0-7cc3-98c4-dc0c0c07398f is a version 7 (Unix Epoch time-based) UUID with the RFC 9562 variant; it was stamped at 2022-02-22 19:22:22.000 UTC.

Field layout

unix_ts_ms (48)
0
0
0
0
0
0
0
1
0
1
1
1
1
1
1
1
0
0
1
0
0
0
1
0
1
1
1
0
0
0
1
0
0
1
1
1
1
0
0
1
1
0
1
1
0
0
0
0
ver (4)
0
1
1
1
rand_a (12)
1
1
0
0
1
1
0
0
0
0
1
1
var (2)
1
0
rand_b (62)
0
1
1
0
0
0
1
1
0
0
0
1
0
0
1
1
0
1
1
1
0
0
0
0
0
0
1
1
0
0
0
0
0
0
1
1
0
0
0
0
0
0
0
1
1
1
0
0
1
1
1
0
0
1
1
0
0
0
1
1
1
1
Как выполняется расчёт S
  1. Normalise

    Lower-case hex in 8-4-4-4-12 groups: 017f22e2-79b0-7cc3-98c4-dc0c0c07398f.

  2. Variant

    octet 8=98=100110002⇒RFC 9562\text{octet 8} = \texttt{98} = \texttt{10011000}_2 \Rightarrow \text{RFC 9562}

    Leading bits 10 mean the RFC 9562 layout; 0, 110 and 111 are reserved for older or future schemes.

  3. Version

    high nibble of octet 6=7c⇒7 (Unix Epoch time-based)\text{high nibble of octet 6} = \texttt{7c} \Rightarrow 7\ (\text{Unix Epoch time-based})
  4. Unix timestamp

    bits 0–47=017f22e279b016=1645557742000 ms⇒2022-02-22 19:22:22.000 UTC\text{bits 0–47} = \texttt{017f22e279b0}_{16} = 1645557742000\ \text{ms} \Rightarrow \text{2022-02-22 19:22:22.000 UTC}
  5. Randomness

    This layout leaves 74 bits for random data.

О калькуляторе: UUID generator and decoder (v4, v7)

A UUID is a 128-bit identifier written as 32 hex digits in 8-4-4-4-12 groups. RFC 9562 fixes two fields in every standard UUID: the variant bits 10 at the start of the 17th hex digit, and a 4-bit version number in the 13th. The decoder reads both, then unpacks what that version carries: a 48-bit Unix millisecond timestamp for version 7, a 60-bit count of 100-nanosecond intervals since 15 October 1582 for versions 1 and 6, or 122 random bits for version 4.

The default is the RFC 9562 version 7 example, 017f22e2-79b0-7cc3-98c4-dc0c0c07398f, whose first 48 bits count 1,645,557,742,000 ms, which is 22 February 2022 at 19:22:22 UTC. Developers pick v7 for database keys because the values sort by creation time.

Generated UUIDs come from a seeded xoshiro256** generator, so the same seed always gives the same list. For identifiers that must be unguessable, use a cryptographic source such as crypto.randomUUID().

Примеры с решением

RFC 9562 version 7 example

I want to
Decode a UUID
UUID
017F22E2-79B0-7CC3-98C4-DC0C0C07398F
UUID
017f22e2-79b0-7cc3-98c4-dc0c0c07398f
Version
7
Variant
RFC 9562
Embedded time
2022-02-22 19:22:22.000 UTC
Unix time
1645557742000 ms

Источник проверки: RFC 9562 Appendix A.6 (Tuesday, February 22, 2022 2:22:22.00 PM GMT-05:00); Python 3.8: int('017F22E279B0', 16) = 1645557742000

RFC 9562 version 4 example

I want to
Decode a UUID
UUID
919108f7-52d1-4320-9bac-f847db4148a8
Version
4
Type
Random
Variant
RFC 9562

Источник проверки: RFC 9562 Appendix A.3; Python 3.8 uuid.UUID(...).version = 4, .variant = 'specified in RFC 4122'

RFC 9562 version 1 example

I want to
Decode a UUID
UUID
C232AB00-9414-11EC-B3C8-9F6BDECED846
Version
1
Embedded time
2022-02-22 19:22:22.0000000 UTC
Clock sequence
13,256
Node
9f:6b:de:ce:d8:46

Источник проверки: RFC 9562 Appendix A.1; Python 3.8 uuid.UUID(...).time = 138648505420000000, (time − 122192928000000000) / 10^7 = 1645557742 s; .clock_seq = 13256; .node = 0x9f6bdeced846

RFC 9562 version 6 example

I want to
Decode a UUID
UUID
1EC9414C-232A-6B00-B3C8-9F6BDECED846
Version
6
Embedded time
2022-02-22 19:22:22.0000000 UTC

Источник проверки: RFC 9562 Appendix A.5 (same instant as the v1 example)

Вопросы

What is the difference between UUID v4 and v7?

Version 4 fills 122 of the 128 bits with random data, so values are spread evenly and reveal nothing. Version 7, defined in RFC 9562 (May 2024), puts a 48-bit Unix millisecond timestamp first and 74 random bits after it, so new IDs sort in creation order. RFC 9562 notes that v4 has poor database-index locality, which is why v7 suits primary keys, at the cost of revealing when each ID was made.

Can two random UUIDs collide?

In practice, no. A v4 UUID has 122 random bits, so by the birthday bound you would need about 2.7 × 10^18 of them for a 50% chance of a single duplicate, or about 103 trillion for a one-in-a-billion chance. Real collisions come from faulty random number generators or reused seeds, which is why the seeded UUIDs here shouldn't be used where uniqueness across systems matters.

What is the difference between a UUID and a GUID?

They are the same 128-bit format; GUID is Microsoft's name for it. Microsoft tools often print GUIDs in upper case inside braces, such as {017F22E2-79B0-7CC3-98C4-DC0C0C07398F}, and RFC 9562 allows upper, lower or mixed case, so parsers should accept both. The one real difference is binary byte order: Windows stores the first three groups little-endian, which matters only when reading raw bytes.

How do I get the timestamp from a UUID v7?

Take the first 12 hex digits, which hold a 48-bit count of milliseconds since 1970-01-01 00:00 UTC, and convert them to decimal. For 017f22e2-79b0-7cc3-98c4-dc0c0c07398f, 017f22e279b0 is 1,645,557,742,000 ms, which is 2022-02-22 19:22:22.000 UTC. The 48-bit field runs out in the year 10889, so it will not wrap in practice.

Is a version 1 UUID a privacy risk?

It can be. Version 1 stores a 60-bit timestamp and a 48-bit node field that is traditionally the machine's MAC address, so the ID reveals when and on which network card it was made; the RFC 9562 v1 example decodes to 2022-02-22 19:22:22 UTC with node 9f:6b:de:ce:d8:46. RFC 9562 allows a random node value instead, and says to use version 7 instead of 1 or 6 where possible.

Насколько точен «UUID generator and decoder (v4, v7)»?

Точность зависит от введённых данных и допущений метода. Десятичная арифметика использует 50 значащих цифр, но оценки, численные методы и исходные данные могут быть менее точными; округление на экране не устраняет эти ограничения. Решённые примеры, проверенные по независимым источникам: 8. Например, «RFC 9562 version 7 example» проверяется по источнику RFC 9562 Appendix A.6 (Tuesday, February 22, 2022 2:22:22.00 PM GMT-05:00); Python 3.8: int('017F22E279B0', 16) = 1645557742000.

Откуда взята методика?

RFC 9562 — Universally Unique IDentifiers (UUIDs), §4–5 and Appendix A test vectors; Blackman & Vigna — xoshiro256** and SplitMix64 reference code.

Об этом калькуляторе

v7: tms=bits 0–47v1/v6: t=60-bit count107−12 219 292 800 s\begin{aligned} \text{v7: } t_{ms} &= \text{bits } 0\text{–}47 \\ \text{v1/v6: } t &= \frac{\text{60-bit count}}{10^7} \\ &\quad - 12\,219\,292\,800\ \text{s} \end{aligned}

Источники

  1. RFC 9562 — Universally Unique IDentifiers (UUIDs), §4–5 and Appendix A test vectors
  2. Blackman & Vigna — xoshiro256** and SplitMix64 reference code

Проверено по источникам

В калькулятор включены решённые примеры с ответами из независимых источников. Их количество: 8. Они входят в набор тестов, и вы также можете запустить их здесь.

Похожие калькуляторы