You copied a string out of an email, a log or a config file, pasted it into a decoder, and instead of readable text you got an error. The string looks right: the right mix of letters and digits, equals signs at the end. Yet it refuses to decode.

Almost every failure like this has one of four causes: a character that does not belong in Base64, padding in the wrong place, a copy that quietly changed the string on its way to you, or data that was never text. This guide walks through each cause with the free Base64 Text Encoder/Decoder on Ovatly.

Contents

  • Quick answer
  • Cause 1: a character outside the alphabet
  • Cause 2: padding in the wrong place
  • Cause 3: the copy changed the string
  • Cause 4: it decodes, but not to text
  • How to fix and decode, step by step
  • Worked example: repairing a broken string
  • Limitations and honest warnings
  • Common mistakes
  • FAQs
  • Conclusion

Quick answer

When a Base64 string fails to decode in the Base64 Text Encoder/Decoder, check four things in order. First, look for a character outside the Base64 alphabet, such as #, $ or a space. Second, check the padding: = signs belong only at the very end, at most two of them. Third, check the copy itself for line breaks, spaces or a lost ending. Fourth, consider that the string may be valid Base64 of binary data, in which case the tool errors because the bytes are not valid UTF-8 text. Stop suspecting missing padding: the decoder accepts strings with or without it.

Cause 1: a character outside the alphabet

Base64 is written with a fixed alphabet: the letters A to Z and a to z, the digits 0 to 9, and two extra characters, + and / in the standard form, or - and _ in the URL-safe variant. The only other character allowed is the = padding at the end. Anything else makes the string not real Base64.

The usual intruders arrive during copying: a trailing # or $ from a surrounding line, a % from a partially encoded URL, or a label copied along with the value. This one fails on a single character:

SGVsbG8sIFdvcmxkIQ==#

Remove the # and the same string decodes without complaint. When a string fails, scan it for any character that is not a letter, a digit, one of the four symbols above, or a trailing =.

Cause 2: padding in the wrong place

Base64 works in groups of four characters, and the = signs are padding that mark how many bytes were in the final partial group. A genuine string ends with one =, two ==, or no padding at all, and never has an = anywhere else.

So this string is broken even though every character in it is legal:

SGVs=bG8sIFdvcmxkIQ==

The = in the middle claims the data ended after four characters, and everything after it contradicts that. Three or more = signs at the end fail too: padding marks at most a two-character gap.

Note the flip side. Padding that has gone missing entirely is fine here: some systems strip the = signs, and this decoder accepts strings with or without padding. If your string fails, misplaced padding is a suspect; absent padding is not.

Cause 3: the copy changed the string

The most common cause of all is a copy that is not quite the string. Email clients and terminals wrap long lines, and a value pasted from a wrapped email often carries a space or a line break in the middle:

SGVsbG8sIFdv cmxkIQ==

That gap is not part of the encoding. Join the pieces with nothing between them, keeping every character and dropping only the break, and the string runs together again as SGVsbG8sIFdvcmxkIQ==.

Truncation is the sneakier version. If a copy loses whole groups of four from the end, what remains still decodes, just to less text. The string SGVsbG8sIFdvcmxk decodes cleanly to "Hello, World" with the exclamation mark silently gone, because the group that carried it never arrived. A cut that lands in the middle of a group fails outright instead. Either way, check a copied string's length against the original before trusting what it decodes to.

Cause 4: it decodes, but not to text

Some strings pass every format check and still produce an error, and this one is the tool working as designed. The decoder is a text tool: if the decoded bytes are not valid UTF-8 text, it says so instead of printing mojibake. The short string //8= shows why. It is valid Base64, and it decodes to two bytes, 0xFF 0xFF, which are not UTF-8 text at all, just part of some binary payload that was encoded for transport.

The string faithfully encodes binary data, and binary data belongs in a file tool. Images have their own route too: the Base64 Image Encoder in the Image Tools category produces a data URI for those.

How to fix and decode, step by step

  1. Open the Base64 Text Encoder/Decoder.
  2. Paste the string and scan it for characters outside the alphabet, = signs anywhere but the end, and gaps where a line break was copied.
  3. Fix what you find: delete stray characters, remove a misplaced =, join wrapped lines with nothing between them.
  4. Press Decode from Base64.
  5. Read the result, or read the validation error. If the error survives a clean string, the bytes are probably not UTF-8 text, and the data belongs in a file tool.
  6. Copy the result. If the text looks shorter than expected, compare it with the source before relying on it.

Worked example: repairing a broken string

Take the string from Cause 2, SGVs=bG8sIFdvcmxkIQ==. Decoding it produces a validation error, because the = in the middle breaks the format. One scan finds the defect: every character belongs to the alphabet, the length is a multiple of four, and the only problem is padding in the wrong place.

Delete that one character and the string becomes SGVsbG8sIFdvcmxkIQ==, twenty characters ending in proper == padding. Decode it again and out comes "Hello, World!", the classic test string. The whole repair was removing a single misplaced character, which is typical.

Limitations and honest warnings

This tool encodes and decodes text. It will not decode binary data into anything readable: binary belongs in a file tool, and images belong in the Base64 Image Encoder in the Image Tools category.

Decoding also proves less than people assume. A string that decodes to readable text proves the copy was well formed; it does not prove the copy was complete, as the truncation case shows. And the standing warning bears repeating: Base64 is an encoding, not encryption, so a failed decode is a formatting problem, never a locked one.

Common mistakes

  • Blaming missing padding. This decoder accepts strings with or without padding, so a stripped = is rarely the cause. Look for misplaced padding or stray characters instead.
  • Trusting a decode that looks almost right. A truncated string can decode without error to text quietly missing its ending. Check the result, not just the absence of an error.
  • Trying to read binary as text. An error about UTF-8 means the payload was never text. Route it to a file tool rather than hunting for a character to fix.
  • Treating the URL-safe variant as damage. The - and _ characters are the URL-safe alphabet, accepted as they are.

FAQs

Why does the tool say my string is not valid Base64? Something in the string breaks the format: a character outside the Base64 alphabet, an = sign in the middle, or a length that does not line up with the groups of four characters. Compare the copy character by character with the original.

My string lost its = signs. Is that the problem? Almost certainly not. The decoder accepts Base64 with or without padding, so a string stripped of its = signs still decodes. Look for other damage first: stray characters, breaks, or a missing ending.

The string decodes but the tool still shows an error. Why? The Base64 is fine, but the bytes behind it are not valid UTF-8 text. That happens with binary data such as images or compressed files. The tool reports it instead of printing mojibake, and binary data belongs in a file tool.

Can a damaged string decode without any error? Yes. If a copy loses whole groups of four characters from the end, the rest still decodes cleanly, just to shorter text. A string that decodes is not proof the copy is complete, so check the result against what you expect.

Does a - or _ in the string mean it is damaged? No. Those characters mark the URL-safe variant of Base64, which swaps two standard characters so the text can sit inside a web address. The decoder accepts both variants as they are.

Conclusion

A Base64 string that will not decode is almost always damaged in one small way: a character that does not belong, padding in the middle, a break or a lost ending, or a payload that was binary all along. Run the four checks, repair the copy, and the Base64 Text Encoder/Decoder will do the rest. The companion skill is recognising these strings before you paste them, covered in How to Spot a Base64 String in Logs and Data. For more tools like these, see the Developer Tools guide archive.