uuid.lol

Nano ID Generator

Press c to copy or r for a new one

Alphabet and length

64 characters: useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict

Collision odds

Possible IDs
8.5 Ă— 1037
Entropy
126.0 bits
Until a 1% chance of a collision
149 billion years

That is a 1% chance of any single collision ever happening, with IDs minted at that rate the whole time.

Generate in bulk

What is a Nano ID?

A Nano ID is a random string and nothing else. The default is 21 characters pulled from a 64-character alphabet of letters, digits, underscore and hyphen, taken from a cryptographically secure source.

A UUID spends part of itself on structure. Six bits go to the version and variant fields, which is why a v4 holds 122 random bits inside its 128. A Nano ID has no version, no variant and no timestamp, so all 126 bits of a 21-character default are random. It writes more entropy in 21 characters than a UUID manages in 36.

Opaque on purpose

A Nano ID gives away nothing about where it came from. Compare that with a UUID v7 or a ULID, which both carry the millisecond they were created. Anyone holding two of those can subtract one from the other and learn how fast you are creating rows.

That is the reason to reach for a Nano ID when an ID is going to end up somewhere public: a share link, an invite email, an API response a customer can read. Internally, where sortable keys earn their keep, a time-ordered format is usually the better pick.

How long should yours be?

There is no length that is right everywhere, because the answer depends on how many IDs you will actually mint and over what period. The calculator above does that arithmetic for you. Set the alphabet, put in the rate you expect when things are going well, and read off how long you have before a 1% collision chance.

If that number comfortably outlives the thing you are building, the length is fine. Twelve characters is plenty for a URL slug on a site creating a few thousand rows a day. The default 21 exists so you can drop it in wherever a UUID would have gone and stop thinking about it.

Characters people misread

Some IDs get read aloud over the phone, copied off a printed receipt, or typed in from a screenshot. Those run into the look-alike pairs: zero and capital O, the digit one against lowercase l and capital I, five and S, two and Z.

The no look-alikes alphabet in the picker drops one of each pair, leaving 48 characters. That costs about 0.4 bits per character against a plain alphanumeric set, so two extra characters buy the entropy back and you come out ahead.

A smaller alphabet needs a longer ID

Entropy is the length multiplied by the base-2 logarithm of the alphabet size. Hexadecimal gives you exactly 4 bits per character. The URL-safe set gives 6. Decimal digits give about 3.32.

So the 126 bits of a default Nano ID take 32 hexadecimal characters to match, or 38 decimal digits. Shortening the alphabet to make IDs easier to read or safer to double-click is a fair trade, as long as you add the characters back. Change the alphabet in the picker and watch the entropy figure move.

Generate one in code

TypeScript

// npm install nanoid
import { customAlphabet, nanoid } from "nanoid";

nanoid();
//=> "V1StGXR8_Z5jdHi6B-myT"

const short = customAlphabet("0123456789abcdef", 12);
short();
//=> "a3f9c0182b7d"

Python

# pip install nanoid
from nanoid import generate

generate()
#=> 'V1StGXR8_Z5jdHi6B-myT'

generate('0123456789abcdef', 12)
#=> 'a3f9c0182b7d'

Go

// go get github.com/matoous/go-nanoid/v2
import gonanoid "github.com/matoous/go-nanoid/v2"

id, err := gonanoid.New()
//=> "V1StGXR8_Z5jdHi6B-myT"

short, err := gonanoid.Generate("0123456789abcdef", 12)
//=> "a3f9c0182b7d"