Fix Base64 “Invalid Symbol at Offset” Errors
Seeing invalid character or invalid symbol at offset? This is usually caused by URL-safe characters, missing padding, or hidden newlines. Follow the steps below to fix it fast.
What the error means
The offset tells you where parsing failed. If the character at that position is a newline, quote, URL-safe marker, or random symbol, decoding stops immediately.
Fast diagnosis checklist
- Remove spaces, tabs, and line breaks.
- Convert URL-safe Base64 (-, _) to standard (+, /).
- Ensure length is a multiple of 4; add = padding when required.
- If input starts with data:, strip the prefix before decode.
- Confirm you are decoding with the correct variant (standard vs URL-safe).
Rust-specific fix pattern
fn normalize_base64(input: &str) -> String {
let raw = input.trim().replace(char::is_whitespace, "")
.replace('-', "+")
.replace('_', "/");
let remainder = raw.len() % 4;
if remainder == 0 {
raw
} else {
format!("{}{}", raw, "=".repeat(4 - remainder))
}
}After normalization, decode using the expected engine. If your source is URL-safe by design, decode with a Base64URL engine instead of converting characters.
When offset is 10 or 48
These are common positions for copied newlines in logs or wrapped payloads. Print the raw character at the offset before applying fixes, then re-run decode.
Common Base64 invalid-character fixes
Browser InvalidCharacterError
If atob() fails, remove any data:*;base64, prefix and whitespace before decoding. Browser decoders expect only the Base64 payload.
URL-safe payloads
JWTs and URL parameters often use - and _. Decode them with a Base64URL decoder, or normalize them to + and / before using a standard decoder.
Bad padding
A copied value can lose trailing = padding. Add padding until the payload length is divisible by four, then decode again.
Base64 decode error FAQ
What does “invalid symbol at offset” mean in Base64?
It means the decoder found a character that does not belong to the expected Base64 alphabet at that exact index.
Why do offsets like 10 or 48 appear often?
Those offsets commonly map to copied line breaks, extra whitespace, or URL-safe characters that were not converted to standard Base64.
How do I fix Base64 decode errors quickly?
Trim whitespace, convert URL-safe characters, fix padding, then decode again with the correct standard or URL-safe variant.
How do I fix InvalidCharacterError when decoding Base64 in the browser?
Remove any data URL prefix, whitespace, and line breaks before calling atob, then restore missing padding and use the URL-safe variant only when the input uses - or _.