Quick answer
Use UUID v7 for database keys and v4 for IDs that mustn't reveal when they were made. The deciding question is what the ID has to do:
- UUID v7 for database keys and anything you sort by creation: a v7 UUID starts with a millisecond timestamp, so new values sit next to each other in an index and sort roughly in creation order.
- UUID v4 when the ID shouldn't say when it was made: apart from the version and variant bits, a v4 UUID is random, so it reveals nothing about its creation time.
- Neither as a secret: RFC 9562, the UUID standard, says UUIDs "MUST NOT be used as security capabilities", meaning identifiers whose possession alone grants access (IETF: RFC 9562, section 8). Use a proper token for that.
If you're unsure, ask whether anyone outside your system will see the ID. A v7 UUID hands every viewer its creation time to the millisecond. If that's fine and the ID is a primary key, v7 is the better fit. If it isn't, use v4.
In FreeToolsKit's UUID/GUID Generator & Validator, pick v4 (random) or v7 (time-ordered), set How many UUIDs and press Generate UUIDs. To check an ID you already have, paste it into UUID or GUID to check and press Validate. It shows the version and, for v7, the time encoded in it.
What is inside each version
Both versions are 128 bits, written as 32 hexadecimal digits in the 8-4-4-4-12 pattern. The 13th digit is the version (4 or 7), and the 17th digit is 8, 9, a or b, which marks the standard variant (binary 10).
- v4: RFC 9562 says it is "meant for generating UUIDs from truly random or pseudorandom numbers". After the version and variant, 122 bits are random (IETF: RFC 9562, section 5.4).
- v7: the first 48 bits are a Unix timestamp in milliseconds. The remaining 74 bits, after the version and variant, are random, or partly a counter or a finer time fraction if the implementation adds one (IETF: RFC 9562, section 5.7).
RFC 9562 replaced RFC 4122 in May 2024 and is the first standard to define v7. It also says implementations "SHOULD utilize UUIDv7 instead of UUIDv1 and UUIDv6 if possible" (IETF: RFC 9562, section 5.7), so v7 is the standard's choice whenever you want a time-based UUID.
The five criteria that decide it
1. Database index locality and sort order: v7
A primary-key index is usually a B-tree, kept in key order. RFC 9562 explains that versions that aren't time-ordered, such as v4, "have poor database-index locality". New values land far apart, so inserts "are performed at random locations", and the effect on B-trees "can be dramatic" (IETF: RFC 9562, section 1).
v7 is designed to "sort as opaque raw bytes without the need for parsing". The RFC says the difference between this kind of index locality and random inserts "can be one order of magnitude or more" in real-world use (IETF: RFC 9562, section 6.11). That's the standard's own general statement, not a benchmark. Measure your own database before relying on a figure.
Database vendors make the same point in their own ways. Microsoft says SQL Server's NEWSEQUENTIALID() can be faster than NEWID() because NEWID() "causes random activity" (Microsoft Learn: NEWSEQUENTIALID). That function isn't a v7 UUID, though. MariaDB stores version 6 and higher without byte-swapping because they "are designed around time ordering" (MariaDB: UUID data type).
Wherever you can, store UUIDs as 128-bit binary rather than text. RFC 9562 notes that text needs 288 bits for a 128-bit value (IETF: RFC 9562, section 6.13). We didn't find a MySQL source we could open for this guide, so it gives no MySQL-specific advice.
2. Timestamp exposure: v4
Anyone can read a v7 UUID's time. The RFC calls embedded timestamps "a very small attack surface" (IETF: RFC 9562, section 8). The risk is small, but the time tells people when a record was created. On order IDs, account IDs or document links that customers can see, those times could hint at your signup or sales patterns. If that matters, use v4.
The time is also only a claim: the tool notes that "anyone can build a UUIDv7 with any timestamp". Don't use it as proof of when a record was created.
3. Randomness and collisions: both are enough for most uses
No standard gives a collision probability. RFC 9562 asks you to "weigh the consequences of UUID collisions" for your application (IETF: RFC 9562, section 6.7).
Here is the arithmetic for the random bits, assuming a good random source and the usual birthday approximation:
- v4: 2^122 is about 5.3 × 10^36 possible values. You'd need about 2.7 × 10^18 v4 UUIDs before the chance of any duplicate reaches 50%.
- v7: only IDs from the same millisecond can collide, and each millisecond has 2^74 random values, about 1.9 × 10^22. The 50% point is about 1.6 × 10^11 IDs within one millisecond.
This is arithmetic, not a guarantee. A weak random source breaks it, which is why the RFC asks for a cryptographically secure generator.
4. Security: neither version
RFC 9562 says implementations "SHOULD NOT assume that UUIDs are hard to guess". For password-reset links, API keys or session tokens, use a dedicated secret. If a UUID takes part in any security operation, the RFC says v4 "SHOULD be utilized" (IETF: RFC 9562, section 8). The RFC gives that advice straight after its note on timestamps. v4 still isn't a secret.
5. Tooling support: v4 is everywhere, v7 is newer
- Browsers:
crypto.randomUUID()generates "a v4 UUID using a cryptographically secure random number generator". There is no built-in v7 (MDN: Crypto.randomUUID()). - Node.js:
crypto.randomUUID()generates version 4, andcrypto.randomUUIDv7()generates version 7. It was "Added in: v26.1.0", and its timestamp "is not guaranteed to be strictly increasing" (Node.js: Crypto). - PostgreSQL:
uuidv4()anduuidv7()are listed in the current documentation (PostgreSQL: UUID functions).uuidv7()first appears in the PostgreSQL 18 documentation. - Python:
uuid.uuid7()was "Added in version 3.14". It uses a 42-bit counter "to guarantee monotonicity within a millisecond" (Python: uuid module). - .NET:
Guid.CreateVersion7()creates a GUID "according to RFC 9562" and is documented for .NET 9 and later (Microsoft Learn: Guid.CreateVersion7).
If your stack is older, you may need a library for v7, while v4 is almost certainly built in.
The test: 20 of each, checked by script
On 19 November 2026 we ran the tool in Chromium with these settings: v4 (random), How many UUIDs 20, Format set to Canonical, and Uppercase hexadecimal (A–F) unticked. We pressed Generate UUIDs, then Download TXT and Download CSV. Then we chose v7 (time-ordered), which cleared the old list, and repeated the steps.
The heading read "20 UUIDs (version 4), in the order generated", and the files were named uuids.txt and uuids.csv. The CSV had a uuid header line and the same 20 values. A Python script then checked both batches:
- Version and variant: every v4 value had
4as its 13th digit, and every v7 value had7. The 17th digit was always8,9,aorb. Python's ownuuidmodule reported the same versions and the standard variant. - The v7 time: all 20 v7 values decoded to 19:56:54.613 UTC on 19 November 2026. The browser clock read 19:56:54.585 just before the click and 19:56:54.651 just after the list appeared, so the timestamp is the real generation time. The first v7 value was
01a1f562-2dd5-7e91-8da5-bc9ab4a2212c. - v4 order: sorting the 20 v4 values put them in a different order from generation. That's expected, since they're random.
Sort order across and within milliseconds
We pressed Generate UUIDs three more times, about 25 ms apart, which gave four v7 batches of 20, each with its own millisecond. When we sorted all 80 as text, every batch came out in click order and the timestamps never went backwards.
Within a batch, though, sorting didn't keep generation order. All 20 values shared one millisecond, so their order came from the random bits. The tool says this in its limitations: it has no counter, so IDs "created in the same millisecond can sort in any order". A batch of 1,000 spanned only two milliseconds.
RFC 9562 lets generators add a counter or a finer time fraction when batches must stay in order (IETF: RFC 9562, section 6.2). Python's uuid7() does this. For index locality, a few random positions within one millisecond don't matter. If you need strict creation order, store a separate sequence or timestamp column, or use a generator with a counter.
The text sorted correctly here because every value was lowercase. Keep one case when you sort UUIDs as text, because uppercase letters sort before lowercase ones in byte order.
Check a UUID you were given
Paste the ID into UUID or GUID to check and press Validate. We tried the example values printed in RFC 9562's appendix, in several forms:
- Uppercase v4:
919108F7-52D1-4320-9BAC-F847DB4148A8gave "Valid UUID — version 4." with Variant "RFC 9562 (binary 10)" and the lowercase canonical form. - The same v4 in braces: the result was the same, and Input format read "Braces (GUID style)".
- The RFC's v7 with the urn:uuid: prefix: "Valid UUID — version 7." with Encoded time (UTC) "2022-02-22T19:22:22.000Z", the time the RFC used to build it.
- A v1 UUID (
C232AB00-9414-11EC-B3C8-9F6BDECED846): "Valid UUID — version 1." with "1 — time-based (Gregorian)". v1 is valid but older, and the RFC prefers v7. - One digit short: "Not a valid UUID. A UUID has exactly 32 hexadecimal digits; this has 31."
- A g in the last place: "Not a valid UUID. A UUID may contain only the hexadecimal digits 0–9 and a–f (plus hyphens)."
Use this to confirm what a library or database really produced before you depend on it, for example that a "v7" column holds 7s, not 4s.
Before you choose
- Primary key in a B-tree index? Prefer v7, and store it as binary where you can.
- Will customers, partners or the public see the ID? If its creation time shouldn't be visible, use v4.
- Is it standing in for a password, key or token? Use neither. Generate a real secret.
- Do you need strict order within one millisecond? Use a generator with a counter, or a separate sequence column.
- Does your language or database generate v7? Check the version, then validate a sample to confirm it.

