Home › Developer Tools › Nano ID Generator

Nano ID Generator

Generate Nano IDs: short, URL-safe, cryptographically random identifiers. Pick an alphabet and length, create up to 10,000 IDs at once, and use the collision calculator to see how long it would take before two IDs clash.

Last updated:

Generate

Collision probability

Based on the alphabet and length chosen in the generator.

Advertisement
Advertisement

How to use the Nano ID Generator

  1. Choose an alphabet: the default URL-safe set (A-Z, a-z, 0-9, _ and -) or a preset, or type your own characters.
  2. Set the length (21 is the nanoid default) and how many IDs you need.
  3. Click Generate. IDs appear instantly and are checked for duplicates within the batch.
  4. Check the collision risk: enter how many IDs you create per hour to see how long until a 1% chance of a collision.
  5. Copy or download the list as plain text, comma-separated or a JSON array.

How Nano IDs are generated

A Nano ID is built one character at a time from cryptographically secure random bytes. To keep every character equally likely, the generator does not use byte % alphabetLength (which favors the first characters whenever 256 is not a multiple of the alphabet size). Instead it:

  1. Computes a bitmask: the smallest value of the form 2k - 1 that covers the alphabet (63 for a 64-character alphabet, 63 for 36 characters, 15 for 16).
  2. Takes a batch of random bytes and ANDs each one with the mask.
  3. Uses the result as an index if it falls inside the alphabet, and throws it away if it does not (rejection sampling).

This is the same approach as the open-source nanoid library's customAlphabet, so IDs made here have identical statistical properties.

Entropy by alphabet and length

Each character adds log2(alphabet size) bits. Aim for at least about 100 bits for IDs that must be globally unique; fewer bits are fine for short-lived or low-volume IDs such as invitation codes.

AlphabetSizeBits per charLength for ~126 bitsBits at length 10
URL-safe (default)646.002160
Alphanumeric625.952259.5
No look-alikes495.612356.1
Lowercase + numbers365.172551.7
Hexadecimal164.003240
Numbers only103.323833.2

The collision formula

The chance that at least two of n random IDs are equal, out of N = alphabet sizelength possible values, is approximately p ≈ 1 - e-n(n-1)/(2N) (the birthday problem). Solving for n gives the number of IDs at which the risk reaches p: n ≈ √(2N · ln(1/(1-p))). For the default 21-character URL-safe ID, N = 6421 = 2126, so a 1% risk takes about 1.3 × 1018 IDs.

Frequently asked questions

What is a Nano ID?

Nano ID is a popular open-source format for random unique identifiers. By default it uses 21 characters from a 64-symbol URL-safe alphabet (A-Z, a-z, 0-9, underscore and hyphen), giving 126 random bits, comparable to the 122 random bits of a UUID v4 in a shorter string.

How likely is a Nano ID collision?

With the default alphabet and length you would need to generate about 1,000 IDs per hour for roughly 149 billion years (on the order of 10^18 IDs) to reach a 1% chance of a single collision. The calculator on this page uses the birthday approximation p = 1 - e^(-n(n-1)/2N), where N is alphabet size raised to the ID length.

Is it safe to use a custom alphabet?

Yes, as long as you keep enough entropy. Each character carries log2(alphabet size) bits, so a smaller alphabet needs a longer ID. The generator uses a bitmask with rejection sampling, so every character is equally likely for any alphabet size, without the modulo bias of naive random % length code.

Nano ID vs UUID: which should I use?

Use UUID when a database column, API or standard requires that format. Use Nano ID when you want shorter, URL-friendly IDs for links, file names or public identifiers. Neither embeds a timestamp, so neither sorts by creation time; use ULID or UUID v7 for that.

Are these IDs generated securely?

Yes. Randomness comes from crypto.getRandomValues, the browser's cryptographically secure generator, the same source the nanoid library uses in browsers. Nothing is sent to a server.

Can Nano IDs start with a hyphen or underscore?

With the default alphabet, yes. If an ID will be used as a command-line argument, CSS selector or HTML id, choose the alphanumeric preset or add a letter prefix.

Are all the tools on FreeToolCabin tested for quality and accuracy?

Yes! Every tool on our site undergoes automated Q/A testing in real browser environments to ensure high precision, correct output, and zero errors. If you happen to spot a bug or have a suggestion, please contact us at [email protected] and our team will review it right away.

Related tools

UUID GeneratorGenerate UUID v4 and v7 / GUIDs in bulk and copy or download them.ULID GeneratorGenerate sortable ULIDs and UUID v7 in bulk, monotonic option, and decode their timestamps.Random String GeneratorGenerate secure random strings and tokens in bulk with any length and character set.UUID Decoder & ValidatorDecode any UUID: version, variant, v1/v6/v7 timestamp and MAC node, plus bulk validation.QR Code GeneratorMake QR codes for links, Wi-Fi, email and more.Barcode GeneratorCreate Code 128, EAN-13, UPC-A, EAN-8, Code 39 and ITF-14 barcodes as PNG or SVG.Schema Markup Generator (JSON-LD)Create JSON-LD structured data for FAQ, Product, Article and more.Htaccess & Nginx Redirect GeneratorBuild 301 redirects for .htaccess, Nginx and Netlify or Cloudflare _redirects.Fake Data GeneratorGenerate mock data as JSON, CSV or SQL.API Key GeneratorCreate secure API keys and secrets with prefixes, checksums and SHA-256 hashes for storage.MIME Type LookupFind the MIME type for any file extension, or the extensions for a MIME type, in 400+ entries.Cron Expression GeneratorBuild crontab schedules visually, read them in plain English and see the next run times.URL Slug GeneratorTurn titles into clean, SEO-friendly URL slugs: accents, stop words, separators and bulk lines.JSON Schema GeneratorTurn sample JSON into a draft 2020-12 JSON Schema with types, required fields and formats.Gitignore GeneratorBuild a .gitignore from 50+ templates for languages, frameworks, IDEs and OS, merged and deduped.License GeneratorCreate a LICENSE file for MIT, Apache, GPL, BSD, ISC, MPL or Unlicense with your name and year.Htpasswd GeneratorCreate .htpasswd entries with bcrypt, APR1-MD5 or SHA-1 for Apache and Nginx basic auth.Placeholder Image GeneratorCreate placeholder images in any size, color and text as PNG, JPG, WebP, SVG or data URI.Ads.txt GeneratorCreate or validate ads.txt and app-ads.txt files: seller lines, cert IDs and variables.Docker Run to Compose ConverterConvert docker run commands to docker-compose.yml, or a compose file back to docker run.Dockerfile GeneratorGenerate a production Dockerfile and .dockerignore for Node, Python, Go or a static nginx site.HTML Boilerplate GeneratorTick the options you need and get a clean HTML5 starter template with meta, OG tags and CSS reset.JSON to Zod SchemaInfer a Zod (or Yup) schema from sample JSON with optional, nullable and z.infer types.Linux Commands Cheat SheetSearchable Linux and bash command reference with flags explained, examples and copy buttons.LLMs.txt GeneratorBuild an llms.txt file for AI crawlers: summary and link sections, import from your sitemap.Nginx Config GeneratorBuild an nginx server block: static site, SPA, reverse proxy or PHP, with SSL, gzip and redirects.OpenAPI / Swagger ViewerView OpenAPI 2/3 JSON or YAML as interactive API docs with validation and an endpoint list.package.json GeneratorFill a form and get a valid, npm-ready package.json with scripts, dependencies and checks.PKCE Code Challenge GeneratorGenerate an OAuth 2.0 PKCE code_verifier and S256 code_challenge, build auth URLs, verify pairs.README GeneratorFill in a form and get a polished README.md with badges, install, usage and license, live preview.Regex GeneratorBuild regular expressions visually from blocks or presets (email, date, phone) and test them live.Commit Message GeneratorBuild Conventional Commit messages with type, scope, body, breaking change and issue refs.Database Schema DesignerDesign tables and relationships visually, then export SQL for MySQL, PostgreSQL or SQLite.Docker Compose GeneratorBuild a docker-compose.yml with a form: services, ports, volumes, env, healthchecks and presets.Dummy File GeneratorCreate test files of an exact size in KB, MB or GB with zeros, random bytes or text.FFmpeg Command GeneratorPick a task and options, get the exact ffmpeg command with every flag explained.Folder Tree GeneratorTurn a local folder or an indented list into an ASCII directory tree for your README.GitHub Actions Workflow GeneratorBuild a GitHub Actions CI workflow: triggers, matrix, caching, tests, Pages or Docker deploy.Jinja2 Template TesterRender Jinja2 templates with YAML or JSON variables using real Jinja2, with clear error lines.JSON Schema Mock Data GeneratorGenerate realistic sample JSON from a JSON Schema: formats, patterns, $ref, seeds and counts.Kubernetes Secret GeneratorCreate Kubernetes Secret YAML from key/value pairs or .env with auto base64, or decode one.Kubernetes YAML ValidatorValidate Kubernetes manifests against the API schema of a chosen version, with error paths.Prettier Config GeneratorToggle Prettier options, preview formatted code live and copy your .prettierrc file.Quartz Cron GeneratorBuild and explain Quartz and Spring cron expressions with seconds, ?, L, W and #, plus next fire times.README Badge GeneratorCreate Shields.io-style README badges for license, version, build and custom labels.Systemd Service File GeneratorCreate a systemd .service unit with ExecStart, user, restart policy, environment and hardening.tsconfig.json GeneratorBuild a tsconfig.json with target, module, strict checks and path aliases, each option explained.Access Log AnalyzerAnalyze Apache and Nginx access logs: top URLs, IPs, status codes, bots and traffic charts.Regex String GeneratorGenerate random test strings that match any regular expression, checked against the real regex.ASCII Table GeneratorTurn CSV or pasted cells into plain-text tables: MySQL, Markdown, Unicode box and reST styles.Kubernetes YAML GeneratorGenerate Deployment, Service, Ingress, ConfigMap, Secret and HPA manifests with safe defaults.Markdown TOC GeneratorGenerate a linked table of contents from Markdown headings with GitHub-style anchors.OpenAPI EditorEdit OpenAPI/Swagger YAML or JSON side by side with live API docs, validation and download.OpenAPI ValidatorValidate OpenAPI 3.0/3.1 and Swagger 2.0 specs: schema errors, broken $refs, line numbers.Pivot Table MakerBuild pivot tables from CSV or Excel by drag and drop: sum, count, average, charts, export.SQL Query BuilderBuild SELECT queries visually: joins, filters, GROUP BY, ORDER BY and LIMIT, as clean SQL.Truth Table GeneratorType a logic expression and get its full truth table, minterms and canonical DNF/CNF.TypeScript PlaygroundWrite TypeScript with live type checking, see the compiled JavaScript and run it in your browser.Article Schema GeneratorCreate Article, BlogPosting or NewsArticle JSON-LD with headline, authors, dates and images.Event Schema GeneratorCreate Event JSON-LD with dates, venue or online location, tickets, organizer and performers.Google Search Query BuilderBuild advanced Google searches with site:, filetype:, intitle:, exact phrases and date operators.HowTo Schema GeneratorCreate HowTo JSON-LD with steps, tools, supplies, total time and cost, then copy it.Htaccess GeneratorBuild an Apache .htaccess file: HTTPS, www, gzip, caching, error pages, IP blocks, hotlinks.HTML Email Template BuilderDrag and drop blocks to build a responsive, table-based HTML email with inline styles.Organization Schema GeneratorCreate Organization JSON-LD with logo, URL, contact points, address and social profiles.PIN GeneratorGenerate random 4, 6 or 8-digit PINs that avoid sequences, repeats, dates and common PINs.Product Schema GeneratorBuild Product JSON-LD with price, availability, brand, GTIN, ratings and reviews.Question Keyword GeneratorFind the questions people ask about a topic, grouped by who, what, why, how, can and more.
See all 85 Code Generators & Builders →