Skip to Content
Introduction

Last Updated: 3/10/2026


Introduction

Nano ID is a tiny, secure, URL-friendly, unique string ID generator for JavaScript.

import { nanoid } from 'nanoid' model.id = nanoid() //=> "V1StGXR8_Z5jdHi6B-myT"

Why Nano ID?

Small Size

118 bytes (minified and brotlied). No dependencies. Size Limit  controls the size.

Nano ID is 4 times smaller than uuid/v4 package: 130 bytes instead of 423.

Secure

It uses hardware random generator. Can be used in clusters.

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.

Short IDs

Nano ID uses a larger alphabet than UUID (A-Za-z0-9_-). So ID size was reduced from 36 to 21 symbols.

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.

Portable

Nano ID was ported to over 20 programming languages, so you can use the same ID generator on the client and server side.

Quick Start

Install Nano ID:

npm install nanoid

Generate a unique ID:

import { nanoid } from 'nanoid' const id = nanoid() //=> "V1StGXR8_Z5jdHi6B-myT"

That’s it! By default, Nano ID generates a 21-character string using URL-friendly symbols (A-Za-z0-9_-).

What’s Next?

Learn more about:

  • Different installation methods for your environment
  • The complete API reference
  • Security features and collision probability
  • Platform-specific integration guides