🔧 Error: Base64 Invalid Input

Understand why atob() fails to execute and how to clean your Base64 encoded streams.

← Dashboard

The Error Signature

The browser atob() function requires strict base64 conforming strings. If an invalid character is encountered, a DOMException is thrown.

DOMException: Failed to execute 'atob' on 'Window': 
    The string to be decoded is not correctly encoded.
    at Base64Decoder (base64-decoder.tsx:28)

Common Causes & Code Examples

1. Multi-byte Unicode Emojis in base64 string

If the base64 string concatenates an unencoded emoji or invalid character directly, decoding fails:

RGVlcE1pbmQgQW50aWdyYXZpdHkgRGV2U3VpdGUgLSBQcmVtaXVtIFV0aWxpdGllcyDwn5🚀

To fix, replace the emoji with its base64 code representations (qA):

RGVlcE1pbmQgQW50aWdyYXZpdHkgRGV2U3VpdGUgLSBQcmVtaXVtIFV0aWxpdGllcyDwn5qA

2. Missing Padding (=) Characters

Base64 strings must have a length divisible by 4. If the source encoded text ends abruptly, you may need to append one or two = padding characters to align the stream.

3. Invalid Characters (Spaces, Newlines, Tabs)

Pasting base64 text from formatted email files or text documents often carries spacing, carriage returns, or tabs. Ensure these are stripped out prior to running decode scripts.

Resolution Checklist

  • Strip spaces: Remove spaces and tabs from the input string.
  • Align padding length: Ensure the string length is a multiple of 4, adding = or == padding if required.
  • Check character set: Verify that only base64 characters (A-Z, a-z, 0-9, +, /, =) are present in the string.

Frequently Asked Questions

Solve common base64.atob decoding failures.