Base64 guide
Fix Rust base64 Invalid symbol 61 padding errors
In Rust base64 decoding, symbol 61 is byte 0x3D, the equals sign used for padding.
What symbol 61 means
Decimal byte 61 is the equals sign. In Base64, padding belongs only at the end of a standard padded value. If the Rust base64 crate reports invalid symbol 61, the decoder encountered an equals sign before a valid padding position, or the selected engine expects no padding. This shows up with edited URL-safe values, pasted log text, wrongly joined wrapped lines, and JWT segments sent to a standard padded decoder.
Example
use base64::{engine::general_purpose, Engine as _};
let value = "SGVsbG8=gMTAyNGJhc2U";
let decoded = general_purpose::STANDARD.decode(value)?;
use base64::{engine::general_purpose, Engine as _};
let value = "SGVsbG8gMTAyNGJhc2U=";
let decoded = general_purpose::STANDARD.decode(value)?;
How to repair the padding
- Look for equals signs before the end of the value. Standard Base64 padding belongs only at the tail of the string.
- Remove labels, quotes, commas, and Bearer prefixes before checking the encoded characters. Wrapper text can make the offset point at the wrong place.
- Identify the source format: standard padded Base64, padded Base64URL, or unpadded Base64URL. Then choose the matching engine.
- JWT segments use Base64URL without padding in the signed token. Decode a copy for inspection and leave the token text unchanged when sending it back.
- After cleanup, count the remaining characters. Standard padded Base64 is built from 4-character groups.
Padding mode matters
The Rust base64 crate exposes separate engines because formats disagree on alphabet and padding. Standard padded text, padded Base64URL, and no-pad Base64URL are different inputs.
Symbol 61 can also mean the decoder mode is wrong. A no-pad engine rejects equals signs, and earlier cleanup can move padding into the middle of the value.
Symbol 61 vs symbol 10
Symbol 10 points at a line feed newline. Symbol 61 points at an equals sign. They can appear together when a copied value has both wrapped lines and padding.
Fix whitespace first, then padding. If you add padding while the value still contains newlines, the next error may be harder to read because offsets move around.
Common mistakes
- Adding equals signs in the middle of a Base64 value
- Using a padded decoder on a format that intentionally omits padding
- Treating a JWT segment as a normal padded Base64 string
- Fixing padding before removing copied quotes, commas, or log labels
- Changing a signed token and then expecting the original signature to stay valid
Related problems
FAQ
What character is symbol 61?
Symbol 61 is the equals sign, which is used as padding in standard Base64.
Can equals signs appear inside Base64?
No. In standard padded Base64, equals signs only appear at the end, and there can be zero, one, or two of them.
Do I always add padding before decoding?
No. Some formats use unpadded Base64URL. Match the decoder to the source format before editing the value.