
Short answer
A Base64 decode usually fails because of characters outside the alphabet, a bad length, stripped = padding, or mixing the URL-safe (- and _) and standard (+ and /) alphabets. Pad the length to a multiple of 4 and use the matching alphabet.
1. Checklist
| Symptom | Likely cause | Fix |
|---|---|---|
| Invalid character | Space, quote or line break inside the string | Remove whitespace and quotes |
| Invalid length | Truncated copy; 1 leftover character | Re-copy the full string |
| Missing padding | = stripped (common in JWTs and URLs) | Add = until length is a multiple of 4 |
| Garbled output | URL-safe string decoded as standard or the reverse | Switch alphabet: - and _ vs + and / |
| Gibberish text | Data is binary, such as an image | Decode as hex bytes, not text |
2. Padding rule
- Length mod 4 = 0: no padding needed.
- Length mod 4 = 2: add ==. Example: TQ is M, so use TQ==.
- Length mod 4 = 3: add =. Example: TWE becomes TWE=.
- Length mod 4 = 1: not a valid Base64 length.
3. Example
SGVsbG8 is 7 characters long (7 mod 4 = 3), so add one =: SGVsbG8= decodes to Hello.
Use the Base64 tool with the URL-safe and padding options to test. Background: how Base64 works.
4. Frequently asked questions
Why does my Base64 string fail to decode?expand_more
Common causes are invalid characters, a bad length, missing padding or the wrong alphabet.
Do I always need = padding?expand_more
Standard Base64 includes it. Some systems such as JWTs omit it, so add = to a multiple of 4 before decoding.
What length is invalid?expand_more
A length that leaves exactly 1 character in the last group of 4 can never be valid.
Why do I get gibberish after decoding?expand_more
The data is probably binary, such as an image, not UTF-8 text.