Base64url vs. Base64
Base64url (RFC 4648 §5) is Base64 made safe for URLs and file names. Two characters change and the padding goes away:
+becomes-and/becomes_the trailing
=padding is usually omitted
You meet it in JSON Web Tokens, OAuth PKCE challenges, WebAuthn and many short IDs. A strict standard Base64 decoder rejects it; this one accepts both.
Decoding in code
// Node.js
Buffer.from(s, 'base64url').toString('utf8')
// Browser
const b64 = s.replace(/-/g, '+').replace(/_/g, '/');
new TextDecoder().decode(Uint8Array.from(atob(b64), c => c.charCodeAt(0)))
# Python – add the padding back first
import base64
base64.urlsafe_b64decode(s + '=' * (-len(s) % 4)) Questions
How do I decode a JWT with this?
A JWT has three Base64url parts separated by dots. Paste the middle part (the payload) to read the claims, or the first part for the header – or paste the whole token into the JWT decoder, which also shows the dates and verifies the signature. Decoding alone proves nothing – never trust the content of a token just because it decodes.
Does the encoder produce Base64url?
The encoder writes standard Base64. To turn it into Base64url, replace + with -, / with _ and strip the trailing =.
Why do I get garbled characters?
The decoded bytes are not UTF-8 text – they may be binary data such as a signature, an image or compressed content.