Nano ID vs uuid
Nano ID vs uuid compared for 2026: Evil Martians' 21-character URL-safe ID generator (nanoid 6.0.2) vs the RFC 9562 uuid package (14.0.3) with v4 and time-ordered v7. Includes speed, bundle size, sort order, TypeScript and PostgreSQL index-size tests we ran on 5 December 2026.
Quick Answer
Use uuid's v7() for database primary keys and anything another system has to parse, and Nano ID for short, URL-safe public IDs. In our PostgreSQL 16 test with 1 million rows, v7 values in a native uuid column built the smallest primary-key index (31.6 MB) and loaded fastest (1.4-2.1 s), because they arrive in time order; random v4 UUIDs needed 39.3 MB and 3.7-3.9 s, and Nano IDs in a text column 53.3 MB and 4.3-5.4 s. Nano ID 6.0.2 wins on size and speed in JavaScript: 21 characters instead of 36, 195 bytes minified in a browser bundle against 791 for uuid's v4, and 49-67 ms per million IDs on one core against 150-204 ms for uuid v4 and 117-134 ms for Node's built-in crypto.randomUUID(). uuid v7 was the slowest generator at 1.36-1.58 s per million, which is still far more than any database can insert. Both packages are ESM-only, MIT-licensed and dependency-free, and both loaded with require() on Node.js 22.23.5. If you only need random v4 strings, crypto.randomUUID() needs no package at all.
Last updated December 5, 2026. Covers nanoid 6.0.2 (5 October 2026) and uuid 14.0.3 (10 October 2026); npm registry metadata and download counts, GitHub repositories and releases, both READMEs and CHANGELOGs read on 5 December 2026, plus speed, bundle, sort-order, TypeScript and PostgreSQL 16 tests we ran that day.
| Feature | Nano ID | uuid |
|---|---|---|
| Licence & Repository | MIT; ai/nanoid, ~27.1k stars, 2 open issues and PRs | MIT; uuidjs/uuid, ~15.4k stars, 10 open issues and PRs |
| Latest Release | 6.0.2 on 5 Oct 2026 (3.3.20 CommonJS line the same day) | 14.0.3 on 10 Oct 2026 |
| npm Weekly Downloads (28 Nov-4 Dec 2026) | 345,899,935 | 335,564,026 |
| Our Run: Install (packages / size) | 1 package, 14.7 KB | 1 package, 65.7 KB |
| Default ID Format | 21 chars, A-Za-z0-9_- (e.g. V1StGXR8_Z5jdHi6B-myT) | 36 chars, 8-4-4-4-12 hex |
| Random Bits (per README / RFC 9562) | 126 bits at default size | 122 bits (v4); 74 bits after the 48-bit timestamp (v7) |
| Standard | None (library convention) | RFC 9562 |
| ID Kinds | Random only; custom alphabet/size; non-secure variant | v1, v3, v4, v5, v6, v7, NIL, MAX |
| Our Run: Sorts in Creation Order (100,000 IDs) | No | Yes with v7 (v4 no) |
| Validation & Parsing | ||
| Our Run: 1 Million IDs (1 core, 3 runs) | 49-67 ms (customAlphabet hex32 61-99 ms) | v4 150-204 ms; v7 1,362-1,578 ms |
| Our Run: Browser Bundle (min / gzip) | 195 B / 223 B | v4 791 B / 481 B; v7 1,280 B / 672 B |
| Our Run: PostgreSQL PK Index, 1M Rows | 53.3 MB (text column) | v7 31.6 MB; v4 39.3 MB (uuid column); v4 as text 75.8 MB |
| Our Run: PostgreSQL COPY 1M Rows | 4,345-5,440 ms | v7 1,439-2,083 ms; v4 3,735-3,949 ms |
| Our Run: Bytes per Value in PostgreSQL | 22 bytes (text) | 16 bytes (uuid); 37 bytes as text |
| URL-Safe Without Encoding | ||
| Module Format | ESM only (require() worked on Node 22.23.5) | ESM only since v12 (require() worked on Node 22.23.5) |
| Our Run: TypeScript Mistakes Caught | 1 of 2 (size type caught; branded type inferred without a cast) | 3 of 3 (built-in types) |
| Command Line | npx nanoid [--size] [--alphabet] | npx uuid [v1|v3|v4|v5|v6|v7] |
| Release Activity | 6.0.0 Jul, 6.0.1 Aug, 6.0.2 Oct 2026 | 14.0.0 Apr, 14.0.1 Jun, 14.0.2 Aug, 14.0.3 Oct 2026 |
Nano ID
Nano ID is a tiny random string ID generator from Andrey Sitnik and Evil Martians. nanoid() returns a 21-character ID from a 64-symbol URL-friendly alphabet (A-Za-z0-9, underscore and hyphen), which its README puts at 126 random bits, close to the 122 random bits of a UUID v4. customAlphabet() and customRandom() build generators with your own alphabet (1 to 256 symbols) and length, and nanoid/non-secure trades the hardware random source for Math.random. It reads randomness from Node's crypto module or the Web Crypto API and uses a rejection-style algorithm rather than random % alphabet, so every symbol is equally likely. The package has no dependencies, ships its own TypeScript types, includes a CLI (npx nanoid --size 10) and has been ported to more than 20 languages. Version 6.0.0 (12 July 2026) made nanoid() and customAlphabet() four times faster and dropped Node.js 18 and 20; 6.0.2 (5 October 2026) trimmed the bundle and fixed customRandom edge cases. It is ESM-only; the CommonJS 3.x line still gets fixes (3.3.20 on the same day). There is no parse, validate or timestamp: an ID is just a string.
Pros
- Short IDs: 21 URL-safe characters instead of 36, with a similar amount of randomness
- Fastest generator in our run: 49-67 ms per million IDs on one core
- Tiny: 195 B minified (223 B gzip) in a browser bundle, 14.7 KB installed, zero dependencies
- Custom alphabets and lengths for invite codes, slugs or numeric-only IDs
- Safe edge cases: nanoid(-1) threw RangeError (Wrong ID size) instead of looping
Cons
- Not a standard: databases, APIs and other languages see an opaque string with no validator
- Random order: 100,000 IDs did not sort in creation order, which bloats B-tree indexes
- Bigger and slower in PostgreSQL text columns: 53.3 MB PK index and 4.3-5.4 s to load 1M rows
- 48.7% of 1 million IDs contained - or _, and 1.5% started with -, which trips some CLIs and tools
- ESM-only and Node.js ^22, ^24 or >=26 for 6.x; older runtimes need the 3.x line
Best For
Short public IDs in URLs (share links, invite codes, file names), client-generated keys in browsers and React Native, and any place where length matters more than interoperability.
uuid
uuid is the reference JavaScript implementation of RFC 9562 (which replaced RFC 4122). It generates every UUID version: v1 and v6 (timestamp plus node), v3 and v5 (name-based, MD5 and SHA-1), v4 (random) and v7 (Unix-millisecond timestamp followed by random bits, so values sort by creation time). It also exports NIL and MAX, parse() and stringify() to convert between strings and 16-byte arrays, validate(), version(), and v1ToV6()/v6ToV1(). Each generator can write straight into a caller-supplied Uint8Array. The package has no dependencies, is tree-shakeable (sideEffects false), ships TypeScript types and a uuid CLI. Version 12 (September 2025) removed CommonJS, and 14.0.0 (19 April 2026) fixed advisory GHSA-w5hq-g745-h8pq, where v3(), v5() and v6() could write outside a caller's buffer given a bad offset; it also requires a global crypto object (Node.js 20 or later) and TypeScript 5.4.3 or later. 14.0.2 (18 August 2026) fixed v1 nanosecond overflow and the v7 sequence formula in v7Bytes, and 14.0.3 (10 October 2026) is the current release. Older majors 11, 12 and 13 received patch releases in April and May 2026.
Pros
- A standard: PostgreSQL uuid columns, SQL Server, Java, Go and every API client understand it
- v7 is time-ordered: 100,000 IDs sorted exactly in creation order
- Smallest and fastest PostgreSQL keys in our test with v7 in a uuid column: 31.6 MB index, 1.4-2.1 s per 1M rows
- validate(), version() and parse() built in; v5 gives deterministic IDs from a name
- TypeScript caught 3 of 3 planted option mistakes; buffer offsets out of range throw RangeError
Cons
- 36 characters as text; long in URLs and logs
- v7 was the slowest generator we timed: 1,362-1,578 ms per million IDs on one core
- Bigger browser bundle: 791 B for v4, 1,280 B for v7, 2,027 B with validate and version
- v7 leaks creation time to the millisecond to anyone who can see the ID
- ESM-only since v12; import * as uuid pulls in every version (10,251 B in our browser bundle)
Best For
Database primary keys (v7 in a native uuid column), IDs that cross service or language boundaries, deterministic IDs from names (v5) and anything that must validate as a UUID.
Two different jobs: a standard vs a short string
The uuid package implements a specification. Every value it produces is 128 bits laid out by RFC 9562, with version and variant bits in fixed places, so validate() and version() can tell a v7 from a v4 and any database or language can parse it into 16 bytes. Version 4 fills 122 bits with randomness; version 7 starts with a 48-bit Unix millisecond timestamp and fills the rest with random bits and a counter, so IDs created later sort later. Name-based v5 always returns the same UUID for the same namespace and name: v5('techloghub.com', v5.DNS) gave 53371fed-b858-5665-80ef-cef03e726899 both times we ran it. Nano ID is not a format at all. It is a fast, well-tested way to turn secure random bytes into a string from an alphabet you choose, 21 characters from 64 URL-safe symbols by default. That gives you about the same collision resistance as v4 in 15 fewer characters, but no structure: validate() from uuid returned false for every Nano ID, as it should, and there is no Nano ID validator because any 21-character string from the alphabet is valid. Pick the tool by who consumes the ID. If it crosses a boundary (a database type, a partner API, a Go service), use a UUID. If it ends up in a URL or in front of a person, Nano ID's length is the feature. Our UUID Generator tool and UUID v4 vs v7 guide cover the format in more depth.
What we measured in Node.js: speed, size and edge cases
On 5 December 2026 we installed nanoid 6.0.2 and uuid 14.0.3 on Node.js 22.23.5 in a 2-vCPU sandbox and generated 1 million IDs per run on one pinned core, three runs each. nanoid() took 49-67 ms, a 32-character hex customAlphabet 61-99 ms, and nanoid/non-secure 326-356 ms (the README warns the non-secure version is slower). uuid's v4() took 150-204 ms and Node's own crypto.randomUUID() 117-134 ms. uuid's v7() took 1,362-1,578 ms, roughly ten times v4, but that is still more than 600,000 IDs per second per core. For reference, the ulid package (3.0.2) took 25-27 seconds per million in the same harness, so check that one before using it on a hot path. Bundled with esbuild 0.28.2, minified, a browser entry that imports nanoid was 195 B (223 B gzip); uuid's v4 was 791 B (481 B), v7 1,280 B (672 B), and v4 + v7 + validate + version 2,027 B (947 B). Import named functions: import * as uuid with the namespace logged pulled in 10,251 B. Edge cases held up on both sides. nanoid(0) returned an empty string, nanoid(-1) threw RangeError, and nanoid(2.5) returned 2 characters. uuid threw RangeError for a buffer offset that would run past a 16-byte array in v4, v7 and v5, the class of bug fixed in 14.0.0.
PostgreSQL: index size and insert speed
ID choice matters most in the database, so we loaded 1 million rows (an ID plus a short text payload) into PostgreSQL 16.15 four ways, with the primary key in place, three runs each, then ran VACUUM ANALYZE. uuid v7 in a native uuid column: COPY took 1,439-2,083 ms and the primary-key index was 31,563,776 bytes. uuid v4 in a uuid column: 3,735-3,949 ms and 39,329,792 bytes. Nano IDs in a text column: 4,345-5,440 ms and 53,346,304 bytes, with a 68.7 MB table against 60.2 MB. v4 stored as text, a common mistake: 4,546-5,766 ms and 75,792,384 bytes. pg_column_size reported 16 bytes per uuid, 22 per Nano ID and 37 per UUID string. pg_stats showed why v7 wins: its correlation with physical order was 1.0, against 0.007 for v4 and -0.001 for Nano ID, so new v7 keys append to the right edge of the B-tree instead of splitting random pages. Point lookups were similar for all three (a 100,000-row self-join took 212-237 ms). The lessons: store UUIDs in a uuid column, prefer v7 for large or write-heavy tables, and if you need short public IDs, keep a v7 primary key and add a unique Nano ID column for URLs. See our PostgreSQL vs MySQL and Prisma vs Drizzle comparisons for the wider database choice.
Sorting, privacy and URL safety
Time order is v7's main feature and its main trade-off. In our run 100,000 v7 IDs generated in a tight loop sorted into exactly the order they were created, across 432 distinct millisecond prefixes, because uuid keeps internal sequence state for IDs made in the same millisecond. That makes v7 good for cursor pagination and log correlation, but anyone who sees the ID can read when it was made: v7({ msecs: Date.UTC(2026, 11, 5) }) produced 01a24380-2000-73be-..., and the first 12 hex digits decode straight back to 2026-12-05T00:00:00Z. If creation time is sensitive (sign-up dates, order volume), use v4 or Nano ID for public IDs. Nano ID IDs have no order: the same 100,000-ID test did not sort. They are URL-safe without encoding, but the alphabet includes underscore and hyphen. Of 1 million default Nano IDs, 486,974 contained one of them, 15,473 started with a hyphen and 15,510 with an underscore. A leading hyphen can be read as a flag by command-line tools, and the README notes that CouchDB and PouchDB reserve a leading underscore, so add a prefix or use customAlphabet for those cases. UUIDs are hex and hyphens, case-insensitive for validate() (an uppercased v4 passed) but not hyphen-optional (32 bare hex digits failed).
TypeScript, modules and when to skip both
Both current lines are ESM-only: uuid since version 12, and nanoid 6.x ships as type module (its 3.x line is the CommonJS one). On Node.js 22.23.5 a CommonJS file could still require() each one, through Node's require(esm) support, taking 4.8 ms for nanoid and 11.2 ms for uuid in a single run. Nano ID 6.x requires Node.js ^22, ^24 or 26 and later; uuid 14 expects a global crypto object and supports current Node LTS releases plus one prior. Both ship their own types. In a strict TypeScript 6.0.3 check of five planted mistakes, uuid's types caught all three option errors (msecs passed to v4, a string msecs to v7 and a UUID assigned to a number) and nanoid's caught a string passed as the size. The one that slipped through: assigning nanoid() to a branded UserId type compiled without a cast, because nanoid's generic return type is inferred from the variable. Both have CLIs: npx nanoid --size 10 and npx uuid v7. You may not need either package. Node.js has crypto.randomUUID() built in for v4 values (so does the Web Crypto API in current browsers), and it beat uuid's v4 in our timing. Reach for uuid when you need v7, v5, validation or byte conversion, and for Nano ID when you need short IDs or a custom alphabet. Our Base64 Encoding Explained guide covers another way to shorten binary IDs for URLs.
Verdict
Use uuid's v7() for primary keys and for any ID another system, database or language has to understand. Stored in a native PostgreSQL uuid column, v7 values are 16 bytes, arrive in time order and gave us the smallest index and fastest load of everything we tried: 31.6 MB and 1.4-2.1 s for a million rows, against 39.3 MB and 3.7-3.9 s for random v4 and 53.3 MB and 4.3-5.4 s for Nano IDs in a text column. Use Nano ID for short public identifiers: share links, invite codes, file names, client-side keys and anything a person might copy, where 21 URL-safe characters beat 36 and the 195-byte browser footprint matters. It was also the fastest generator we timed. Avoid two common mistakes: storing UUIDs as text (the v4-as-text index was 75.8 MB, nearly twice the uuid column) and using Nano ID as a clustered primary key on large tables, where random order costs index size and insert speed. If you only ever need random v4 values in Node.js or the browser, crypto.randomUUID() is built in, faster than uuid's v4 in our run and needs no dependency. Many apps use both: a v7 primary key internally and a Nano ID slug in public URLs.


