How to use the Repair malformed Base64 tool
- Paste the damaged value into the Base64 with uneven spacing or padding box. Select Example to load SG Vs bG8.
- Select Repair to clean up the string.
- Read the corrected string in the Result box. It is standard Base64 with = padding on one line.
- Select Copy, then pass the repaired value to the decoder that rejected the original.
What the Base64 repair tool fixes
The repair targets damage to the form of the string, where the data characters themselves are intact.
- Spaces, tabs and line breaks anywhere in the value.
- Missing = padding at the end.
- Too many = signs, or the wrong number of them.
- URL-safe characters: - is rewritten as + and _ as /.
- Both alphabets mixed in one string.
- Unused bits set in the final character, which strict decoders reject.
- A data URL prefix, which is removed.
How the repair works
The tool strips whitespace and all trailing = signs, maps the URL-safe characters to their standard equivalents, and checks that only alphabet characters remain. It then decodes with the browser's lenient decoder and encodes the bytes again, which writes correct padding and clears any unused bits.
In the last line below, the input ends in R where a canonical encoder writes Q. The two characters differ only in bits that carry no data.
SG Vs bG8 -> SGVsbG8=
SGVsbG8=== -> SGVsbG8=
PDw_Pz8-Pg -> PDw/Pz8+Pg==
SGVsbG8sIHdvcmxkIR== -> SGVsbG8sIHdvcmxkIQ==What cannot be repaired
Other faults end with The input contains invalid characters or a missing Base64 character, or pass through without the tool being able to notice.
- Characters outside both alphabets, such as quotes, backslashes, periods or percent escapes like %3D. Remove or decode them first.
- A length that leaves one character in the last group. Six bits cannot form a byte, so a character was lost.
- An = sign in the middle, which usually means two values were joined.
- Truncation. A string that was cut short usually still repairs to valid Base64, but for less data than was sent.
- Plus signs that a form decoder turned into spaces. The spaces are deleted, not restored, so put the + characters back before repairing.
- Wrong but legal characters, for example a value that was lowercased.
Where malformed Base64 comes from
Most damage happens in transit. Email clients, chat apps and PDF viewers insert line breaks and spaces when long strings are copied. URL-safe tokens end up in decoders that only know + and /. Padding is stripped by code that treats = as a delimiter, then the value is handed to a library that insists on it.
After a repair, confirm the result before you rely on it. Check the decoded size against what you expect, or compare a SHA-256 hash with Verify Base64.
Frequently asked questions
How do I fix an incorrect padding error?
Paste the string and select Repair. The tool removes whatever padding is there and writes the right amount: none, one or two = signs, depending on how many characters the final group has.
Can it recover a truncated Base64 string?
No. Missing characters mean missing bytes, and nothing in the remaining text says what they were. The tool can only make the surviving part decodable, which may hide the loss.
Does the repaired output use the URL-safe alphabet?
No. Output is always standard Base64 with + and / and padding. To get the URL-safe form, pass the repaired value through Normalize Base64 and choose URL-safe, unpadded.
Why does it say a Base64 character is missing?
After cleanup the string has a length that leaves a single character in its last group of four. One character holds only 6 bits, less than a byte, so at least one character was dropped somewhere.
Does repairing change my data?
Not when the damage was spacing, padding or alphabet. The decoded bytes are the same before and after. Cleared unused bits were never part of the data. Deleted spaces that used to be plus signs are the exception.