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.
Continue with related guides
Browse the full guides hub or open the Base64 encode/decode tool.