How to Encode and Decode Text with Base64
Select Encode for text-to-Base64 conversion or Decode for Base64-to-text conversion. Match the alphabet to the value, and use exactly 64 unique characters for a custom alphabet before running the conversion. [en-US] The article targets US readers and uses US English terminology.
Choose the right Base64 conversion
Base64 Advanced converts readable text to Base64 and can turn a Base64 value back into text. It offers a standard alphabet, a URL-safe alphabet, and a custom alphabet that meets the required format. Encode is useful when you need an encoded representation of text, while Decode is intended for recovering text from an encoded value. The choice of alphabet should follow the value you are handling, especially when a value came from another tool or process. The conversion works with text through UTF-8: encoding changes the input text into UTF-8 before Base64 conversion, and decoding interprets the resulting bytes as UTF-8 text. This makes the tool suitable for checking ordinary text conversions and for verifying a controlled round trip. It does not turn an arbitrary value into a guaranteed readable result, because the reviewed behavior covers the stated text conversion path rather than every possible input format or encoding condition. Empty input is not a usable conversion request, so prepare the value before you run the operation.
Convert text or a Base64 value
-
Enter the source text or Base64 value in the input area. Supply a nonempty value, because the operation fails when the selected input is empty.
-
Select Encode when the input is readable text and the desired output is Base64. Select Decode when the input is a Base64 value that you want interpreted as UTF-8 text. Encode is selected by default.
-
Choose the alphabet used by the value: standard Base64, URL-safe Base64, or a custom alphabet. For a custom option, enter exactly 64 unique characters. A shorter alphabet, a longer alphabet, or repeated characters does not meet that requirement.
-
Run the conversion and inspect the returned value. Encoding first converts the input to UTF-8, whereas decoding converts the decoded bytes from UTF-8 text.
-
When decoding, a value whose length is not divisible by four receives equals-sign padding when needed. If the value was produced with a custom alphabet, select that same alphabet before decoding it. A valid custom alphabet can therefore be used consistently for encoding and decoding the tested text.
Interpret the returned value
An Encode result is Base64 text, so it may look different from the readable source even when the conversion succeeded. A Decode result is interpreted as UTF-8 text, which is the relevant output form when the original input was UTF-8 text. Do not judge the alphabet by appearance alone: standard and URL-safe Base64 can use different characters, and a custom alphabet changes the representation according to its supplied character set. For a custom value, the matching valid alphabet is part of the decoding setup rather than an optional preference.
If the operation fails, confirm that the input area contains a value, the selected mode is Encode or Decode, and the alphabet choice matches the data. For a custom option, recount the characters and remove duplicates until the alphabet contains exactly 64 unique characters. Missing length padding may be added during decoding when needed, but that behavior does not correct a mismatched alphabet or empty input. The reviewed behavior does not establish handling for every malformed value or every non-UTF-8 input, so interpret results within this text-conversion scope.
Worked example
You want to verify that a short UTF-8 text value can complete a standard-alphabet round trip without changing its readable content.
Enter the text "Hello, world!", leave Encode selected, choose the standard alphabet, and run the conversion. Then select Decode and submit the returned value with the standard alphabet still selected. Compare the decoded text with the text entered at the start, rather than expecting the encoded form to resemble the source.
The first conversion returns an encoded Base64 text value, and decoding that returned value with the same standard alphabet returns UTF-8 text corresponding to the original input.
Limitations
- Empty input fails, a custom alphabet must contain exactly 64 unique characters, and decoding interprets decoded bytes as UTF-8 text. The reviewed behavior does not define results for every malformed or non-UTF-8 value.
Common errors
- A custom alphabet with a wrong length or repeated character cannot satisfy the custom-alphabet requirement. Replace it with exactly 64 unique characters, then choose that same alphabet when decoding the value.
FAQ
How do I decode a Base64 value?
To decode a Base64 value, choose Decode, keep the input nonempty, and select the alphabet that produced the value. If needed, equals-sign padding is added to reach a length divisible by four, but the alphabet still must match.
Can I use a custom Base64 alphabet?
A custom alphabet can be used when it contains exactly 64 unique characters. Keep that valid alphabet available and select it again when decoding a value that was encoded with it, so the tested text can make the same-alphabet round trip.
What happens when Base64 padding is missing?
When the encoded length is not a multiple of four, decoding adds equals-sign padding when needed. This padding behavior does not choose the mode for you, validate a custom alphabet, or supply missing input.