DevTools Logo

UUID, ULID & Token Formats Cheat Sheet

Quick reference for identifier and token formats: UUID v1-v8, ULID, NanoID, BIP39 mnemonics, and common token grammars.

Reference
uuid
ulid
nanoid

Identifiers come in distinct families: time-ordered (ULID, UUIDv7), random (UUIDv4, NanoID), and hash/name-derived (UUIDv3/v5/v8). Choose by the property you need — sortability, randomness, or determinism.

UUID Versions at a Glance

Table
VersionBased onDeterministicSortableNotes
v1MAC + timestampNoRoughlyPrivacy leak (MAC address); use v7 instead
v3MD5 of namespace+nameYesNoLegacy
v4RandomNoNoMost common; not sortable
v5SHA-1 of namespace+nameYesNoPreferred deterministic variant
v7Unix ms timestamp + randomNoYesTime-ordered, collision-safe
v8CustomConfigurableConfigurableExperimental, vendor-defined

Example v4: f47ac10b-58cc-4372-a567-0e02b2c3d479 Example v7: 01901b2f-bd3a-7a3c-9f1e-2e4a5b6c7d8e

ULID

ULID is a 26-character Crockford-base32 string: 10 chars of UNIX timestamp (ms) + 16 chars of randomness. Sortable lexicographically and URL-safe.

text
01AN4Z07BY      2naidob2sample
└─ timestamp ─┘ └─ randomness ─┘
01AN4Z07BY79KA1307SR9XYNV
js
import { ulid } from "ulid";
const id = ulid(); // "01HHZ7XZJY..."

NanoID

NanoID is a compact random ID (21 chars by default, 64-bit alphabet) used widely in React/database defaults. Length and alphabet are configurable.

js
import { nanoid } from "nanoid";
nanoid();        // "V1StGXR8_Z5jdHi6B-myT"
nanoid(10);      // shorter, 10 chars

Token Generation

Random tokens for API keys, invites, and session tokens should use a CSPRNG, never Math.random.

js
// Node — 32 random bytes as base64url
import { randomBytes } from "node:crypto";
const token = randomBytes(32).toString("base64url"); // 43 chars
python
import secrets
token = secrets.token_urlsafe(32)   # ~43 chars
Table
Token typeExampleEntropy source
API keysk_live_4fC9...32+ random bytes
JWTeyJhbGciOi.JIUzI1NiIs...Signed claims, not random
BIP39 mnemonicabandon ability able...128–256 bits of entropy
Base589zQ4vF...BTC-style alphabet

Common Pitfalls

[!WARNING] UUIDv1 embeds the MAC address and timestamp — an information leak. Prefer v4 for random or v7 for time-ordered.

[!TIP] For database primary keys that must sort by creation order, use ULID or UUIDv7 — both are lexicographically ordered and avoid the index fragmentation of random UUIDv4.

References