What is a NanoID?
NanoID is a small unique identifier designed to be shorter than a UUID and safe in URLs. The default is 21 characters from a 64-character alphabet: uppercase, lowercase, digits, _, and -. That is about 126 bits of entropy, which is enough uniqueness for almost any app without the hyphens and hex padding of a UUID.
The format comes from the nanoid library. This generator uses the same unbiased sampling idea and crypto.getRandomValues() in your browser.
Size and alphabet
Collision resistance is alphabet size ^ length. Shorten the ID only when you know the volume you will mint. A 12-character URL-safe ID is fine for a small product catalog. A 6-character numeric code is not enough for a public signup token.
- URL-safe (default): Best for public IDs in links and filenames.
- No lookalikes: Drops 0/O, 1/l/I and similar pairs so humans can read the ID aloud.
- Numbers or hex: Use when the consumer only accepts digits or hex.
NanoID vs UUID vs ULID
- Use NanoID for short public slugs, invite codes, and API IDs where URL safety and length matter.
- Use UUID v4 or v7 when you need the RFC 9562 format or a native
uuid column. Generate those with the UUID Generator.
- Use ULID when the ID should sort by time as a string. Generate those with the ULID Generator.
NanoIDs are random, so they behave like UUID v4 in B-tree indexes. If you need time-ordered primary keys, pick UUID v7, ULID, or a KSUID.