Erzeugen NanoIDs for compact unique identifiers
NanoID ist ein tiny, URL-sicher, eindeutig ID generator. Smaller und faster than UUID, mit customizable alphabet und Größe.
- 1
NanoID is a 21-character URL-safe ID (default alphabet: A-Za-z0-9_-). It is 4 bytes shorter than UUID v4 (36 chars with hyphens) and faster to generate. The collision probability is negligible: with 21 chars from a 64-char alphabet, you need 2^63 IDs for a 50% collision chance. NanoID is ideal for URLs, database keys, and component IDs.
- 2 UUID/ULID-Generator →
Erzeugen a UUID for comparison. UUID v4 is 36 characters (32 hex + 4 hyphens). NanoID is 21 characters — 40% shorter. For URL-safe IDs, NanoID is preferable (UUID uses hyphens which may need encoding in some contexts). Use UUID when you need RFC 4122 compliance; use NanoID for compact, URL-safe IDs.
- 3 Base58-Kodierer →
For even shorter IDs, encode a random number in Base58 (Bitcoin alphabet, no 0/O/I/l). A 16-byte random number in Base58 is ~22 characters. Base58 is URL-safe and human-readable (no ambiguous characters). Use this for user-facing IDs where length matters.
- 4 Zufallsbytes-Generator →
Erzeugen the random bytes for NanoID. NanoID uses a CSPRNG (crypto.getRandomValues) for security. 21 characters from a 64-character alphabet provides 126 bits of entropy — sufficient for global uniqueness with negligible collision probability.
Häufige Fragen
- NanoID vs UUID — which to use?
- Use NanoID for compact, URL-safe IDs (URLs, database keys, component IDs). Use UUID when you need RFC 4122 compliance, standard format (8-4-4-4-12), or interoperability with systems that expect UUIDs. NanoID is shorter (21 vs 36 chars) and faster, but UUID is more widely recognized.
- Can I customize NanoID?
- Yes. Specify the size (default 21) and alphabet (default URL-safe: _-0-9a-zA-Z). For a larger alphabet (more entropy per char), use Base64. For human-readable IDs, use a custom alphabet without ambiguous characters (0/O, 1/l/I). For prefixed IDs (user_xxx), prepend a prefix to the generated ID.