Encodings / Guides

Base64 vs Base64 URL

They encode the same bytes, but with two-character alphabet differences that change everything when the result lands in a URL or JWT. Here's exactly what's different, when each is used, and how to convert between them.

Encode or decode now →

The two-character difference

Both encodings turn 3 input bytes into 4 output characters from a 64-character alphabet. They differ on two characters:

PositionBase64 (RFC 4648 §4)Base64 URL (RFC 4648 §5)
62+-
63/_
Padding= required to multiple of 4= usually omitted

That's it. Same 0–61 (A–Z, a–z, 0–9), same encoding algorithm, same decoded output. The two-character swap exists so the result is safe to drop into a URL path or query string without further escaping.

When to use which

Use Base64 (standard) for…

Use Base64 URL for…

Why the standard Base64 characters break URLs

URLs interpret several Base64 characters as control:

Base64 URL avoids all three by mapping the two problematic alphabet characters to - and _ (which are valid in URLs without escaping) and dropping padding entirely.

Converting between them

The transform is mechanical:

// standard → URL
const urlSafe = standard
  .replace(/\+/g, "-")
  .replace(/\//g, "_")
  .replace(/=+$/, "");

// URL → standard
const padded = urlSafe + "=".repeat((4 - urlSafe.length % 4) % 4);
const standard = padded.replace(/-/g, "+").replace(/_/g, "/");

Our encoder does the conversion for you — paste a Base64 URL string into the Base64 URL tab and decode, or paste a standard Base64 string into the Base64 tab.

Quick reference: decoding a JWT

A JWT is three Base64 URL segments joined by dots:

eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiIxIn0.dBjftJeZ4CVP-mB92K27uhbUJU1p1r_wW1gFWFOEjXk

To peek at the contents:

  1. Split on . — three segments.
  2. Decode segment 1 (header) as Base64 URL → JSON. Tells you the algorithm.
  3. Decode segment 2 (payload) as Base64 URL → JSON. Your claims.
  4. Segment 3 is the signature — binary, used only for verification.

Important: decoding only proves what the token claims. Always verify the signature server-side before trusting any claim from a JWT.

Reference

FAQ

Why does my Base64 string fail to decode?

Most often: it's actually Base64 URL (uses - and _ instead of + and /), or padding (= characters at the end) is missing, or the string was HTML-escaped somewhere along the way (+ became a space). Try the Base64 URL tab.

Are Base64 and Base64 URL the same length?

Same encoded length before padding is stripped. Standard Base64 always pads to a multiple of 4 with = characters. Base64 URL strips padding, so an unpadded Base64 URL string can be up to two characters shorter than the equivalent standard Base64.

Can I just use Base64 in URLs?

Technically you can, but the + / and = characters all have meaning in URLs (+ is sometimes parsed as a space, / is a path separator, = is a query-string separator). Browsers and servers may rewrite them. Base64 URL exists specifically to dodge this.

How do I decode a JWT?

A JWT is three Base64 URL-encoded segments separated by dots: header.payload.signature. Split on dots, decode the first two segments as Base64 URL, parse each as JSON. The signature is binary; you don't read it directly, you verify it against the header+payload using the algorithm in the header.

Is Base64 encryption?

No. Base64 is a reversible encoding — anyone can decode it without a key. Use it for transport (binary in text channels) and identifier-shape (URL-safe IDs), never for keeping secrets.

Open the encoder →