+0
Daily
+10
Weekly
+26
Monthly
27,130
stars
977
forks
157
watchers
316
prs
270
issues
37
releases
README
Nano ID
English | 日本語 | Русский | 简体中文 | Bahasa Indonesia | 한국어 | العربية
A tiny, secure, URL-friendly, unique string ID generator for JavaScript.
“An amazing level of senseless perfectionism,
which is simply impossible not to respect.”
- Small. 117 bytes (minified and brotlied). No dependencies.
[Size Limit] controls the size.
- Fast. Faster than native crypto.randomUUID().
- Safe. It uses hardware random generator. Can be used in clusters.
- Short IDs. It uses a larger alphabet than UUID (A-Za-z0-9_-).
So ID size was reduced from 36 to 21 symbols.
- Portable. Nano ID was ported
to over 20 programming languages.
js
import { nanoid } from 'nanoid'
model.id = nanoid() //= "V1StGXR8_Z5jdHi6B-myT"
---
Nano ID is built by Evil Martians, an American design and engineering consultancy for developer tools, AI, and cybersecurity startups.
---
[Size Limit]: https://github.com/ai/size-limit
Table of Contents
- Table of Contents
- Comparison with UUID
- Benchmark
- Security
- Install
- CDN
- API
- Custom Alphabet or Size
- Custom Random Bytes Generator
- Non-Secure
- Usage
- React
- React Native
- PouchDB and CouchDB
- CLI
- TypeScript
- Other Programming Languages
- Tools
Comparison with UUID
Nano ID is quite comparable to UUID v4 (random-based).
It has a similar number of random bits in the ID
(126 in Nano ID and 122 in UUID), so it has a similar collision probability:
For there to be a one in a billion chance of duplication,
103 trillion version 4 IDs must be generated.
There are two main differences between Nano ID and UUID v4:
1. Nano ID uses a bigger alphabet, so a similar number of random bits
are packed in just 21 symbols instead of 36.
2. Nano ID is faster than crypto.randomUUID and uuid/v4.
Benchmark
rust
$ node ./test/benchmark.js
nope-id 50,866,431 ops/sec
nanoid 25,580,859 ops/sec
customAlphabet 3,955,574 ops/sec
crypto.randomUUID 6,583,303 ops/sec
uuid v4 5,575,055 ops/sec
@napi-rs/uuid 8,369,981 ops/sec
uid/secure 7,965,602 ops/sec
@lukeed/uuid 6,301,692 ops/sec
nanoid for browser 626,943 ops/sec
secure-random-string 509,515 ops/sec
uid-safe.sync 491,164 ops/sec
Non-secure:
uid 34,793,413 ops/sec
nanoid/non-secure 2,717,308 ops/sec
rndm 2,779,850 ops/sec
Security
_See a good article about random generators theory:
[Secure random values (in Node.js)]_
- Unpredictability. Instead of using the unsafe Math.random(), Nano ID
uses the crypto module in Node.js and the Web Crypto API in browsers.
These modules use unpredictable hardware random generator.
- Uniformity. random % alphabet is a popular mistake to make when coding
an ID generator. The distribution will not be even; there will be a lower
chance for some symbols to appear compared to others. So, it will reduce
the number of tries when brute-fDiscussions
#548Browser file is working on Nodejs 24?1 comments · 2025-12-05#528Incorrect release name `3.1.11`1 comments · 2025-04-07#513Need to fix bytes to bits1 comments · 2024-12-24#507How do I submit another language?2 comments · 2024-11-23#503Is Nanoid RFC3986 compatible?1 comments · 2024-10-20#498Does nanoid have async/await option or will it always block ?1 comments · 2024-09-06#497NanoId to Uint8Array1 comments · 2024-09-02#495What about benchmarks?2 comments · 2024-09-02
Latest release
6.0.2 6.0.2 2026-10-05- Reduced JS bundle size (by @bayandin). - Fixed floats in size of customRandom (by @lost-signals). - Fixed performance of customRandom on changes size (by @00200200). - Fixed docs (by @Likio3000 & @lenamonj).