Since 2010 · Powering 2M+ tool runs every month
Since 2010
Add to Chrome

My Toolbox

Automatic Mode

No saved tools yet.

Go Premium
Related tools
URL Slug GeneratorWPA Key GeneratorDjango Secret Key GeneratorWordPress Secret Key Generator
Home Page > Randomness

Random NanoID Generator

Generate cryptographically secure NanoIDs, the compact modern alternative to UUIDs. Customise the alphabet (URL-safe, hex, alphanumeric, no-lookalike), set a length from 8 to 64, bulk generate and check collision probability.

Free to useNo sign-up requiredUpdated Feb 2026
Random NanoID GeneratorTry it now — free ▼
ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_-
64 unique characters
Optional prefix added before each ID (e.g. "usr_", "doc_", "tx-")

Embed Random NanoID Generator Widget

About Random NanoID Generator

Welcome to the Random NanoID Generator, a powerful online tool for generating secure, URL-friendly unique string identifiers. NanoID is a modern, lightweight alternative to UUIDs (Universally Unique Identifiers), offering shorter IDs with comparable collision resistance. Whether you are building APIs, databases, URL shorteners, or distributed systems, this generator provides cryptographically secure IDs with customizable alphabets, adjustable lengths, and real-time collision probability analysis.

What is NanoID?

NanoID is a tiny, secure, URL-friendly unique string ID generator originally created for JavaScript by Andrey Sitnik. It has since been ported to every major programming language. The key innovation of NanoID is using a larger alphabet (64 characters by default) instead of UUID's 16 hexadecimal digits, which means more entropy per character and shorter IDs.

A default NanoID looks like: V1StGXR8_Z5jdHi6B-myT

NanoID vs UUID Comparison

Feature NanoID UUID v4
Default Length 21 characters 36 characters (with hyphens)
Alphabet Size 64 characters (A-Za-z0-9_-) 16 characters (0-9a-f)
Entropy ~126 bits (21 chars) ~122 bits (32 hex digits)
URL-Safe ✓ No encoding needed ✗ Hyphens need encoding in some contexts
Customizable ✓ Alphabet and length ✗ Fixed format (8-4-4-4-12)
Size Efficiency ✓ 6 bits per character ✗ 4 bits per character
Format Compact string xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx

How This Tool Generates Secure NanoIDs

Cryptographic Randomness

This generator uses Python's secrets module on the server side, which provides cryptographically secure random number generation backed by the operating system's entropy source (/dev/urandom on Linux/macOS, CryptGenRandom on Windows). Each character in the NanoID is independently and unpredictably selected from the chosen alphabet.

Alphabet Presets

We offer 9 carefully curated alphabet presets to match different use cases:

  • NanoID Default (64 chars): The standard NanoID alphabet A-Za-z0-9_-. URL-safe, compact, and widely compatible. 6 bits of entropy per character.
  • Alphanumeric (62 chars): Letters and digits only, no special characters. Safe for filenames, database fields, and contexts where symbols cause issues.
  • Hexadecimal (16 chars): Traditional hex format. Useful when IDs need to integrate with hex-based systems like CSS colors or hash digests.
  • Numbers Only (10 chars): Numeric IDs only. Good for order numbers, reference codes, or systems that only accept digits.
  • Lowercase / Uppercase (26 chars): Single-case alphabets for case-insensitive systems or visual consistency.
  • No-Lookalike (57 chars): Removes easily confused characters (1/l/I, 0/O/o). Ideal for human-readable codes like invite links, confirmation numbers, and anything users need to type manually.
  • URL-Safe (66 chars): Extended alphabet with -._~ per RFC 3986 unreserved characters.
  • Custom Alphabet: Define your own character set. Characters are automatically deduplicated.

Collision Probability Explained

Collision probability measures how likely two independently generated IDs are to be identical. This is governed by the birthday problem in probability theory:

  • Total possible IDs: alphabet_size ^ id_length. For default NanoID: 64^21 = ~2^126
  • For n generated IDs: collision probability ~ n^2 / (2 * total_possible)
  • With 1,000 IDs: probability is astronomically small (~10^-33)
  • To reach 1% collision chance with default settings: you would need ~10^18 IDs (a quintillion)

The collision probability calculator on this page shows real-time analysis based on your chosen alphabet and ID length, helping you make informed decisions about ID configuration for your specific scale.

How to Use the NanoID Generator

  1. Choose an alphabet preset: Select from 9 presets or define a custom alphabet. The alphabet preview shows the exact characters that will be used.
  2. Set the ID length: Choose from 8 to 64 characters. Default is 21, which gives ~126 bits of entropy with the standard alphabet.
  3. Configure optional settings: Add a prefix for namespaced IDs (e.g., "usr_", "doc_") and select the quantity (1-50).
  4. Generate and copy: Click "Generate NanoID(s)" to create your IDs. Use one-click copy for individual IDs or copy all at once.

Use Cases for NanoID

Database Primary Keys

NanoIDs make excellent primary keys for databases. They are shorter than UUIDs (21 vs 36 characters), saving storage space and reducing index size. Use a prefix like "usr_" or "ord_" to make IDs self-documenting.

API Resource Identifiers

NanoIDs are URL-safe by default, making them ideal for REST API endpoints: /api/users/V1StGXR8_Z5jdHi6B-myT. No URL encoding needed, and they look clean in logs and URLs.

URL Shorteners

A 10-character NanoID with the default alphabet gives 64^10 = ~10^18 possible combinations - enough for any URL shortener. The No-Lookalike alphabet is particularly useful here since users may need to type the short URL manually.

Session Tokens and CSRF Tokens

Since this tool uses cryptographic randomness, the generated IDs are suitable for security tokens. Use longer lengths (32-64 characters) for sensitive security applications.

Distributed Systems

NanoIDs can be generated independently on multiple servers without coordination, unlike auto-incrementing integers. The collision probability is negligible even at massive scale.

File Naming

Use the Alphanumeric preset for safe filenames across all operating systems. No special characters means no escaping issues on Windows, macOS, or Linux.

Choosing the Right Length

Length Entropy (64-char) Best For 1% Collision Threshold
8 48 bits Short URLs, small datasets ~16 million IDs
12 72 bits General purpose, medium datasets ~68 billion IDs
16 96 bits Large systems, high throughput ~280 trillion IDs
21 126 bits Default, most applications ~10^18 IDs
32 192 bits Security tokens, ultra-safe ~10^28 IDs
64 384 bits Maximum security ~10^57 IDs

Code Examples

JavaScript (using nanoid package)

import { nanoid } from 'nanoid';

// Default: 21 chars, URL-safe alphabet
const id = nanoid(); // "V1StGXR8_Z5jdHi6B-myT"

// Custom length
const shortId = nanoid(10); // "IRFa-VaY2b"

// Custom alphabet
import { customAlphabet } from 'nanoid';
const hexId = customAlphabet('0123456789abcdef', 12);

Python (using nanoid package)

from nanoid import generate

# Default NanoID
id = generate() # "V1StGXR8_Z5jdHi6B-myT"

# Custom length and alphabet
id = generate('0123456789abcdef', 12)

Frequently Asked Questions

What is a NanoID and how is it different from a UUID?

NanoID is a tiny, secure, URL-friendly unique string ID generator. It is 21 characters by default (vs UUID's 36 characters), uses a larger alphabet (A-Za-z0-9_-) for more entropy per character, is URL-safe without encoding, and has no fixed format or hyphens. NanoID achieves similar collision resistance to UUID v4 in fewer characters because it uses 64 symbols instead of 16 hex digits.

How secure are NanoIDs generated by this tool?

This tool uses Python's secrets module, which provides cryptographically secure random number generation backed by the operating system's entropy source. Each character is independently and unpredictably selected. A default 21-character NanoID with the standard alphabet has ~126 bits of entropy, comparable to UUID v4's ~122 bits.

What NanoID length should I use for my project?

The default length of 21 characters provides ~126 bits of entropy with the standard alphabet, which is sufficient for most applications. For URL shorteners or user-facing IDs, 8-12 characters may be enough depending on your total ID count. For distributed systems generating millions of IDs, 21+ characters ensures negligible collision probability. Use the collision probability calculator to find the right length for your specific use case.

Can I use NanoIDs as database primary keys?

Yes, NanoIDs work well as database primary keys. They are compact (21 chars vs UUID's 36), URL-safe, and have excellent collision resistance. However, unlike auto-incrementing integers, they are not sequential - so if your database uses B-tree indexes, random IDs may cause more page splits. Consider using a prefix (like "usr_" or "ord_") to make IDs self-documenting.

What is the "No-Lookalike" alphabet preset?

The No-Lookalike preset removes characters that look similar in many fonts: 1/l/I (one, lowercase L, uppercase I) and 0/O/o (zero, uppercase O, lowercase O). This makes IDs much easier to read, transcribe, and communicate verbally. It is ideal for user-facing IDs like invite codes, confirmation numbers, or any ID that humans need to type manually.

Additional Resources

Reference this content, page, or tool as:

"Random NanoID Generator" at https://MiniWebtool.com/random-nanoid-generator/ from MiniWebtool, https://MiniWebtool.com/

by miniwebtool team. Updated: Feb 07, 2026

Randomness:

Top & Updated:

Random PIN GeneratorRandom String GeneratorRandom User-Agent GeneratorView all →
Home Page > Randomness > Random NanoID Generator