Which ID should I use?
| Type | Example | Best for |
|---|---|---|
| UUID v4 | 9b2e…-4c1a-… | The universal default. 122 random bits, supported by every database and language. Doesn't reveal when it was made. |
| UUID v7 | 0192…-7b3c-… | Database primary keys. It starts with a timestamp, so new rows are inserted in order, which keeps B-tree indexes compact and fast. Standardised in RFC 9562 (2024). |
| ULID | 01J8Z3… | Sortable IDs that are shorter (26 characters), case-insensitive and URL-safe. Popular in event logs and distributed systems. |
| Nano ID | V1StGXR8_Z5jdHi6B-myT | Short IDs in URLs, such as share links or invite codes. The default 21 characters are about as collision-resistant as a UUID v4. |
UUID v4 vs UUID v7 for primary keys
Random v4 UUIDs land all over the index, so each insert touches a different page. On large tables that means more disk reads, page splits and a bloated index. UUID v7 puts a millisecond timestamp in the first 48 bits, so new keys arrive in order, much like an auto-increment number, while still being unique across servers without coordination. PostgreSQL 18 adds a built-in uuidv7() function, and libraries exist for Java, .NET, Go and Python.
The catch: a v7 UUID reveals roughly when the record was created. If that matters, for example for user IDs in public URLs, use v4.
How unique is a UUID?
A version 4 UUID has 122 random bits. You would need to generate about a billion UUIDs per second for around 85 years before the chance of a single duplicate reached 50%. In practice, a bug in how the random numbers are produced is a far bigger risk than a collision. This page uses your browser's cryptographically secure generator (crypto.getRandomValues).
Generating UUIDs in code
- Java:
UUID.randomUUID()for v4. - JavaScript:
crypto.randomUUID()in browsers and Node.js. - Python:
uuid.uuid4(); Python 3.14 addsuuid.uuid7(). - PostgreSQL:
gen_random_uuid(), anduuidv7()from version 18. - MySQL:
UUID()returns a version 1 UUID; store it asBINARY(16)withUUID_TO_BIN(UUID(), 1)for better index order.
Frequently asked questions
What is the difference between a UUID and a GUID?
They are the same thing. GUID is Microsoft's name for a UUID. GUIDs are often written in uppercase and wrapped in braces, which you can switch on above.
Can I tell when a UUID was created?
Only for time-based versions. Paste a v1, v6 or v7 UUID, or a ULID, into the decoder to see its timestamp. Version 4 UUIDs are fully random and contain no time.
Are UUID v7 IDs from this page sortable?
Yes. IDs generated in the same millisecond use an increasing counter, so a batch sorts in exactly the order it was created. ULIDs work the same way.
Should I store UUIDs as text or binary?
Use the database's native type when there is one (PostgreSQL uuid, SQL Server uniqueidentifier). Otherwise store 16 bytes in a binary column; text takes 36 bytes and compares more slowly.
Are the IDs sent anywhere?
No. They are generated in your browser and never leave your device.