Encrypt Online
Theme

Encoding & Transport · Field note

Base64URL vs Base64: What Changes on the Web

A practical guide to the differences between standard Base64 and URL-safe Base64 so you stop breaking tokens and query values.

Encrypt Online Editorial Team3 min read
Base64URL vs Base64: What Changes on the Web guide cover

Before you start

Decode a small sample first and confirm whether you are changing representation, changing structure, or actually protecting content.

In brief

What it is: Base64URL is the URL-safe variant of Base64 that swaps two characters and often omits padding.

Why it matters: That small change matters in tokens, URLs, cookies, and signed request strings where the standard alphabet can break transport or verification.

Watch for: Debugging a transport mismatch as if it were an encryption bug.

This difference is small on paper and expensive in production. A token that survives one system can break in another when the alphabet or padding rules are off by a single character.

Base64URL belongs next to Base64, URL, and JWT-style workflows because most failures here are transport bugs, not crypto bugs.

What changes between them

  • Base64URL exists to make encoded values friendlier in URLs and filenames.
  • Not every system that says “Base64” means the same alphabet or padding behavior.
  • A token bug can be nothing more than one side expecting URL-safe encoding and the other side using standard Base64.
TopicStandard Base64Base64URL
Character setUses + and /Uses - and _
PaddingOften uses =Padding may be omitted depending on the protocol
Best fitGeneral encoded text transportURLs, tokens, filenames, and web-safe contexts
Common failure modeNeeds extra escaping in URLsDecoded with the wrong alphabet or padding expectations

Mistakes that lead to the wrong choice

  • Assuming every Base64 value is safe to paste into a URL as-is.
  • Dropping or adding padding without checking the protocol.
  • Decoding a Base64URL token with tooling that expects the standard alphabet.
  • Thinking the problem is cryptographic when it is actually just character compatibility.

Decision questions

Why do web tokens use - and _?

Because those characters are friendlier in URLs and filenames than + and /.

Do I always need padding?

No. Some protocols omit it, but you should follow the rules of the system you are interoperating with.

Can I fix a broken token by URL-encoding it?

Sometimes, but first confirm whether the system expected Base64URL instead of standard Base64.

Do this locally (CLI)

Shell
printf '%s' 'hello?' | openssl base64 -A
printf '%s' 'aGVsbG8_' | tr '_-' '/+' | awk '{ l=length($0)%4; if (l==2) print $0"=="; else if (l==3) print $0"="; else print $0 }' | openssl base64 -d -A
  • Standard Base64 and Base64URL use different alphabets for two characters.
  • If padding was omitted, restore it before using a strict standard Base64 decoder.

Standards and references