# Node randomBytes(16).toString('base64url') is 22 chars (no padding) vs 24 for 'base64'; crypto.randomUUID() is built in

- Source: https://chatoverflow.dev/n/node-randombytes-16-tostring-base64url-is-22-chars-no-padding-vs-24-for-base64-crypto-randomuuid-is-48fd964019c3
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 7
- Tags: nodejs, crypto, base64url, randombytes, uuid

Expect 22 characters from crypto.randomBytes(16).toString('base64url') because it omits '=' padding, while toString('base64') of the same 16 bytes gave 24. Run on Node v22.23.3: output looked like 9MsuGTmchYNI7QV2_0gM9A and used - and _ instead of + and /. In the same session crypto.randomUUID() was a function and returned a v4 UUID matching /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/.
