NanoID Generator
Understand NanoID Generator
Generates short, URL-safe random identifiers with a configurable length and alphabet.
How it works
Bytes come from crypto.getRandomValues and are masked down to the alphabet size, with out-of-range values discarded so that every character stays equally likely. The 21-character default over a 64-symbol alphabet (A-Z, a-z, 0-9, underscore, hyphen) carries 126 bits of randomness — more than the 122 bits in a UUID v4 — in 21 characters rather than 36. Shortening the id or narrowing the alphabet cuts that proportionally: 21 characters of hex is only 84 bits.
When to use it
- Public-facing ids in URLs where a 36-character UUID is unwieldy.
- Share links, invite codes, and document ids that people may paste around.
- File names and object keys that must be safe in a URL and on a command line.
- A hex or numeric-only id for a downstream system that rejects other characters.
- Trimming id length in a system where storage or URL length genuinely matters.
Watch out for
- Shortening is not free. Dropping from 21 default-alphabet characters to 10 takes you from 126 bits to 60, where collisions stop being theoretical at scale. Size the length to your generation volume, not to what looks tidy.
- The default alphabet contains hyphen and underscore. Both are URL-safe, but an id beginning with a hyphen is read as a flag by many command-line tools — use the alphanumeric set for values that will be passed as arguments.
- Unguessable is not authorized. A NanoID in a URL is a capability: everyone who receives the link has whatever access the link grants, unless permissions are checked separately.
- A numeric-alphabet id is a string, not a number. Parsing it as an integer drops leading zeros and loses precision beyond about 16 digits.
Not the right tool for: Database primary keys where insert order matters. NanoIDs are pure randomness with no time component, so they fragment indexes exactly the way UUID v4 does — use ULID or UUID v7 there.
Frequently Asked Questions
How does NanoID compare to UUID?
NanoID's 21-character default has ~126 bits of entropy, similar to UUID v4 (122 bits), but uses only 21 chars vs 36 (UUID with hyphens). It's URL-safe, has no hyphens, and avoids the overhead of UUID formatting. Suitable for IDs in URLs, filenames, and databases.
What happens if I shorten the ID length?
Shorter IDs have more collision risk. Use NanoID's collision calculator: for 10 IDs/second, a 21-char ID needs ~149 years to reach 1% collision probability. A 13-char ID needs only ~12 years at the same rate. Scale length to your generation volume.
Can I use a custom alphabet?
Yes — replace the default alphabet (A-Za-z0-9_-) with any characters. Numeric only (0-9) for numeric-looking IDs, hex (0-9a-f) for hex IDs, or your own set. The tool shows the collision probability for your configuration.
How to Use NanoID Generator
- Paste or type your input in the input area above.
- The tool processes your input automatically or click Run.
- Copy or download the result using the action buttons.
- Use Ctrl+Enter to run quickly from the keyboard.