User Rating 0.0 โ˜…โ˜…โ˜…โ˜…โ˜…
Total Usage 0 times
Unique characters used in ID generation
Presets:
Is this tool helpful?

Your feedback helps us improve.

โ˜… โ˜… โ˜… โ˜… โ˜…

About

NanoID is a compact, URL-safe, cryptographically strong identifier format. A standard UUID v4 occupies 36 characters to encode 122 bits of entropy. A default NanoID packs comparable collision resistance into 21 characters by using a 64-symbol alphabet (A - Z, a - z, 0 - 9, _, -), yielding 126 bits of entropy. Misconfiguring the alphabet size or ID length is the primary source of collision risk in distributed systems. Dropping to a 10-character hex ID, for example, reduces entropy to roughly 40 bits - a collision becomes probable after only ~1.05 million records. This generator uses the browser crypto.getRandomValues() CSPRNG and applies mask-based rejection sampling to eliminate modulo bias across arbitrary alphabet sizes.

The collision probability panel below computes the exact Birthday Paradox estimate for your configuration. Note: the tool assumes uniform random distribution. If you supply an alphabet with duplicate characters, effective entropy decreases and the estimate becomes optimistic. For database primary keys, maintain at least 100 bits of entropy. For short-lived session tokens, 64 bits may suffice.

nanoid random id generator unique id uuid alternative crypto random nanoid generator short id

Formulas

The core entropy per character is derived from the alphabet size A:

Hchar = log2(A)

Total entropy for an ID of length L:

Htotal = L ร— log2(A)

Collision probability after generating n IDs is approximated by the Birthday Paradox:

p 1 โˆ’ eโˆ’n22 โ‹… AL

The mask for rejection sampling is the smallest bitmask m satisfying:

m = (2โŒˆlog2(A)โŒ‰) โˆ’ 1

A random byte is bitwise ANDed with m. If the result โ‰ฅ A, the byte is discarded and a new one is drawn. This eliminates modulo bias entirely.

Where: A = alphabet size (number of unique characters), L = ID length, n = number of IDs generated, H = entropy in bits, p = collision probability, m = bitmask for rejection sampling.

Reference Data

Alphabet NameCharactersSizeBits per CharDefault LengthTotal Entropy (bits)Use Case
Default NanoIDA-Za-z0-9_-646.0021126General purpose, URL-safe
Hexadecimal0-9a-f164.0032128Hash-like tokens
Decimal0-9103.322169.7Numeric codes, PINs
Lowercase Alphaa-z264.702198.7Human-readable slugs
Uppercase AlphaA-Z264.702198.7License keys, serial numbers
AlphanumericA-Za-z0-9625.9522131Database keys
Base32 (Crockford)0-9A-HJKMNP-TV-Z325.0026130Unambiguous human input
No Look-Alike2-9A-HJ-NP-Za-km-z575.8322128Printed codes (no 0/O/l/1)
URL-Safe Base64A-Za-z0-9-_646.0021126JWT-compatible tokens
Binary0121.00128128Bit strings, testing
Octal0-783.0043129File permissions, legacy
UUID-Compatible0-9a-f + hyphens164.0032128Drop-in UUID replacement
Emoji SetSelected emoji2568.0016128Fun identifiers, demos

Frequently Asked Questions

NanoID uses mask-based rejection sampling. It computes a bitmask equal to (2^โŒˆlogโ‚‚(A)โŒ‰ - 1), where A is the alphabet size. Each random byte is ANDed with this mask. If the resulting value is โ‰ฅ A, the byte is discarded and another is drawn. This guarantees every character in the alphabet has an exactly equal probability of selection, unlike a simple modulo operation which would skew distribution toward lower-indexed characters.
For database primary keys in systems generating fewer than 1 billion records, 100 bits of entropy is generally safe. The default NanoID configuration (21 characters, 64-symbol alphabet) provides 126 bits, which means you would need to generate roughly 2.2 ร— 10ยนโธ IDs before reaching a 1% collision probability at 1,000 IDs/second. If your alphabet or length is smaller, use the collision probability panel in this tool to verify your configuration meets your throughput requirements.
UUID v4 provides 122 bits of entropy in 36 characters (including 4 hyphens). NanoID default provides 126 bits in 21 characters - 42% shorter with slightly more entropy. NanoID is URL-safe by default with no special characters beyond hyphen and underscore. It also allows custom alphabets, so you can tailor IDs to your system constraints (e.g., case-insensitive databases, numeric-only systems).
Yes. Duplicate characters reduce the effective alphabet size. If you specify "aabcdef" (7 characters but only 6 unique), the effective A = 6, not 7. The entropy calculation and collision probability become optimistic because the tool counts unique characters. Additionally, the character "a" will appear roughly twice as often as others, creating a non-uniform distribution detectable by statistical analysis. Always use unique characters in your alphabet.
crypto.getRandomValues() is a cryptographically secure pseudorandom number generator (CSPRNG) specified in the W3C Web Cryptography API. It draws from the operating system's entropy pool (e.g., /dev/urandom on Linux, BCryptGenRandom on Windows). It is suitable for generating session tokens, API keys, and nonces. However, the security of the final token also depends on sufficient entropy (length ร— logโ‚‚(alphabet size) โ‰ฅ 128 bits recommended) and secure transmission (HTTPS).
For the default 64-character alphabet (a power of 2), rejection never occurs - every byte is valid. For non-power-of-2 alphabets, the worst case is alphabet size 33 (mask = 63), where approximately 47.6% of bytes are rejected. The generator compensates by requesting extra bytes upfront (step size = ceil(1.6 ร— L)). For a batch of 1,000 IDs at length 21 with a 33-char alphabet, expect roughly 35,000 random bytes consumed - negligible for crypto.getRandomValues() which can produce millions of bytes per second.