Why one or two padding characters appear
Each Base64 data character represents six bits. Three bytes supply 24 bits, which fit four characters exactly. With one remaining byte, two data characters are followed by ==. With two remaining bytes, three data characters are followed by =. Padding fills the output group; it does not add bytes to the decoded result.
Can missing padding be restored?
When the receiving format permits unpadded input, remove whitespace and inspect the length of the data characters. A remainder of 2 when divided by 4 needs ==; a remainder of 3 needs =; a remainder of 0 needs no padding. A remainder of 1 cannot be repaired by adding padding. It indicates malformed or truncated data.
When should you keep =?
Keep the encoder’s padding unless the target protocol explicitly permits or requires its omission. Standard Base64 and a particular Base64URL-based protocol may have different requirements. If a downstream API reports incorrect padding, first check its specification and whether any characters were lost during copying. Do not repeatedly add = until an error disappears.
Verified experiments
| Input / operation | Expected result | Browser result |
|---|---|---|
f | Zg== | Not run |
fo | Zm8= | Not run |
foo | Zm9v | Not run |
= | PQ== | Not run |
Zg | f | Not run |
Zg=Base64 → UTF-8 | Error (expected rejection) | Not run |
ABase64 → UTF-8 | Error (expected rejection) | Not run |
What the results mean
f, fo and foo leave one, two and zero bytes in the final group. The literal input = becomes PQ==: the original equals sign and output padding serve different purposes. Zg is accepted here; partially padded Zg= and length-one A are rejected.
How to reproduce
Encode f, fo, foo and = separately, preserving exact input and no trailing newline. Decode Zg, Zg= and A individually. This table describes Decodex acceptance rules; a receiving API may require padding.
Verification method
These fixed, public fixtures run against the same file codec and character codecs used by the converter. The JavaScript cases additionally check browser-native btoa, TextEncoder, URLSearchParams and SHA-256. Expected outputs are published before any script runs; the button shows actual results in your browser. No input is uploaded.
JavaScript · guide-cases.js · JavaScript · file-codec.js
Scope and limitations
Checked on 2026-10-21. This is a correctness check with small fixtures and one 100,000-character case, not a speed benchmark or a guarantee for every file. The four-byte file is synthetic binary data, not a PNG or PDF. SHA-256 equality checks byte preservation; it does not establish that a file is safe to open. Results can depend on browser support.
References
Choose a guide for your problem
How to fix Base64 decoding errors
Diagnose which layer failed: Base64 syntax, text interpretation, or file restoration. This page is the diagnostic starting point; the other guides explain each layer in depth.
Base64 encoding Korean text and emoji with UTF-8
Compare identical text encoded as different bytes. Select a character encoding from knowledge of the source, not from the language of the website.
Base64 vs Base64URL: differences, padding and decoding examples
Follow a Base64 value through a query string. This guide isolates transport damage from errors in the original value.
JavaScript Base64 with Unicode: fix btoa() errors using UTF-8
Implement Unicode conversion in JavaScript and inspect cases where a successful btoa call still gives the wrong byte encoding.