Base64 vs Base64URL, and why strings end in =

Base64 turns bytes into ASCII. Base64URL is the same idea with a URL-safe alphabet. The trailing = characters are padding, not encryption, and some systems strip them.

What the alphabet is

Standard Base64 uses A–Z, a–z, 0–9, + and /, and pads with = so the length is a multiple of four.

Base64URL (RFC 4648 §5) swaps + for - and / for _. That avoids breaking query strings and file paths. JWTs, many signed cookies and some cloud signed URLs use Base64URL.

Why strings end in =

Base64 encodes three bytes as four characters. If the input length is not a multiple of three, the encoder adds one or two = characters so the output length stays a multiple of four.

One leftover byte → two padding chars (==). Two leftover bytes → one (=). Zero leftover bytes → no padding.

echo -n "ab" | base64
# YWI=   (2 bytes → one =)

echo -n "a" | base64
# YQ==   (1 byte → two =)

When padding is optional

Some protocols (JWT header and payload, many Base64URL APIs) omit padding. Decoders usually accept both. Encoders that must match a strict verifier should keep the same padding rule the verifier uses.

If a library rejects a JWT segment, try adding = until the length is a multiple of four before decoding.

Choosing the right mode

  • Use standard Base64 for MIME, data URLs, and most “encode this blob” tasks.
  • Use Base64URL when the string will sit in a URL, filename, or JWT.
  • Do not call either encryption. Anyone can decode them.

Questions

Is Base64URL more secure than Base64?
No. Only the alphabet changes. Both are encodings. Security comes from TLS, signatures or encryption elsewhere.
Can I strip the = characters?
Often yes for Base64URL consumers. Restore padding before a strict Base64 decoder if it requires a multiple of four.
Why does my decode fail with “invalid character”?
You are feeding Base64URL into a standard decoder (- and _), or the other way around. Switch alphabet, or replace -→+ and _→/ then pad.

See also

Related tool: Base64 encode. Runs in your browser; input is not uploaded.

More on this tool