← All tools

NanoID Generator

Generate NanoIDs — short, URL-safe, collision-resistant random IDs popularized by NanoID and used widely for web URLs, session tokens, and database keys. A NanoID is a string drawn from a configurable alphabet (default 64 URL-safe characters) at a configurable length (default 21), produced from cryptographic randomness. Generation uses the canonical bitmask algorithm, which rejects out-of-range random bytes rather than taking them modulo the alphabet size — so no symbol is favoured and there's no modulo bias. Everything runs locally in your browser; randomness comes from the Web Crypto API.

Generate

Alphabet
Length
Count
Preset

NanoID draws each character uniformly at random from an alphabet. The naive way — alphabet[randomByte % alphabet.length] — is biased whenever the alphabet size doesn't divide 256: symbols early in the alphabet appear slightly more often. NanoID instead masks each random byte down to the next power of two above the alphabet size (mask = (1 << ⌈log₂ k⌉) − 1) and rejects any masked value ≥ k, drawing another byte instead. Every accepted value lands in 0..k−1 exactly evenly. With a 64-symbol alphabet the mask is 63 and nothing is rejected (64 divides the 64-value range), so generation is waste-free; smaller alphabets reject proportionally more. The default 21 characters from a 64-symbol alphabet give 64²¹ ≈ 1.4×10³⁸ possibilities — about 121 bits of entropy, enough that collisions are astronomically unlikely until ~10¹⁹ IDs. Pairs with the UUID, ULID, and Snowflake generators. Everything runs locally — nothing leaves your browser.