Decodex

DECODEX · BASE64

Base64 padding explained: what = and == mean

Work out padding from byte groups and check malformed endings. Character encoding and URL transport are covered separately.

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 / operationExpected resultBrowser result
fZg==Not run
foZm8=Not run
fooZm9vNot run
=PQ==Not run
ZgfNot run
Zg=
Base64 → UTF-8
Error (expected rejection)Not run
A
Base64 → 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.

Base64 →

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

More online tools

Convert images, test your keyboard, and use other handy tools in your browser.

Explore Altomono tools