← devnestio

Nano ID Generator

Settings

Nano ID
ULID
Hex Token
Custom
Nano ID — URL-safe unique ID, similar to UUID but smaller. Default alphabet: 64 chars, default length: 21. Collision probability ā‰ˆ1% at 1 billion IDs.

Generated IDs

What is Nano ID Generator?

Nano ID Generator creates cryptographically secure, URL-safe unique identifiers using the Nano ID algorithm. Specify the length (default: 21 characters), choose the character set (alphanumeric, numbers-only, custom), and generate one or multiple IDs at once. Nano ID uses a secure random source (Web Crypto API in browsers, crypto module in Node.js) for unpredictable output.

Nano ID is a tiny, secure, URL-friendly unique ID library created by Andrey Sitnik. A 21-character alphanumeric Nano ID has the same collision resistance as UUID v4 (128 bits of randomness), but is 30% shorter. Nano ID uses a custom alphabet (A-Za-z0-9_-) that is URL-safe without encoding. The algorithm: generate cryptographically random bytes, use modulo to map to the alphabet (with rejection sampling to avoid modulo bias).

Nano ID vs UUID: Nano IDs are shorter (21 chars vs 36 chars), URL-safe (no dashes that need encoding), and customizable (any length or alphabet). UUID v4 is the established standard with broad database and language support (PRIMARY KEY UUID in PostgreSQL, uuid.uuid4() in Python). For database primary keys, UUID v4 has more tooling support. For URLs, session tokens, or application IDs, Nano ID's shorter format is cleaner.

How to Use

  1. Click 'Generate' to create one Nano ID with default settings (21 chars, URL-safe).
  2. Adjust the length slider — shorter IDs have more collision risk for large datasets.
  3. Select a character set: URL-safe alphanumeric, numbers only, or define a custom set.
  4. Set 'Count' to generate multiple IDs at once (up to 100).
  5. Copy individual IDs or use 'Copy all' to get all generated IDs as a newline-separated list.

Examples

Default 21-char ID

Result: Example: V1StGXR8_Z5jdHi6B-myT (URL-safe, ~128 bits entropy)

Short ID for URL

Result: 10-char ID: dBjftJeZ7b (62^10 ā‰ˆ 839 trillion combinations)

Numeric-only ID

Result: Alphabet: 0-9, length: 16 → 1847392056183047 (for SMS codes: 6 digits)

Frequently Asked Questions

How does Nano ID ensure uniqueness?

Nano ID uses cryptographically secure random bytes from the Web Crypto API (crypto.getRandomValues in browsers, crypto.randomBytes in Node.js). For a 21-character alphanumeric ID: 64 characters in the alphabet, 21 positions → 64^21 = 2^126 possible IDs — approximately the same as UUID v4 (2^122). The birthday paradox means collisions become likely after approximately 2^63 IDs generated. For 1% collision probability: you'd need to generate ~2.9 Ɨ 10^18 IDs. In practice, this is computationally impossible.

What is the birthday paradox and why does it matter for IDs?

The birthday paradox: in a group of 23 people, there's a 50% probability that two share a birthday — even though there are 365 possible birthdays. For IDs: given n unique IDs in a space of N possibilities, collision probability ā‰ˆ n² / (2N). For UUID v4 (2^122 space): to reach 1% collision probability, you'd need to generate 2.6 Ɨ 10^17 IDs. At 1 billion IDs/second, this takes 8 years. For a 10-char alphanumeric ID (62^10 ā‰ˆ 8.4 Ɨ 10^17): the same 1% threshold requires ~4 billion IDs — achievable in a busy system. Choose ID length based on your expected dataset size.

Should I use Nano ID or UUID for database primary keys?

UUID v4: native database support (PostgreSQL uuid type, MySQL BINARY(16)), standard tooling, widely recognized. Nano ID: shorter (21 chars vs 36 chars for UUID), URL-safe, more flexible. For new projects with PostgreSQL: consider UUID v7 (2023, time-ordered for better index performance) or ULID (similar to UUID v7 but base-32 encoded). For exposed URLs: Nano ID (shorter, no dashes). For internal database PKs: UUID v4 or UUID v7 (better index performance than random UUIDs because time-ordered). Don't use auto-increment integers for exposed IDs — they're predictable and enumerate your data.

What is the Nano ID alphabet and why is it URL-safe?

The default Nano ID alphabet is: A-Za-z0-9_- (64 characters). These are all URL-safe characters that don't need percent-encoding in URLs (RFC 3986 unreserved characters). Excluded: +, /, and = from base64 (need encoding in URLs), space, and special characters. This means a Nano ID can be used directly in URLs, filenames, HTML attributes, and JSON without escaping. Custom alphabets: remove ambiguous characters (0, O, I, l) for human-readable IDs, or use only lowercase for case-insensitive contexts.

What is ULID and how does it differ from Nano ID?

ULID (Universally Unique Lexicographically Sortable Identifier) is a 26-character base-32 ID that encodes a timestamp in the first 10 characters and randomness in the last 16. This makes ULIDs sortable by creation time — unlike random UUIDs or Nano IDs. Benefits: database index locality (sequential IDs cluster on index pages → better write performance), embedded creation time (no separate created_at column needed for basic sorting), still globally unique. Use ULID when you need sortable IDs (log entries, database records). Use Nano ID when you need shorter IDs without sorting requirements.

Related Tools