51NAV
Explained

UUID v1 vs v4, and Why ULID Sorts Better

UUID v1 leaks your MAC address and v4 is random. ULID stays sortable. Here is how the formats differ and when to pick each.

2 min read Beginner
#uuid #ulid #identifier #generator
Table of Contents

Three identifiers, three trade-offs

UUID v1UUID v4ULID
Layouttimestamp + MACrandommillisecond time + random
Sortable by timeYes (but leaks MAC)NoYes
PrivacyWeak (MAC exposed)StrongMedium (time only)
Alphabethex + -hex + -Crockford Base32

UUID v1

Built from a timestamp and the node’s MAC address. It sorts and is unique without a coordinator, but the MAC is a privacy leak and the time reveals when you created the ID.

UUID v4

Pure random (122 bits). No ordering, no leakage — the safe default when you just need a unique token and do not care about sort order.

f47ac10b-58cc-4372-a567-0e02b2c3d479   (v4)

UUID v7 / v8

Newer time-ordered UUIDs that keep v4’s privacy story while sorting like ULID. If your stack supports them, they are a great middle ground.

ULID

ULID leads with a millisecond timestamp in Base32, so string sorting equals chronological order — perfect as a database primary key where you want inserts to land in time order.

01ARZ3NDEKTSV4RRFFQ69G5FAV   (timestamp | randomness)

The catch: 26 chars in Crockford Base32, so it is not drop-in compatible with UUID columns expecting 36-char hex.

When to pick which

  • Random opaque token: UUID v4.
  • Sortable DB primary key: ULID or UUID v7.
  • Avoid v1 unless you specifically need MAC-based uniqueness and accept the leak.

Generate them

Next steps

Frequently asked questions

Is a UUID v4 guaranteed unique?

Not mathematically, but the 122-bit random space is so large that collisions are astronomically unlikely in practice. Uniqueness comes from randomness, not from a central authority.

Why avoid UUID v1?

v1 embeds the MAC address and a timestamp, which can fingerprint a machine and reveal creation time. Prefer v4 (random) or v7/v8 (time-ordered) for privacy.

What makes ULID sortable?

ULID puts a millisecond timestamp first, encoded in Crockford Base32, so lexicographic order matches creation time — handy as a primary key in a database.

Guide Info

Category
Explained
Difficulty
Beginner
Reading Time
2 min
Tags
#uuid #ulid #identifier #generator

Next guide

UTF-8 vs GBK: Why Chinese Text Turns to Mojibake

Garbled Chinese (乱码) is almost always a charset mismatch: bytes encoded one way are decoded another. Here is the root cause and how to fix it.

View Next Guide