Skip to main content

NanoID Generator

Short random IDs from an alphabet you control. Default is 21 URL-friendly characters. This is not a UUID and not a sort-by-time ULID.

Rated 4.7 out of 5 based on 481 reviews

How to generate a NanoID

  1. Leave Length at 21 unless your system documents another size. Minimum is 2, maximum is 64.
  2. Leave the alphabet on the URL-friendly default, or edit it. It must contain at least two characters.
  3. Set Count if you need a list, then generate.
  4. Paste the ID where a public key belongs. Use a UUID when the receiver expects 8-4-4-4-12 hex.

NanoID

Compact random identifier from a custom alphabet

Default length21 characters
Default alphabetA-Z, a-z, 0-9, underscore, hyphen (URL-friendly)
SamplingUnbiased Web Crypto index into the alphabet
Not a UUIDNo version nibble, no 128-bit canonical layout
Collision riskFalls as length and alphabet size grow. Short IDs collide sooner
Sort orderNot time-sortable. Use ULID when you need time order

URL-friendly by default

The default alphabet is A-Z, a-z, 0-9, underscore, and hyphen. Those characters survive in paths and query strings without percent-encoding. You can shrink the alphabet, but a tiny alphabet raises collision risk at the same length. The alphabet must have at least two symbols. This page does not add a checksum.

NanoID is not a UUID

A UUID is 128 bits with a fixed hex layout and a version. NanoID is a string from your alphabet. Do not send a NanoID to an API that validates UUID syntax. Do not send a UUID when a system wants a 21-character NanoID. For a 26-character Crockford ID that sorts by time, use ULID.

Unbiased sampling

Each character is drawn with an unbiased integer in 0 .. alphabet.length - 1. That avoids the modulo bias you get from a naive random % n. Web Crypto supplies the bits. Math.random is not used. Changing the alphabet changes both appearance and entropy per character.

Collision risk depends on length

A 21-character ID from a 64-symbol alphabet is the usual NanoID default and is ample for many apps. A 2-character ID is a toy and will collide quickly. This generator does not talk to your database, so it cannot promise global uniqueness. Enforce a unique index where the ID is stored. For opaque tokens that are not IDs, see the random string page.

Bulk IDs stay in this tab

Count goes to 1000 lines. Nothing is uploaded. Treat IDs as public labels unless you also hide the records they point to. NanoID is not a password.

NanoID questions

Is a NanoID a UUID?
No. It has no UUID version field and no 8-4-4-4-12 hex form unless you force a hex alphabet and ignore layout.
Why is the default length 21?
That is the usual NanoID default for a URL-friendly 64-symbol alphabet. You can shorten or lengthen it for your system.
Can two IDs collide?
Yes, in theory. Risk drops as length and alphabet grow. Short IDs collide much sooner. Uniqueness belongs in your store.
Is sampling biased?
No. Each index into the alphabet is an unbiased Web Crypto integer.
Will this sort by creation time?
No. Use ULID when you need time-sortable IDs. Use UUID version 7 when you need a UUID that sorts by Unix time.
Can I put symbols other than _ and - in the alphabet?
Yes, if you accept the encoding cost in URLs. Keep at least two characters. Avoid alphabets that confuse operators, such as look-alike letters, unless you mean to.