Skip to content

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

Enter a value to see results

Visualization

Loading calculator...
📚

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. Software developer Andrey Sitnik created the format in 2017 as a smaller alternative to the UUID (Universally Unique Identifier), a 36-character identifier used widely in computing. A default Nano ID is 21 characters long, compared to a UUID's 36, a reduction of about 42%.

How to generate a Nano ID with this tool

The generator on this page builds a Nano ID from two settings.

  1. Length: a whole number from 1 to 100. The default is 21.
  2. 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 setCharacters usedAlphabet size
Alphanumeric (default)A-Z, a-z, 0-962
URL-safeA-Z, a-z, 0-9, -, _64
Numeric0-910
AlphabeticA-Z, a-z52
Lowercasea-z26
UppercaseA-Z26
SymbolsA-Z, a-z, 0-9, and common punctuation88

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.

1id = random(alphabet, size)
2

With 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
2

Each 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))
2

Here 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
2

Solving the formula for a 1% collision probability gives:

1k ≈ 9.4 × 10^17 IDs
2

That 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

TypeLengthNotes
Nano ID21 characters, adjustableRandom, compact, not sortable by time
UUID36 charactersStandard format, widely supported, contains hyphens
ULID26 charactersSortable by creation time
KSUID27 charactersSortable by creation time, includes a timestamp
Auto-increment integerVariesSimple 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

  1. Sitnik, Andrey. "Nano ID." GitHub, https://github.com/ai/nanoid.
  2. "Universally unique identifier." Wikipedia, Wikimedia Foundation, https://en.wikipedia.org/wiki/Universally_unique_identifier.
  3. "ULID Spec." GitHub, https://github.com/ulid/spec.