Nano ID Generator: Create Random Unique IDs Online
Generate random Nano IDs online for free. Set the length and character set, then create a compact, unique identifier for URLs, database keys, or tokens.
The length of the generated Nano ID (1-100 characters)
Select the character set for your Nano ID
Generated Nano ID
Visualization
Documentation
A Nano ID generator creates a short, random string of characters called a Nano ID. Nano IDs work as unique identifiers for things like database records, URLs, and API tokens, and two generated IDs are extremely unlikely to ever match.
What is a Nano ID?
A Nano ID is a randomly generated string used to label something so it can be told apart from every other thing. Developer Andrey Sitnik wrote the open-source Nano ID library, copyright 2017, as a shorter alternative to the UUID (Universally Unique Identifier), a 36-character identifier used widely in computing. The library uses a larger alphabet than a UUID, so its default ID is 21 characters long instead of 36, about 42% shorter. The library's own default alphabet is the URL-safe set (A-Za-z0-9_-); this tool defaults to the alphanumeric set instead.
How to generate a Nano ID with this tool
The generator on this page builds a Nano ID from two settings.
- Length: a whole number from 1 to 100. The default is 21.
- Character set: the group of characters the ID is built from. The default is alphanumeric.
Enter a length, pick a character set, then press "Generate" to create an ID. Press "Copy" to copy it. A new ID also appears automatically whenever the length or character set changes.
Character sets available
The tool offers seven fixed character sets. It does not accept a custom, user-typed alphabet.
| Character set | Characters used | Alphabet size |
|---|---|---|
| Alphanumeric (default) | A-Z, a-z, 0-9 | 62 |
| URL-safe | A-Z, a-z, 0-9, -, _ | 64 |
| Numeric | 0-9 | 10 |
| Alphabetic | A-Z, a-z | 52 |
| Lowercase | a-z | 26 |
| Uppercase | A-Z | 26 |
| Symbols | A-Z, a-z, 0-9, and common punctuation | 88 |
The alphanumeric set is selected by default. It leaves out the hyphen and underscore used in the URL-safe set, though letters and digits alone are already safe to place directly in a URL.
Nano ID formula
A Nano ID is built by picking a fixed number of characters at random from an alphabet, one at a time, using a cryptographically secure random number generator. That is a generator designed so its output cannot be predicted in advance. In the browser, the library this tool uses draws its random bytes from the Web Crypto method crypto.getRandomValues(), which returns cryptographically strong random values.
1id = random(alphabet, size)
2With the default settings, alphabet has 62 characters and size is 21.
Example
Using the default alphanumeric alphabet and a length of 21, one possible generated ID is:
1K7pQ2mZxT9vY4nR8jH3wL
2Each character is drawn independently from the 62 letters and digits, so running the generator twice will almost never produce the same string.
How to calculate collision probability
Because a Nano ID is chosen at random, it is possible, though very unlikely, for two generated IDs to match. This is called a collision. The chance of at least one collision after generating k IDs follows the same math as the "birthday problem":
1P(collision) ≈ 1 - e^(-k² / (2n))
2Here n is the number of possible IDs: the alphabet size raised to the power of the ID length, or n = alphabet_size^length.
Worked example
For the default setting, a 62-character alphabet and a 21-character length:
1n = 62^21 ≈ 4.4 × 10^37 possible IDs
2Solving the formula for a 1% collision probability gives:
1k ≈ 9.4 × 10^17 IDs
2That means roughly 940 quadrillion IDs must be generated before there is even a 1% chance that two of them match. At one million IDs generated every second, reaching that count would take about 29,700 years.
Switching to the 64-character URL-safe alphabet raises the count slightly, to about 1.3 × 10^18 IDs for the same 1% risk, because the larger alphabet leaves more possible IDs to choose from.
Nano ID compared with other identifiers
A ULID is written as a 26-character string that sorts by creation time, and a KSUID's text form is always 27 characters and sorts by its timestamp.
| Type | Length | Notes |
|---|---|---|
| Nano ID | 21 characters, adjustable | Random, compact, not sortable by time |
| UUID | 36 characters | Standard format, widely supported, contains hyphens |
| ULID | 26 characters | Sortable by creation time |
| KSUID | 27 characters | Sortable by creation time, includes a timestamp |
| Auto-increment integer | Varies | Simple and sequential, but predictable and hard to coordinate across separate databases |
Frequently asked questions
What is the default Nano ID length and character set?
The default is 21 characters from the alphanumeric character set: A-Z, a-z, 0-9, which is 62 characters in total.
Does this tool support a custom alphabet?
No. It offers seven fixed character sets: alphanumeric, URL-safe, numeric, alphabetic, lowercase, uppercase, and symbols.
How is a Nano ID different from a UUID?
A Nano ID is shorter. The default is 21 characters against a UUID's 36 characters, about 42% shorter. Both are generated randomly and are not sequential.
Can a Nano ID be sorted by the time it was created?
No. Nano IDs are fully random, so they carry no information about when they were generated. Formats such as ULID or KSUID are built to be sortable by time instead.
Is a Nano ID safe to use as a database primary key?
Yes. It should be stored as a text or string column rather than a number, with a unique index for fast lookups.
How many possible Nano IDs are there?
It depends on the length and character set chosen. With the default 62-character alphabet and 21-character length, there are 62^21, about 4.4 × 10^37, possible IDs.
References
- Andrey Sitnik. Nano ID license file. ai/nanoid LICENSE on GitHub — MIT license, "Copyright 2017 Andrey Sitnik".
- Andrey Sitnik. Nano ID README. ai/nanoid on GitHub — larger alphabet than UUID (
A-Za-z0-9_-), "ID size was reduced from 36 to 21 symbols"; uses the Web Crypto API in browsers. - MDN Web Docs. Crypto: getRandomValues() method. MDN, Crypto.getRandomValues() — the method returns cryptographically strong random values.
- ULID project. Universally Unique Lexicographically Sortable Identifier. ulid/spec on GitHub — canonically a 26-character string, as opposed to the 36-character UUID; lexicographically sortable.
- Segment. KSUID. segmentio/ksuid on GitHub — the text representation is always 27 characters and sorts by timestamp.