Both are 128-bit UUIDs that look alike and fit the same columns. The difference is the first 48 bits: random in v4, the creation time in v7. That one change decides how they behave in a database and what they reveal.

The short answer

Use v7 for database keys and for anything you want to sort by creation time. Use v4 when an ID must not reveal when it was made, for example in a public link. Both are unique enough that you never have to worry about duplicates.

If you can't decide, take v7. RFC 9562, the current UUID standard, recommends it for new systems.

Side by side

v4 v7
Content 122 random bits 48-bit Unix time in milliseconds, then random bits
Random bits 122 62 to 74, depending on the generator
Sorts by creation time No Yes
Shows when it was made No Yes, to the millisecond
New rows in a B-tree index Anywhere At the end
Defined in RFC 4122 (2005), now RFC 9562 RFC 9562 (2024)
Built in Almost everywhere Newer versions, for example PostgreSQL 18, .NET 9, Python 3.14

What the two look like

v4 3f2b8c1e-6d4a-4f0b-9a7e-2c5d8e1f4a6b ^ ^ version 4, variant everything else is random v7 01a183c6-500e-71fb-8e3a-1f489e0ea1c4 ^^^^^^^^^^^^^ time: 28 October 2026, 18:29:34 UTC ^ ^ version 7, variant 

You can tell them apart by the first digit of the third group: 4 or 7. Paste any UUID into the decoder to see its version and, for v7, the exact time.

Uniqueness: both are safe

With v4, a duplicate needs two of the same 122 random bits. You would have to create about 2.7 quintillion v4 UUIDs for a 50 % chance of a single collision.

With v7, two UUIDs can only collide if they were made in the same millisecond and their random parts match too. A busy system creates many UUIDs per millisecond, but each one still has at least 62 random bits. For real workloads that is as safe as v4. The collision calculator shows the odds for both versions with your own numbers.

Database speed

Most databases store primary keys in a B-tree index, sorted by value. A new v4 key lands at a random place in that tree. With a large table, the right index page is often not in memory, has to be read from disk and may have to be split. Over time the index gets bigger and writes get slower.

A new v7 key is larger than all keys before it, so it lands at the end of the index. The last pages stay in memory, pages fill up completely and inserts stay fast as the table grows. Range queries by creation time also get cheaper, because recent rows sit next to each other.

For small tables you won't notice a difference. For tables with millions of rows it is often the main reason to switch. The guide UUIDs as primary keys explains the details for PostgreSQL, MySQL and SQL Server. One catch: SQL Server sorts uniqueidentifier by its last bytes first, so v7 does not sort by time there. The SQL Server page shows what to do instead.

Privacy: what v7 reveals

Anyone who sees a v7 UUID can read when it was created. For an order ID that is usually harmless. For a user ID in a public profile URL it tells everyone when that person signed up. For a document link it tells when the document was made.

v4 reveals nothing at all. A common pattern is to use both: v7 as the internal primary key, and a separate v4 or other random ID for anything that leaves your system.

Neither version is a secret. Don't use a UUID of any version as a password, session token or access key.

Sorting and paging

With v7 keys, ORDER BY id gives you the rows in creation order without a separate timestamp column. That also makes keyset paging easy: ask for rows with an id greater than the last one you saw.

Two limits apply. The order is only as good as the clocks of the machines that create the IDs, so UUIDs from different servers within the same few milliseconds may not be in perfect order. And within one millisecond, only a generator with a counter keeps the order. The uuidgen.net v7 generator uses one, as described in RFC 9562.

Switching from v4 to v7

You don't have to change existing data. v4 and v7 have the same size and format, so they fit the same column type. Keep the old v4 keys as they are, because other tables, URLs and logs refer to them, and create new keys as v7. The index slowly turns into one where new rows are added at the end.

What you need is a v7 generator in your code or database. Many platforms have one built in by now, older ones need a small library. The v7 page lists one-liners for JavaScript, Python, Java, C#, Go and PostgreSQL, and the code examples go into detail for each language.

And v5?

v5 is in a different category. It is not random and has no time: the same namespace and name always give the same UUID. Use it when two systems must compute the same ID independently, and v4 or v7 for everything else. The guide Which UUID version should you use? covers v5 and the other versions.

Summary

You need Take
Primary keys in a large table v7
IDs sorted by creation time v7
Public IDs that reveal nothing v4
Wide support on old platforms v4
The same ID from the same input v5

You can create both in the browser: the v4 generator and the v7 generator.

This article first appeared on uuidgen.net, where the guide is also available in German, Spanish, French, Japanese and Portuguese.