How to encode and decode UTF-8 text with Base64

Convert text to Base64, decode standard or URL-safe input, and check padding, whitespace, and character encoding in TinyToolbox.

Open the tool

A configuration field asks for a Base64 value, or a test fixture includes a short string that looks like Y2Fmw6k=. The characters can look cryptic even though the value simply represents a sequence of bytes. To work with the data, decide which direction you need. Encoding starts with readable text and produces Base64 characters. Decoding starts with those characters and tries to recover readable text.

TinyToolbox Base64 Encoder and Decoder encodes text as UTF-8 bytes before converting it to standard Base64. It decodes standard and URL-safe Base64 into UTF-8 text. The form runs in your browser. Use it for text examples and inspect the result before pasting it into a configuration field or passing it to another program.

Check what the receiving field expects

Base64 represents bytes using printable characters. A receiver might use it to carry a short text value through a system that expects a restricted alphabet. Other systems may ask for ordinary text, a URL component, or a complete data URI. These formats can all look similar in a settings panel, but they expect different input.

If documentation says a field holds a Base64-encoded UTF-8 string, encode the original words once and supply the result. If it says to paste a JSON object, send the JSON with its braces and quotes. If it asks for a URL component, URL Encoder and Decoder handles percent encoding. A value such as %20 belongs to that convention, whereas IA== is standard Base64 for a single space.

Base64 is reversible by design. Anyone who has a Base64 value can try decoding it. Treat sensitive material the same way before and after encoding. For a debugging example, substitute a short made-up value before conversion. That lets another person reproduce the formatting problem without receiving the original content.

Encode a text value in TinyToolbox

  1. Open Base64 Encoder and Decoder.
  2. Paste or type the original text into Input text.
  3. Choose Encode under Operation.
  4. Select Run tool and review Result.
  5. Select Copy result when the value is ready to use.

Start with Hello. The result should be SGVsbG8=. Next try café, which becomes Y2Fmw6k=. The accented character shows why the text encoding matters. It occupies more than one byte in UTF-8, even though it appears as one character. The tool encodes the bytes produced from the original text, so the result reflects that difference.

The input form accepts up to one million characters. For a large document, try a small representative sample first. If you need to encode a whole file as bytes, use a file-based conversion suited to that input. Copying what you see in a text editor can involve a different character encoding or line-ending convention from the original file.

Check the result before saving it to a settings field. The input Hello and the input Hello followed by a newline are different strings. A clipboard selection can include that last newline without making it obvious. Use a round trip to see whether you copied every character you intended.

Decode and check a round trip

Copy the result you just encoded. Replace the input with that Base64 string and choose Decode. Run the tool again. SGVsbG8= should return Hello, and Y2Fmw6k= should return café. Compare punctuation, capitalization, and spaces with the original. If you can see both copies in a text editor, turn on visible whitespace to check for blank lines or spaces at the end.

When debugging a value someone else supplied, begin with the Base64 portion alone. Remove surrounding quote marks, a label such as Encoded value, or any Markdown fences included in the message. If the source is a JSON object, parse it and copy the value inside the field. A complete JSON object contains punctuation that belongs to JSON outside the Base64 value.

If the decoded result itself looks like another short Base64 string, check what the sender did before decoding it a second time. It might represent text that was encoded twice, or the original text might legitimately consist of those characters. Try asking what the intended value should look like and compare with the exact round-trip example. Repeated transformations can obscure which step introduced the difference.

Understand padding and the URL-safe alphabet

Standard Base64 uses letters, digits, plus, and slash for its alphabet. Its output can end with one or two equal signs. Those trailing equal signs are padding. The conversion works on groups of three bytes, and padding marks a short last group.

Original text Standard Base64
M TQ==
Ma TWE=
Man TWFu

You can paste each result into Decode to check how the padding changes. Keep the padding when copying standard output unless the receiving format explicitly tells you to omit it. A producer can choose to omit padding in certain protocols, and browser decoding can accept some unpadded values. A receiving system may require a particular spelling even if two strings decode to the same bytes.

URL-safe Base64 uses a hyphen in place of plus and an underscore in place of slash. The decoder accepts those substitutions. For example, the standard Base64 4KC/ and URL-safe 4KC_ both decode to ࠿, a Unicode character. The Encode operation produces the standard alphabet. If you need URL-safe output, follow the destination’s instructions on alphabet substitutions and padding.

Some transport layers have their own escaping rules. In a form-encoded value, a literal plus sign can be interpreted as a space if the sender did not encode it correctly. If a value decodes correctly before transmission and fails afterward, compare the exact value on both sides. Check whether the application expects standard Base64, URL-safe Base64, or a percent-encoded representation of the Base64 string as part of a URL.

Diagnose errors by checking the input in layers

First check for transport markup. A prefix such as data:text/plain;base64, is part of a data URI, not the encoded text itself. For a text data URI, Data URI Decoder can handle the prefix and report the media type. If a simple Base64 input contains a prefix you copied from a field label, remove the label and keep only the value.

Next inspect the alphabet and ending. Compare the string with the source, especially if it was copied across several wrapped lines. Look for a missing character, an unexpected quote, or padding in the middle. Newlines added for display may be acceptable when decoding, but text added between fragments can invalidate the input. If you have several separately encoded strings, decode them separately unless their format tells you to join them before decoding.

Finally, check what the bytes represent. The tool uses strict UTF-8 decoding. Base64 can also represent an image, archive, or text written in a different character encoding. A string can be well-formed Base64 and still produce a UTF-8 error. For example, the Base64 value /w== represents the byte FF, which cannot stand alone as UTF-8 text. Look at the expected file or text format before trying to change the Base64 itself.

If text decodes with an unexpected extra space or blank line, inspect the original bytes or run a small test using text with and without the extra whitespace. Differences inside the string are meaningful. Avoid trimming the original when the receiving application treats whitespace as part of a value, a record, or a fixture.

Work through a configuration example

Suppose a local test expects a Base64-encoded greeting. The required decoded value is Bonjour, café with no trailing newline. Start by typing the greeting into Input text. Encode it and copy the result into a temporary note. Then decode that same value and verify that the comma, space, and accented letter are present.

Put the tested value into the configuration field using the field’s normal quoting rules. If it is inside a JSON object, the Base64 output should generally be the contents of a quoted JSON string. Run the test and compare the value the program receives with the output you copied. If it fails, isolate whether the program saw a different string or expected a different encoding.

If you need to show the example to a colleague, include both the original greeting and its Base64 representation so they can check the direction of the conversion. Mention whether the original ends with a newline. A short fixture with known characters makes a better test than an opaque production value and helps distinguish formatting problems from differences in the actual data.

Verify the final value at the destination

Before handing off the result, confirm the expected alphabet, padding, and text encoding. Decode an encoded value once to verify the original text, or compare decoded text against a known source where you have one. If the value is part of a larger JSON fixture, use JSON Formatter & Viewer on the fixture to check its structure separately.

Run the receiving application’s normal validation or import step when available. TinyToolbox can confirm that your example converts between Base64 and readable UTF-8, while the recipient determines whether the value belongs in that field and satisfies its format. Keep a small verified sample so the same conversion can be reproduced when the configuration changes.

Count UTF-8 bytes before predicting the encoded length

Try encoding café with the composed letter é in Base64 Encoder and Decoder. The text contains four visible letters but uses five UTF-8 bytes. The first three letters use one byte each, and é uses two. Standard Base64 represents these five bytes as Y2Fmw6k=. Decode that result and compare it with the original. The trailing equal sign accounts for the final group containing two bytes.

Now compare it with cafe, without the accent. That text uses four bytes and encodes to Y2FmZQ==. Both outputs contain eight characters, but the one with two equal signs represents one fewer byte. If a receiving system lists a byte limit, use the decoded bytes or the source before encoding to check it. The two encoded strings have the same length even though the underlying text differs in both content and size.

Try a third sample using an ordinary e followed by a combining acute accent. It may look like the first word in your browser. It uses six bytes in UTF-8 and gives Y2FmZcyB with no trailing padding. Decoding returns the same sequence that was supplied, including the combining mark. Use UTF-8 Byte Inspector to verify the underlying bytes if a comparison tool reports that the two apparently identical words differ.

Suppose your test requires exactly one representation of the accented word. Record the expected UTF-8 bytes or code points in your fixture, as well as the Base64 text. This helps a reviewer reproduce the same sample even if a source editor or copy operation normalizes characters. If the destination checks values after applying its own normalization, confirm that behavior independently. Base64 preserves the bytes it represents, and the visible result alone may hide the difference between two source sequences.

When handing the value to another application, preserve its exact alphabet and trailing padding according to that application’s instructions. Decode the value as received and compare it with the expected fixture. This checks the transport separately from the original encoding.