Fix Base64 Decoding Issues & Character Encoding Errors
Resolve Base64 decoding failures, padding errors, invalid characters, and UTF-8 encoding issues. Step-by-step solutions with code examples.
Base64 encoding and decoding errors are among the most common issues developers face when working with APIs, authentication tokens, and data serialization. This guide covers every major Base64 failure mode and shows you exactly how to fix each one using our free online tool.
Common errors covered
Invalid Base64 padding (missing = signs)
Error: Incorrect padding
base64.binascii.Error: Invalid base64-encoded string: number of data characters (13) cannot be 1 more than a multiple of 4
Base64 strings must have a length that is a multiple of 4. Missing = padding characters at the end cause decoding to fail. This commonly happens when URLs strip trailing = signs.
Step-by-step fix
- 1 Paste your Base64 string into the Base64 Encoder/Decoder.
- 2 Check the string length - if it is not a multiple of 4, padding is missing.
-
3
Add
=characters to the end until the length is divisible by 4. - 4 Click Decode - the output should now be valid.
SGVsbG8gV29ybGQ
SGVsbG8gV29ybGQ=
Invalid characters in Base64 string
InvalidCharacterError: Failed to execute 'atob' on 'Window': The string to be decoded contains characters outside of the Latin1 range.
Standard Base64 uses only A-Z, a-z, 0-9, +, /, and =. URL-safe Base64 replaces + with - and / with _. Mixing these formats causes decoding failures.
Step-by-step fix
-
1
Check if your string contains
-or_(URL-safe) vs+or/(standard). -
2
Replace
-with+and_with/for standard decoding. - 3 Or use our tool's URL-safe mode toggle to handle this automatically.
- 4 Verify no whitespace or newlines are embedded in the string.
SGVsbG8-V29ybGQ_
SGVsbG8+V29ybGQ/
UTF-8 characters corrupted after Base64 round-trip
Output contains garbled text instead of accented characters
When encoding text with non-ASCII characters (accents, emoji, CJK), you must encode to UTF-8 bytes first, then Base64-encode those bytes. Decoding must reverse this: Base64-decode then interpret as UTF-8.
Step-by-step fix
- 1 Open the Base64 tool and paste your encoded string.
- 2 Make sure the UTF-8 character set option is selected.
- 3 Click Decode - the tool automatically handles UTF-8 interpretation.
- 4 If encoding: paste your Unicode text, ensure UTF-8 is selected, then click Encode.
# Python mistake
import base64
result = base64.b64decode('w6nDqMOg').decode('ascii') # Wrong charset
# Python fix
import base64
result = base64.b64decode('w6nDqMOg').decode('utf-8') # Correct
Prevention Tips
- Always check Base64 string length is a multiple of 4 before decoding.
-
Use URL-safe Base64 (
base64url) for any string that passes through URLs. - Explicitly set UTF-8 encoding when working with non-ASCII text.
-
Validate Base64 input with a regex before processing:
/^[A-Za-z0-9+/]*={0,2}$/
Frequently Asked Questions
Why does my Base64 string have + and / but the URL version has - and _?
There are two Base64 alphabets. Standard uses +/ while URL-safe uses -_ because + and / have special meaning in URLs. Our tool auto-detects which format you are using.
Is it safe to paste sensitive data into the Base64 tool?
Yes. Our Base64 encoder/decoder runs entirely in your browser. No data is sent to any server. You can verify this by checking the Network tab in DevTools.
How do I Base64-encode a file?
Use our Image to Base64 tool for images, or use the Base64 tool file upload option for any binary file.
Related Error Guides
Related Tools
Still stuck? Try our free tools
All tools run in your browser, no signup required.