UUID Generator

UUID v4 vs v1

Most developers just need UUID v4. But if you are building a distributed database or need time-ordered IDs, you need to understand the difference. Here it is.

UUID v4UUID v1
Source122 random bitsTimestamp + MAC + clock
Sortable by timeNoYes
Reveals MAC addressNoYes (historically)
PredictableNoPartially (same millisecond)
Recommended forGeneral useTime-ordered distributed IDs
SupportUniversalWidespread

UUID v4: random, simple, recommended

UUID v4 is generated from 122 random bits using a cryptographically secure random number generator. There is no timestamp, no MAC address, no relationship between sequentially generated UUIDs. Each one is independent.

The probability of collision is negligible: with one billion UUIDs generated per second, you would need to run for roughly 86 years before the probability of any collision reached 50%. For virtually every application, v4 UUIDs are unique enough.

Use v4 for: database primary keys, session tokens, API keys, idempotency keys, file names, log correlation IDs, and any use case where you just need a unique identifier.

v4: f47ac10b-58cc-4dec-a716-446655440000

UUID v1: time-based, sortable

UUID v1 encodes a 60-bit timestamp representing 100-nanosecond intervals since October 15, 1582 (the UUID epoch). It also includes a clock sequence (to handle clock resets) and a node identifier — traditionally the MAC address of the generating machine.

The key property: v1 UUIDs generated sequentially are sortable by time. This matters when UUIDs are used as primary keys in distributed databases like Cassandra, where insertion order affects read performance. Sequential v1 UUIDs write to the same partition range, reducing hot spots.

The downsides: v1 historically exposed the MAC address of the server (a privacy concern), and UUIDs generated within the same 100ns window can be predictable. Modern v1 implementations often use a random node instead of the actual MAC address.

v1: 6ba7b810-9dad-11d1-80b4-00c04fd430c8

UUID v7: the modern alternative to v1

UUID v7 was introduced to solve v1's problems. It uses a 48-bit Unix millisecond timestamp in the most significant bits, followed by random bits — giving you both time-ordering and randomness without exposing system information. If you need sortable UUIDs and your environment supports v7, it is preferable to v1.

The recommendation

99% of the time: use UUID v4. It is simple, secure, has no privacy concerns, and is the most universally supported version. Only reach for v1 (or v7) if you specifically need time-ordered UUIDs for database performance reasons.

Generate UUID v4 or v1 now

Switch between versions, bulk generate, toggle format options. Free, no sign-up.

Use UUID Generator →

Frequently asked questions

Should I use UUID v4 or v1?

Use UUID v4 for almost everything. It is random, requires no knowledge of the machine or timestamp, and is the most widely supported version. Use UUID v1 (or the newer v7) when you specifically need UUIDs to be sortable by creation time — for example, as primary keys in Cassandra or when you want to extract the timestamp from the ID later.

What is UUID v4?

UUID v4 generates its value from 122 random bits (6 bits are reserved for version and variant markers). The character '4' at position 13 indicates version 4. Each UUID v4 is independent — there is no relationship between sequentially generated v4 UUIDs. Modern browsers provide crypto.randomUUID() which generates cryptographically random v4 UUIDs.

What is UUID v1?

UUID v1 encodes a 60-bit timestamp (representing 100-nanosecond intervals since October 15, 1582), a 14-bit clock sequence, and a 48-bit node (typically the MAC address of the generating machine). The timestamp makes v1 UUIDs sortable by creation time, but it also means that UUIDs generated at the same millisecond on the same machine can be predictable.

Is UUID v4 safer than v1?

Yes, for most use cases. UUID v1 encodes the MAC address of the generating machine, which leaks hardware information and can allow attackers to predict UUIDs generated in the same time window. UUID v4 is fully random and reveals nothing about the generating system. For security-sensitive identifiers like session tokens, v4 is the correct choice.

Can I sort UUID v4 by creation time?

No. UUID v4 is random and has no time component. Two v4 UUIDs generated a microsecond apart are indistinguishable by value. If you need time-sortable UUIDs, use UUID v1 or the newer UUID v7 (which embeds a Unix millisecond timestamp in the first 48 bits, making it both random and sortable).

What is UUID v7 and should I use it instead?

UUID v7 is a newer version that combines a Unix millisecond timestamp with random bits. This makes v7 UUIDs both unique (like v4) and time-sortable (like v1), without exposing MAC address information. If you need sortable UUIDs and your platform supports v7, it is generally better than v1. However, v7 is not yet in the core RFC 4122 standard and support varies across languages and databases.