Base64 Decode Error — Invalid Character Fix

💡A Base64 decode error with 'invalid character' usually means the string uses URL-safe encoding (- and _), is missing padding (= signs), or contains whitespace. Convert URL-safe characters to standard ones, add missing padding, and strip whitespace before decoding.

Quick Diagnosis

If you seeInvalid character in Base64” → it means the input contains a character not in the Base64 alphabet (A–Z, a–z, 0–9, +, /) do this: strip whitespace and newlines, or switch to URL-safe Base64 if the string uses - and _

If you seeIncorrect padding” → it means the Base64 string length is not a multiple of 4 do this: pad with = characters at the end until the length is divisible by 4

If you seedecoded output is garbled” → it means the encoding was URL-safe (- and _ instead of + and /) do this: replace - with + and _ with / before decoding with standard Base64

If you seeerror only when decoding API response” → it means the response may be double-encoded or include surrounding quotes do this: trim quotes and whitespace from the raw string before decoding

Common Fixes

URL-safe Base64 — wrong alphabet

❌ Wrong

atob('aGVsbG8-d29ybGQ_')
// InvalidCharacterError: Invalid character

✅ Fixed

atob('aGVsbG8-d29ybGQ_'.replace(/-/g, '+').replace(/_/g, '/'))
// → 'hello world'

URL-safe Base64 uses - and _ instead of + and /. Convert before calling atob().

Missing padding

❌ Wrong

atob('aGVsbG8')
// InvalidCharacterError: Invalid character

✅ Fixed

const pad = s => s + '='.repeat((4 - s.length % 4) % 4);
atob(pad('aGVsbG8'))
// → 'hello'

Base64 strings must be padded to a multiple of 4. Add = characters as needed.

When to Use the Decoder Tool

If you are working with an API response, JWT payload, or binary data encoded as Base64, paste the raw string into the decoder to confirm it is valid before processing it in code. The tool will identify padding issues and invalid characters immediately, saving time compared to debugging through error messages alone.

Decode Base64 Without Errors

Paste your Base64 string and decode it instantly. The tool handles standard and URL-safe encoding and shows the exact error if the input is invalid.

Related Guides

Frequently Asked Questions

What causes a Base64 invalid character error?

The input contains characters outside the standard Base64 alphabet. Common causes are URL-safe encoding (- and _ instead of + and /), embedded newlines, or stray whitespace.

How do I fix Base64 padding?

Add = characters at the end until the string length is divisible by 4. The formula is: padding = (4 - length % 4) % 4.

Is URL-safe Base64 the same as standard Base64?

No. URL-safe Base64 replaces + with - and / with _. You must convert back to standard characters before using atob() or most Base64 decoders.

All tools run in your browser. Your data never leaves your device.