Nano ID is a unique-string algorithm designed by Andrey Sitnik as a smaller, faster, URL-friendly alternative to UUID v4. The default output is 21 characters drawn from a 64-character URL-safe alphabet (A-Z, a-z, 0-9, underscore, dash), giving roughly 126 bits of entropy — slightly higher than UUID v4's 122 bits while shaving 15 characters off the length.
This generator implements the official algorithm directly rather than depending on the npm package, but the math is identical. It pulls cryptographically secure bytes from window.crypto.getRandomValues, the same Web Crypto primitive used by UUID v4 generators and by browsers' built-in crypto.randomUUID(). The values are not derived from Math.random, which is not safe for IDs that must be unguessable.
Each byte from getRandomValues covers 0-255, but the alphabet rarely has exactly 256 characters. To avoid modulo bias the generator computes a power-of-two mask (the smallest mask whose values cover the alphabet without skewing probability), reads bytes in chunks, and discards values that exceed the alphabet length. This is why the alphabet size affects both entropy and the speed of generation.
Custom alphabets are fully supported — you can pass an alphabet as small as two characters or as large as Unicode allows. The Entropy stat in the UI is calculated as length * log2(alphabetSize) and updates as you type. Smaller alphabets like hex or numeric reduce entropy per character; you can compensate by increasing length. The Nano ID collision calculator at zelark.github.io/nano-id-cc is a good companion for picking a size.
Common pitfalls: shrinking IDs below 8 characters with a small alphabet leads to real collision risk in any system that grows beyond a few thousand records; using a numeric-only alphabet creates IDs that can be confused for primary key integers in logs; and including ambiguous characters like O, 0, l, 1 in custom alphabets degrades human readability when IDs are shared verbally. The default URL-safe alphabet sidesteps the URL-encoding issues you would hit with characters like + or /.
Practical sizing: a 21-character Nano ID has a 1-in-10^15 collision probability for the first billion IDs, which is comfortably below the threshold most engineering teams consider acceptable. Dropping to 10 characters with the same alphabet is reasonable for systems generating millions of IDs but not billions; a 6-character ID is appropriate only for short-lived ephemera like share codes that expire in minutes.
Generation happens entirely in your browser. The bytes never leave the page, there is no rate limit, and you can request up to 1000 IDs at once for seeding test datasets or pre-allocating identifiers in offline-first applications.