NathanTools
NathanTools
Text Tools 13
SEO Tools 7
Image Tools 19
YouTube Tools 38
Device Tests 4
PDF Tools 10
Calculators 52
Electrical Calculators 10
Time Tools 7
Random Tools 9
Converters 14
Developer Tools 11
Hash Generators 5
Password & Security 2
Network & DNS 3
Website Tools 9

NanoID Generator

Generate short, random, URL-safe IDs. Pick the length and alphabet and see how many IDs you can make before a duplicate becomes likely.

100% free No sign-up Works on any device
Format
0Random bits
0IDs for a 1% chance of a duplicate
0At 1,000 IDs an hour

NanoIDs

Updated November 2026 · Same algorithm as the nanoid library · Generated in your browser

How to generate a NanoID

  1. A new 21-character ID appears at the top when the page loads. Press Copy, or the arrow for another.
  2. Set the Length and watch the collision figures: they show how many IDs you can safely create.
  3. Choose an Alphabet. No look-alikes drops characters people confuse, such as 0, O, 1, l and I, which helps for codes people type.
  4. Add a Prefix such as usr_ or ord_ to show what each ID is for, then copy or download up to 1,000.

How long should a NanoID be?

Each character adds log2(alphabet size) random bits: 6 bits for the default 64-character alphabet. The chance of a duplicate depends on how many IDs you make, not how fast. A rough guide for the default alphabet:

LengthRandom bitsIDs before a 1% chance of a duplicateGood for
848about 2.4 millionShort links, invite codes for a small app
1272about 9.7 billionPublic IDs in URLs for most apps
1696about 40 trillionLarge multi-tenant systems
21126about 1.3 × 1018Database keys and tokens, the library default

Keep a unique index on the column anyway. It costs little and turns a once-in-a-lifetime collision into a clean error you can retry.

Why random IDs need rejection sampling

A random byte has 256 values. Taking it modulo an alphabet of, say, 62 characters makes the first 8 characters slightly more likely than the rest, which weakens the ID. This tool masks each byte to the next power of two (63 for a 62-character alphabet) and throws away values that don't map to a character, so every character has exactly the same chance.

Generate a NanoID in code

LanguagePackageCall
JavaScript / Node.jsnanoidnanoid(), or customAlphabet("0123456789", 12)()
Pythonnanoidgenerate(size=21)
C# / .NETNanoidNanoid.Generate()
Gogithub.com/matoous/go-nanoid/v2gonanoid.New()
JavajnanoidNanoIdUtils.randomNanoId()
Rustnanoidnanoid!()

Frequently asked questions

A NanoID is a short random string ID, 21 characters by default, drawn from the 64 URL-safe characters A–Z, a–z, 0–9, _ and -. It's named after the popular nanoid JavaScript library. 21 characters give 126 random bits, about the same as a v4 UUID's 122.

As short as your volume allows. Check the collision figure under the tool: it shows how many IDs you can create before there's a 1% chance two are the same. For a few thousand short links, 8–10 characters are plenty; for database keys keep 21.

Yes. Pick Custom and type the characters to use. Duplicates are removed, and you need at least 2. A smaller alphabet means less randomness per character, so the tool tells you how much longer the ID should be to stay as safe.

Yes. Random bytes are masked to the next power of two and values outside the alphabet are thrown away, the same rejection method the nanoid library uses. Simply taking a byte modulo the alphabet size would make some characters more common.

Use a UUID when a database column, API or standard expects one. Use NanoID when the ID appears in URLs or to people and you want it short, or when you need a custom alphabet, such as digits only or no look-alike characters.

They come from crypto.getRandomValues, so they are unpredictable. For tokens such as password-reset links keep at least 21 characters (126 bits). Nothing generated here is sent to our server.
Esc
↑ ↓ to moveEnter to open