How base64 decoding works
Base64 writes every 3 bytes as 4 characters from an alphabet of 64: A–Z, a–z, 0–9 and two more. Decoding reverses this. Each character stands for 6 bits, four characters give back three bytes, and the padding = at the end tells how many bytes the last group holds.
Examples
SGVsbG8=decodes toHello.w6TDtsO8decodes toäöü: three characters, six bytes of UTF-8.AAEC/w==is binary data, the four bytes00 01 02 ff.
Text or binary?
Base64 can carry anything: text, an image, a key, a compressed file. When the decoded bytes are valid UTF-8 without control characters, the decoder shows them as text. Anything else, such as a PNG image or a random key, is shown as hexadecimal bytes, so that nothing invisible ends up in your clipboard.
Why a string does not decode
Usually the input contains a character from outside the alphabet – a quote, a backslash, or a percent sign left over from URL encoding – or it was cut off: no valid base64 string has a length of 4n+1 characters. The decoder names the first problem it finds. Remember that base64 is an encoding, not encryption: anyone can decode it.
To go the other way, use the base64 encoder. A value of the form xxxxx.yyyyy.zzzzz is usually a JSON Web Token; the JWT decoder splits it and formats its header and payload.