Home/IDs & Random/NanoID Generator

NanoID Generator

Generate URL-safe NanoIDs at any length or alphabet — with a collision calculator that tells you how long your configuration will actually last.

Free Browser-based No signup Copy-ready
Generator Settings
21 is the library default and is roughly as collision-resistant as a UUID v4.
Prefixes such as user_ or inv_ make IDs self-describing in logs — the Stripe convention.
Collision calculator
Generated IDs
nanoids.txt

      

How it works

1

Set length and alphabet

Shorter for share links, longer for anything unguessable. Pick a no-look-alike alphabet if humans will type it.

2

Check the collision maths

Enter your real ID creation rate and see when the first collision becomes likely.

3

Export

Copy as a list, JSON, CSV or SQL — or grab the matching library code.

Choosing a length that will not embarrass you later

NanoID is popular because it is small, fast and URL-safe. The one decision that matters is length, and it is worth doing the arithmetic once rather than discovering the answer in production.

Reasonable defaults

  • 21 chars (default): 126 bits. Safe for essentially any volume — this is the right answer unless you have a specific reason.
  • 16 chars: 96 bits. Comfortable for user-facing IDs at high volume.
  • 10–12 chars: 60–72 bits. Fine for short links and public slugs.
  • 6–8 chars: Display codes only, and only with a uniqueness check on insert.

Where teams get it wrong

  • Using a short ID as a security token. Length is not the same as secrecy — an 8-character ID is brute-forceable.
  • Assuming a database unique constraint makes collisions free. It makes them visible, as failed inserts under load.
  • Custom alphabets containing characters that need percent-encoding in URLs.
  • Reimplementing NanoID with a naive modulo, which biases the first characters of the alphabet.
NanoID has no timestamp. That is the trade-off against ULID and UUID v7: nothing leaks about when a record was created, but the IDs do not sort chronologically and give your database index no locality. Use NanoID for public-facing identifiers, and a time-ordered ID for the primary key.

Frequently Asked Questions

View all FAQs
What is the default NanoID length?
The standard Nano ID library uses 21 characters by default.
How much entropy does a 21-character NanoID have?
With the 64-character default alphabet, 21 characters provide 126 bits of entropy.
Is NanoID better than UUID?
It depends on the application. NanoID is shorter and customizable. UUID is standardized and widely supported by databases and APIs.
Can NanoID contain only numbers?
Yes. Use a numeric custom alphabet. Because ten symbols provide less entropy per character than 64 symbols, you will generally need a longer ID.
Does NanoID contain a timestamp?
No, not by default. If you need sortable timestamp-based identifiers, compare UUID v7 or ULID.
Can I use NanoID as a database primary key?
Yes, provided your schema and indexing strategy fit random text IDs. Enforce uniqueness at the database level.
Are NanoIDs safe in URLs?
The default alphabet is URL-friendly. Remember that a URL-safe identifier is not automatically a secret or authorization token.
Is this NanoID generator free?
Yes. Generate IDs, customize the format and calculate collision risk above without creating an account.

NanoID Generator – Create Secure, URL-Safe IDs Online

Need a compact unique ID without the long UUID format? Use the NanoID Generator above to create secure, URL-safe NanoIDs instantly. Choose the ID length, generate one or thousands at once, use the standard alphabet or enter your own, add a prefix or suffix and check the estimated collision risk before choosing a shorter format.

The default Nano ID format uses 21 characters from a 64-character URL-safe alphabet: uppercase letters, lowercase letters, numbers, underscore and hyphen.

That gives 126 bits of entropy and collision resistance in the same general range as UUID v4 while producing a shorter text identifier.

Generation happens locally in your browser using secure random values.

What Is NanoID?

NanoID is a compact random identifier format popular in web applications, APIs and databases.

A default ID looks like:

V1StGXR8_Z5jdHi6B-myT

Unlike UUID, NanoID has no fixed 36-character hexadecimal representation; you can control the length and alphabet.

That flexibility is useful when you need IDs that are:

  • Shorter in URLs
  • Easy to embed in JSON
  • Compatible with a restricted character set
  • Self-describing with prefixes
  • Suitable for test data
  • Generated independently across distributed systems

The official Nano ID library uses cryptographically secure random values and a URL-friendly default alphabet.

How to Use This NanoID Generator

Start with the number of IDs you need.

For normal use, leave the length at 21 characters unless you have a specific reason to change it.

Next, choose the alphabet.

Use the standard URL-safe alphabet unless your system requires a restricted character set.

Add a prefix such as:

user_
order_
inv_

or a suffix if your naming scheme requires one.

Then enter your expected generation volume in the collision calculator.

Generate the IDs only after checking whether the chosen length and alphabet provide enough identifier space for your application.

Why Is the Default NanoID 21 Characters?

Nano ID’s default alphabet contains 64 symbols.

Each character therefore carries 6 bits of entropy because:

2^6 = 64

At 21 characters:

21 × 6 = 126 bits

That gives a huge number of possible IDs.

The default was designed to provide collision probability in a similar range to UUID v4 while using fewer text characters.

Shortening the ID reduces the identifier space quickly.

That may still be perfectly reasonable for a small application, but the decision should be based on expected generation volume rather than appearance alone.

NanoID Collision Probability Explained

A collision happens when two independently generated identifiers are identical.

Collision risk depends mainly on three things:

  1. Alphabet size
  2. ID length
  3. Number of IDs generated

A longer ID creates more combinations.

A larger alphabet also creates more combinations per character.

For example, an 8-character numeric ID has far fewer possibilities than an 8-character NanoID using 64 symbols.

That is why “8 characters” by itself tells you very little about safety.

Use the collision calculator in this tool whenever you shorten the default length or reduce the alphabet.

How Long Should a NanoID Be?

For most applications, 21 characters is the default. Shorten it only when you understand the tradeoff.

With a 64-character alphabet, approximate entropy is:

LengthEntropy
848 bits
1060 bits
1272 bits
1696 bits
21126 bits

Estimate lifetime ID volume and choose a collision risk you can accept rather than selecting a length only because it looks tidy.

If duplicate IDs would cause serious damage, also enforce uniqueness in the database.

Custom NanoID Alphabets

A custom alphabet controls which characters can appear.

Numeric only:

0123456789

Uppercase letters and digits:

ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789

Human-friendly systems may remove characters that look alike, such as:

  • 0 and O
  • 1 and I
  • lowercase l

Custom alphabets are useful for:

  • Human-entered references
  • Printed labels
  • Case-insensitive systems
  • Coupon-like codes
  • Legacy databases
  • Restricted file names

The tradeoff is entropy.

A smaller alphabet needs a longer ID to provide the same identifier space.

Always recalculate collision risk after changing the alphabet.

NanoID vs UUID v4

NanoID and UUID v4 are both commonly used for random unique identifiers.

The difference is flexibility.

FeatureNanoIDUUID v4
Default text length2136
Default entropy/randomness126 bits122 random bits
Custom lengthYesNo standard variation
Custom alphabetYesNo
URL-friendlyYesYes
Standard UUID formatNoYes
Embedded timestampNoNo

Choose NanoID when short text and custom formatting matter.

Choose UUID when external systems specifically expect a UUID type or standardized UUID representation.

NanoID vs UUID v7

UUID v7 is time ordered.

NanoID is random by default.

That means they solve different application needs.

Choose UUID v7 if:

  • IDs should roughly sort by creation time
  • Native database UUID types matter
  • You want an RFC-standardized format

Choose NanoID if:

  • You want a short public ID
  • You need a custom alphabet
  • You do not want creation time embedded
  • You want flexible prefixes or suffixes

Use the UUID v7 Generator to compare both outputs.

NanoID vs ULID

ULID is always a 128-bit, 26-character Crockford Base32 identifier with a millisecond timestamp.

NanoID has configurable length and alphabet and does not contain time by default.

ULID is useful for sortable records.

NanoID is useful for compact random references.

If your database frequently sorts records by ID and you want creation order reflected in the identifier, ULID may be more suitable.

If you want usr_xxx, post_xxx or short public resource IDs, NanoID is often simpler. See the ULID Generator.

Are NanoIDs Secure?

The official Nano ID implementation uses cryptographically secure randomness.

This tool also generates values using the browser’s secure random-number capabilities rather than Math.random().

That makes the IDs difficult to predict, but an identifier is not automatically an authentication credential.

A NanoID may appear in:

  • URLs
  • Browser history
  • Logs
  • Analytics
  • Support tickets
  • Screenshots
  • API responses

Do not treat an ordinary record ID as authorization.

Protect resources with separate authentication and authorization.

Prefixes and Suffixes

Prefixes such as usr_, ord_ and post_ make IDs easier to recognize in logs and support workflows.

They do not increase randomness. If every user ID begins with usr_, those characters are predictable. Calculate collision risk from the random portion, not the prefix or suffix.

Bulk NanoID Generation

Bulk output is useful for database seeds, test fixtures, mock API data, CSV imports and migration dry runs.

For production records, generate the ID inside the application at creation time. The online tool is best used for testing formats, calculating risk and creating controlled batches.

NanoID in Database Primary Keys

NanoIDs can work well as database identifiers.

They can be generated outside the database, which is convenient in distributed applications.

If you store NanoIDs as text, consider:

  • Column length
  • Case sensitivity
  • Index size
  • Collation
  • Uniqueness constraints

A database UNIQUE constraint is still important.

Random generation makes collisions highly unlikely; the constraint ensures the database never silently accepts a duplicate key.

For very write-heavy indexed tables, also compare random NanoIDs with time-ordered UUID v7 or ULID keys.

Random insertion order can behave differently from sequential or time-ordered keys.

URL-Safe Does Not Mean Human-Friendly

The default alphabet works well in URLs, but mixed-case IDs are not always easy to read from paper or dictate aloud.

For human-entered codes, use an alphabet that removes confusing characters and increase the length as needed to compensate for the smaller character set.

Do NanoIDs Reveal Creation Time?

Not by default. A standard NanoID is random and does not encode a timestamp, unlike ULID, UUID v7 and MongoDB ObjectId.

Store a separate creation timestamp whenever your application needs one.

Common NanoID Mistakes

Avoid these errors:

  • Shortening the ID without checking collision risk
  • Reducing the alphabet without increasing length
  • Counting a predictable prefix as entropy
  • Using Math.random() for security-sensitive identifiers
  • Treating an ID as a password or access-control mechanism
  • Assuming uniqueness means a database constraint is unnecessary
  • Using a case-sensitive alphabet in a case-insensitive storage system
  • Choosing numeric-only IDs that are far too short for the expected volume

The generator’s collision calculator exists for a reason. Use it before changing the default parameters.

Related searches

nanoid generatornanoid collision probabilitynanoid custom alphabetnanoid vs uuidnanoid entropynanoid prefixnanoid vs ulidnanoid vs uuid v7url safe id generatornanoid database primary keysecure random id generatornanoid length calculator