Numbers

NanoID-Style Short ID Generator

NanoID-style short ID generation gives you compact, URL-safe unique identifiers that fit neatly into modern application architecture without the bulk of full UUIDs. A standard 21-character NanoID draws from a 64-character alphabet, delivering collision resistance equivalent to UUID v4 while being 36% shorter — a meaningful difference when IDs appear in URLs, API responses, or log files. This generator lets you control length, quantity, and character style so you can match the ID format exactly to your project's requirements. The character set you choose matters more than most developers expect. URL-safe mode uses alphanumerics plus hyphens and underscores, producing IDs that pass through browsers, databases, and HTTP headers without escaping. Numeric-only or hex modes suit systems where downstream parsers expect a restricted alphabet, such as legacy databases or barcode scanners. Switching between styles here takes one click, so you can compare outputs before committing to a format in code. Length is the core trade-off in short unique ID design. Twelve characters gives you roughly 68 billion possible values — more than adequate for a small SaaS with thousands of records. Push to 21 characters and the collision probability across a billion generated IDs drops to near zero. The generator defaults to 21 for safety, but you can dial length down when IDs will be typed manually or displayed in tight UI space, and dial it up when uniqueness is genuinely mission-critical. Generate IDs in batches of up to hundreds at a time, copy the list directly into seed files, environment configs, or test fixtures, and iterate on the settings until the output looks exactly right for your stack.

How to Use

  1. Set the ID Length field to match your use case — 21 for production systems, 10-14 for human-readable codes.
  2. Enter the number of IDs you need in the How Many field, up to hundreds for batch seeding or fixture files.
  3. Choose an ID Style: URL-safe for links and APIs, hex for systems expecting hexadecimal, numeric for digit-only pipelines.
  4. Click Generate to produce the batch, then review the list to confirm the format looks correct for your target system.
  5. Copy the output list directly into your seed file, config, or code, or download it as a text file for bulk use.

Use Cases

  • Generating short public share links for uploaded files or documents
  • Creating URL slugs for blog posts that avoid exposing sequential IDs
  • Assigning API keys or session tokens in lightweight authentication flows
  • Seeding test databases with realistic-looking non-sequential record IDs
  • Building invite codes or referral tokens for user onboarding flows
  • Producing unique filenames for user-uploaded assets stored in object storage
  • Creating idempotency keys for payment API requests to prevent duplicate charges
  • Generating short correlation IDs for distributed service request tracing

Tips

  • Generate a batch of 50-100 at once and store them in a seed file — far faster than calling an ID library ad hoc during development.
  • For invite or referral codes users will type, use alphanumeric style at length 10 and avoid ambiguous characters like O and 0 by choosing a restricted alphabet if available.
  • Hex-style IDs pair naturally with systems that already use SHA hashes or Git commit SHAs, keeping your ID format visually consistent across the stack.
  • When IDs appear in QR codes, shorter IDs reduce QR density and improve scan reliability — 12-14 characters is the sweet spot for printed media.
  • Test your chosen ID in the target URL or database column before committing: paste a sample into your browser bar and your DB insert to catch encoding or length issues early.
  • For distributed systems, combine a short location prefix (e.g., 'eu-' or 'us-') with a 16-character NanoID instead of using a longer single ID — aids debugging without sacrificing much brevity.

FAQ

What is a NanoID and how does it work?

NanoID is a compact unique ID format that selects characters randomly from a defined alphabet using a cryptographically secure random number generator. At 21 characters with a 64-symbol alphabet, it produces roughly 1.9 × 10^37 possible values — comparable to UUID v4 — while being shorter and free of hyphens by default. The original is an open-source JavaScript library, but the format is language-agnostic.

How is a NanoID different from a UUID?

UUIDs follow a fixed 8-4-4-4-12 hyphenated format totalling 36 characters, with 4 bits reserved for version info. NanoIDs are plain strings with no fixed structure, no hyphens baked in, and a configurable length and alphabet. This makes NanoIDs shorter, more flexible, and safer to embed in URLs without percent-encoding. The collision resistance of both formats is roughly equivalent at default settings.

What ID length should I use for my project?

For high-volume systems generating millions of IDs, stay at 21 characters. For internal tools or apps with tens of thousands of records, 14-16 characters is typically safe. If IDs will be manually typed by users — such as invite codes — 10-12 characters in alphanumeric style keeps them manageable while remaining unique enough for the volume. Use the birthday problem calculator to verify collision probability for your exact volume.

Are these IDs safe to use in database primary keys?

Yes, but with a caveat for relational databases. Random string IDs disrupt B-tree index ordering, causing page fragmentation and slower inserts at scale compared to sequential IDs. For read-heavy tables or document stores like MongoDB or DynamoDB, short random IDs work well. For write-heavy relational tables, consider using them as a public-facing slug column while keeping an internal auto-increment primary key.

What does URL-safe mean for ID characters?

URL-safe IDs contain only characters from the RFC 3986 unreserved set: letters A-Z, a-z, digits 0-9, hyphens, and underscores. These characters pass through URLs, HTTP headers, JSON, and HTML attributes without percent-encoding or escaping. Avoid alphabets that include plus signs, slashes, or equals signs if the ID will appear in query strings or path segments.

Can I generate NanoIDs in my own code instead of using a generator?

Yes. The official nanoid npm package covers JavaScript and Node.js. Community ports exist for Python (nanoid), Go (gonanoid), Rust, PHP, and most major languages. For quick prototyping, ad-hoc testing, or generating seed data without adding a dependency, using this web generator is faster than writing or installing code.

What is the collision risk of short IDs at 12 vs 21 characters?

At 12 characters with a 64-symbol alphabet there are ~68 billion possible IDs. The probability of a collision appears only after generating roughly 100,000 IDs — low enough for most apps. At 21 characters the space is 3.7 × 10^37, making collisions effectively impossible at any realistic scale. If you generate more than a million IDs, use at least 16 characters to keep collision probability negligible.

Is the numeric-only ID style suitable for all use cases?

Numeric-only IDs are useful when downstream systems restrict input to digits — older SMS platforms, USSD codes, or legacy ERP systems. However, a 21-digit numeric ID has only 10^21 possible values versus 64^21 for URL-safe, so collision resistance drops significantly. Compensate by increasing the length to 24-30 characters when using numeric mode for any meaningful volume.