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:
- Alphabet size
- ID length
- 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:
| Length | Entropy |
|---|---|
| 8 | 48 bits |
| 10 | 60 bits |
| 12 | 72 bits |
| 16 | 96 bits |
| 21 | 126 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.
| Feature | NanoID | UUID v4 |
|---|---|---|
| Default text length | 21 | 36 |
| Default entropy/randomness | 126 bits | 122 random bits |
| Custom length | Yes | No standard variation |
| Custom alphabet | Yes | No |
| URL-friendly | Yes | Yes |
| Standard UUID format | No | Yes |
| Embedded timestamp | No | No |
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.