Upload a file
  1. base64hub
  2. Text tools
  3. Base64 repair

Repair Base64

Paste Base64 that a decoder rejects. The repair undoes the usual damage from JSON, URLs, email and copy-paste, lists each change it made, and gives you a clean string in the format you choose.

Free no sign-up, no limits Local nothing uploaded Fixes quotes, escapes, %3D, spaces, padding Updated Oct 27, 2026

What was fixed

Processed in your browser. This page cannot send your data anywhere – how we know

How to repair a Base64 string

  1. Paste the broken value into Base64 to check. Leave the surrounding quotes, prefixes and line breaks in; the tool needs them to understand what happened.
  2. Choose the Output format: standard padded, standard without padding, URL-safe with or without padding, MIME (76-character lines, CRLF) or PEM (64-character lines).
  3. Read What was fixed. Each repair is listed separately, so you can tell harmless cleanup from changes that might have cost data.
  4. Copy or download the result, press Validate the result to run a full check on it, or Download decoded file to save the bytes.

What the repair fixes

You pastedWhat happenedRepaired
"SGVsbG8gd29ybGQ\u003d"JSON string with an escaped =SGVsbG8gd29ybGQ=
SGVsbG8%3Dpercent-encoded in a URLSGVsbG8=
PDw/Pz8 Pg==+ became a space in a query stringPDw/Pz8+Pg==
PDw_Pz8-PgURL-safe and unpaddedPDw/Pz8+Pg==
SGVsbG8gd29ybGQpadding strippedSGVsbG8gd29ybGQ=
SGVsbG8=V29ybGQ=two values concatenatedSGVsbG9Xb3JsZA== (HelloWorld)
SGVsbG9=non-zero unused bitsSGVsbG8=
Authorization: Basic …copied with the header namethe token alone

It also removes data:…;base64, prefixes and PEM -----BEGIN …----- lines, unwraps plain quotes, turns literal \n and \/ back into characters (PHP’s json_encode writes \/ by default), strips whitespace and line breaks, unifies mixed +/ and -_ alphabets, and corrects the number of =.

For concatenated values, each piece is decoded separately and the bytes are joined, which is correct when a program appended padded chunks one after another. Deleting the inner = instead would shift every following bit and produce garbage.

Repairs that may hide a real problem

Two fixes are reported as warnings because they guess:

  • Illegal characters removed. If the string contained *, # or a stray Unicode character, the tool deletes it and lists which characters went. A character in the middle of the data might have been a real symbol that got mangled, in which case the decoded bytes will still be wrong from that point on.
  • A dangling character dropped. A length with remainder 1 cannot be produced by any encoder, so one character is extra or the string was cut off. The tool drops the last character so the rest decodes, but if the value was truncated, the end of the file is gone. A truncated image usually shows a gray or missing bottom; a truncated ZIP will not open.

When either warning appears, try to get the original again: an untruncated log line, a full API response, or the attachment straight from the mail server.

Why a naive fix is not enough

The common snippet for “fixing” Base64 handles whitespace, URL-safe characters and padding:

def fix_base64(s):
    s = "".join(s.split())
    s = s.replace("-", "+").replace("_", "/").rstrip("=")
    return s + "=" * (-len(s) % 4)

It repairs SGVsbG8gd29ybGQ and PDw_Pz8-Pg correctly. Feed it PDw/Pz8 Pg==, where a + turned into a space, and it removes the space, leaving 9 data characters. Python then fails with “number of data characters (9) cannot be 1 more than a multiple of 4”. JSON escapes, %3D, glued chunks and prefixes slip through the same way. The repair here tries each fix in turn and only applies the space-to-plus change when the result has a valid length.

The safer long-term fix is at the source: percent-encode Base64 before putting it in a URL, or use Base64URL, and keep it out of places that rewrap or escape text. If the repaired string still decodes to something unexpected, the Base64 errors guide covers garbled text and double encoding, and the Base64 decoder shows the bytes.

FAQ

How do I fix "Incorrect padding" in Python?

Add = until the length is a multiple of 4: s + "=" * (-len(s) % 4). If the error persists, the string has other damage such as spaces or escapes; paste it here to see what else is wrong.

Why are there spaces in my Base64?

Usually a + passed through a URL query string or HTML form without percent-encoding, and the receiving side turned it into a space. The repair puts the + back when that gives a valid length.

Can a repair lose data?

Removing illegal characters or a dangling final character can, and the fix list says so. If the tool reports that it dropped a character because the data was cut off, get a complete copy of the original instead of trusting the result.

What does \u003d mean at the end of my Base64?

It is a JSON escape for =. Some JSON libraries, Gson among them, escape = for HTML safety. A JSON parser turns it back automatically; the repair does the same when you paste the raw text.