What is NanoID?

NanoID is a tiny, URL-safe unique ID generator for JavaScript. It produces compact random strings that are statistically unique — similar to UUID v4, but shorter by default (21 characters vs 36) and designed to be URL-friendly without any encoding. Each character is chosen from a carefully balanced alphabet so that every possible ID is equally likely, eliminating bias in the distribution.

NanoID uses a cryptographically strong random number generator (crypto.getRandomValues in browsers, crypto.randomFill in Node.js), making the generated IDs suitable for security-sensitive contexts such as session tokens and one-time links. The default 21-character length gives roughly 2.1 × 10³⁰ possible combinations — comparable to UUID v4 — while the compact format saves bandwidth and storage space.

Tool description

This online NanoID generator lets you create one or more NanoIDs instantly in your browser with no installation needed. You can control the ID length, how many IDs to generate, and which alphabet is used — from the secure default to hex, alphanumeric, numbers-only, or a fully custom character set.

Examples

Default alphabet, size 21:

V1StGXR8_Z5jdHi6B-myT
useandom-26T198340PX7
bfghjklqvwyzrictV1StG

Hex alphabet, size 16:

3f9a1c2b4e7d0f85
a0c4e8f23b6d917c

Numbers only, size 8:

04817263
93571048

Custom alphabet (abc123), size 12:

b2ca31b1ca2b
3a1c2b3c1ab2

Features

  • Adjustable length: Set the ID size from 1 to 64 characters (default 21)
  • Bulk generation: Generate up to 1,000 IDs at once
  • Alphabet presets: Choose from Default, Numbers, Lowercase, Uppercase, Alphanumeric, Hex, Uppercase Hex, No-Look-Alikes, or a fully custom character set
  • No-Look-Alikes preset: Removes characters that are visually ambiguous (e.g. 0, O, I, l) for human-readable IDs
  • Download as file: Save all generated IDs to nanoids.txt with one click

Use cases

  • Application development: Use NanoIDs as primary keys in databases or as record identifiers in APIs where a short, URL-safe string is preferred over a full UUID.
  • Token generation: Generate short random tokens for password-reset links, invite codes, or referral slugs where readability and URL safety matter.
  • Testing and mock data: Quickly produce a batch of realistic-looking unique identifiers to populate test fixtures or prototype data.

Options explained

Option Description
Size Number of characters in each generated ID (1–64). The default of 21 gives ~126 bits of entropy, equivalent to UUID v4.
Quantity How many IDs to generate in one batch (1–1,000).
Alphabet The character pool to draw from. Larger, more diverse alphabets increase entropy per character.
Custom alphabet Visible when Custom is selected. Enter any characters; duplicates are removed automatically to prevent a skewed distribution.

How it works

NanoID selects each character by generating a random byte, masking it to fit the alphabet size, and retrying if the result falls outside the valid range — a technique called rejection sampling. This ensures a perfectly flat distribution across all alphabet characters regardless of whether the alphabet size is a power of two. The default alphabet (useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict) is URL-safe (no +, /, or =) and has 64 characters, making each character carry exactly 6 bits of entropy.