Base64URL Safe Encoder & Decoder

RFC 4648 §5 (- and _ alphabet, optional = strip) for JWT, PKCE & WebAuthn

Presets:
Input 0 B
Base64URL Output 0 B
Ready
0 B → 0 charsCmd/Ctrl+Enter
Advertisement
Reserved fixed-height slot (CLS = 0.00) 728×90 320×100 300×50

Standard Base64 vs. Base64URL (RFC 4648 §5)

Standard Base64 uses +, /, and =, all of which carry special semantics in URLs: + is interpreted as a space in application/x-www-form-urlencoded queries, / separates path segments, and = separates key/value pairs. Embedding raw Base64 in a query parameter without percent-encoding silently corrupts signatures and tokens.

RFC 4648 Section 5 solves this by substituting - for + and _ for /, and protocols like JWT, OAuth 2.0 PKCE, and WebAuthn strip trailing = padding altogether. Because the unpadded length modulo 4 uniquely determines the missing pad count (length % 4 === 2 needs ==, length % 4 === 3 needs =, while length % 4 === 1 is always invalid), Base64URL round-trips losslessly.

  • Character MapReplaces standard + (index 62) with - (hyphen) and / (index 63) with _ (underscore).
  • Padding RuleOmits trailing = characters by default per RFC 7515 (JWS) and RFC 7636 (OAuth PKCE).
  • Primary ProtocolsJWT / JWS / JWK, OAuth 2.0 PKCE code_challenge, WebAuthn / Passkey credential IDs, and signed URLs.
How do I convert standard Base64 to Base64URL in code?

Replace every + with -, replace every / with _, and strip trailing = characters (for example: str.replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "")).

Why is a Base64URL string with length % 4 === 1 always invalid?

Each Base64URL character carries 6 bits. One stray character provides only 6 bits—two bits short of a full 8-bit byte—so valid unpadded encodings only ever have lengths congruent to 0, 2, or 3 modulo 4.

Does WebAuthn use Base64URL for credential IDs and challenges?

Yes. The WebAuthn Level 3 JSON serialization methods (parseCreationOptionsFromJSON and toJSON) encode all ArrayBuffer fields such as challenge, rawId, and clientDataJSON using unpadded Base64URL.