AG UUID

NanoID Explained

An explanation of how the compact alternative identifier NanoID works and how to customize it.

How It Works

It is built by drawing characters from a URL-safe alphabet (A-Za-z0-9_-) using a cryptographic random source. The default 21 characters offer collision safety comparable to UUID v4 while being shorter.

Customization

You can freely change both the alphabet and the length. Reducing the length makes it shorter but raises the collision probability, so it is important to choose the length based on your expected generation volume.

Use Cases

It is well suited to places where length matters, such as short links, public IDs, and coupon or invite codes. If you need chronological ordering, consider ULID or UUID v7 instead of NanoID.