🆔 NanoID Generator
By ToolNimba Web Dev Team · Updated 2026-06-19
Set a length and count, then press Generate.
A NanoID is a short, URL-safe, random string used as a unique identifier, the kind you see in shortened links, database keys, and React list keys. This generator builds NanoIDs entirely in your browser using the crypto random source, so the values never leave your machine. Pick the length (21 is the default), choose how many you need, and copy each one with a click. Compared with a UUID, a NanoID is shorter and reads cleanly in a URL because it avoids hyphens by default and uses only characters that are safe in links.
What is the NanoID Generator?
NanoID is a tiny, popular library for generating unique string IDs. Its default alphabet has 64 symbols: the 26 uppercase letters A-Z, the 26 lowercase letters a-z, the 10 digits 0-9, plus an underscore (_) and a hyphen (-). Every one of those characters is safe to drop straight into a URL, an HTML id attribute, or a filename without escaping, which is the whole point of the design. Each character is chosen at random from that alphabet, so a 21-character ID encodes 21 x 6 = 126 bits of randomness.
The quality of the randomness matters more than the length. This tool reads bytes from crypto.getRandomValues, the browser cryptographically secure random number generator, rather than Math.random, which is predictable and unsuitable for IDs. Because the alphabet has exactly 64 symbols, each random byte is masked to its low 6 bits and mapped directly to one character. That mapping is uniform, so there is no modulo bias, every character is equally likely and the IDs are unpredictable.
NanoID is often compared with UUID version 4. A UUIDv4 is 36 characters long, written as five hyphen-separated hex groups, and carries 122 bits of randomness. A default 21-character NanoID is 15 characters shorter, reads better in a URL, and actually has slightly more entropy (126 bits). For most applications the collision risk of a 21-character NanoID is negligible: you would need to generate billions of IDs per second for centuries before a collision became likely. Shorten the length only when your ID space is small and you understand the trade-off, since fewer characters means fewer possible IDs and a higher chance of a clash.
When to use it
- Creating short, readable IDs for URLs, share links, and slugs where a long UUID would look ugly.
- Generating primary keys or record IDs for a database when you want them assigned on the client side.
- Producing stable keys for items in a list when building React, Vue, or other component UIs.
- Making unique filenames, upload tokens, or session identifiers that are safe to use without escaping.
How to use the NanoID Generator
- Set the ID length you need (21 is the standard default).
- Enter how many IDs you want to generate at once.
- Press Generate to build the list using your browser secure random source.
- Copy a single ID with its Copy button, or use Copy all to grab the whole list.
Formula & method
Worked examples
You want the entropy of a default 21-character NanoID.
- Alphabet size = 64 symbols (A-Za-z0-9 plus _ and -)
- Bits per character = log2(64) = 6
- Total bits = 21 x 6 = 126
Result: A 21-character NanoID carries about 126 bits of randomness.
You shorten the ID to 10 characters for compact share links.
- Bits per character = log2(64) = 6
- Total bits = 10 x 6 = 60
- Possible IDs = 64^10 which is about 1.15 x 10^18
Result: A 10-character NanoID has 60 bits and roughly 1.15 quintillion possible values.
NanoID length compared with entropy and total possible IDs
| Length | Entropy (bits) | Possible IDs (64^n) |
|---|---|---|
| 8 | 48 | about 2.81 x 10^14 |
| 10 | 60 | about 1.15 x 10^18 |
| 16 | 96 | about 7.92 x 10^28 |
| 21 (default) | 126 | about 8.51 x 10^37 |
NanoID vs UUID version 4 at a glance
| Property | NanoID (default) | UUID v4 |
|---|---|---|
| Length | 21 characters | 36 characters |
| Alphabet | A-Za-z0-9_- (64 symbols) | 0-9a-f and hyphens (hex) |
| Entropy | about 126 bits | about 122 bits |
| URL-safe by default | Yes | Yes, but longer |
Common mistakes to avoid
- Shortening the ID too much. Cutting the length to save space lowers the number of possible IDs fast. Fewer characters means a higher chance two IDs collide, so keep close to 21 unless your ID space is genuinely small and low traffic.
- Assuming a NanoID is a UUID. A NanoID is not a UUID and does not follow the RFC UUID format. If a system requires a real UUID (for example a database UUID column or an API that validates the format), use a UUID generator instead.
- Treating an ID as a secret. A NanoID is unguessable but it is still an identifier, not a password or token. Do not rely on it alone to protect private data, because IDs often appear in URLs and logs.
- Generating IDs with Math.random. Math.random is not cryptographically secure and can repeat or be predicted. This tool uses crypto.getRandomValues so the IDs are properly random, which matters whenever uniqueness or unpredictability counts.
Glossary
- NanoID
- A short, URL-safe, random string identifier built from a 64-symbol alphabet, designed to be compact and collision-resistant.
- URL-safe
- Made only of characters that can appear in a URL without being escaped or encoded, such as letters, digits, underscore, and hyphen.
- Entropy
- A measure of randomness in bits. More bits means more possible values and a lower chance of two IDs colliding.
- Collision
- When two independently generated IDs turn out to be identical, which breaks the assumption that each ID is unique.
- CSPRNG
- A cryptographically secure pseudo-random number generator, such as the browser crypto.getRandomValues, suitable for IDs and tokens.
Frequently asked questions
What is a NanoID?
A NanoID is a short, random, URL-safe string used as a unique identifier. By default it is 21 characters drawn from a 64-symbol alphabet (A-Za-z0-9 plus underscore and hyphen), making it shorter than a UUID while staying easy to read and safe in URLs.
How is a NanoID different from a UUID?
A default NanoID is 21 characters and a UUID version 4 is 36. NanoID uses a larger 64-symbol alphabet so it packs more entropy into fewer characters (about 126 bits versus 122), and it reads cleanly in a URL. Use a UUID only when a system specifically requires the RFC UUID format.
Is a NanoID guaranteed to be unique?
Nothing random is guaranteed unique, but the odds of a collision are vanishingly small. A 21-character NanoID has about 126 bits of entropy, so you would need to generate billions of IDs per second for centuries before a clash became likely.
What length should I use?
The default of 21 characters is a safe choice for almost everything. You can shorten it for compact links or smaller datasets, but every character you remove cuts the number of possible IDs and raises the collision risk, so do not go too short on high-volume systems.
Are these IDs secure and private?
They are generated with crypto.getRandomValues, your browser cryptographically secure random source, so they are unpredictable. Everything runs locally and no IDs are sent anywhere. They are still identifiers, not passwords, so do not use a NanoID alone to protect sensitive data.
Can I use a NanoID in a URL or filename?
Yes. The default alphabet contains only letters, digits, underscore, and hyphen, all of which are safe in URLs, HTML id attributes, and filenames without any escaping. That URL-safety is the main reason NanoID is popular for links and slugs.