Skip to content

Base64 Encoder

Updated:

Enter text to convert it to a Base64 string. The encoder works with ASCII and other single-byte characters; characters such as emoji may cause an encoding error.

Text to Base64 Encoding Tool

Input Fields
If enabled, the result will update automatically when you change any value.

Base64 Encoder Formula

Formula
\[ L=4\left\lceil\frac{n}{3}\right\rceil \]

Where:

  • \(n\) — the number of input bytes.
  • \(L\) — the number of characters in the Base64 output, including any padding.

Base64 divides input into three-byte groups and represents each group with four characters. If the final group has fewer than three bytes, the output uses one or two = characters as padding.

Base64 Encoder – Calculation Example

Example: enter the calculator’s default text, Hello world!. Its 12 supported characters are encoded as 12 bytes, forming four complete three-byte groups.

\[ \operatorname{Base64}(\text{Hello world!})=\text{SGVsbG8gd29ybGQh} \]

\[ L=4\left\lceil\frac{12}{3}\right\rceil=16 \]

Result: SGVsbG8gd29ybGQh, a 16-character Base64 string with no padding.

How to use the Base64 Encoder

  1. Enter or paste your input in Text to Encode. You can leave Hello world! in place to check the example above.
  2. Read the encoded string in Base64 Output.
  3. Use the output’s copy option if you need to paste the string into another application. Keep any trailing = characters: they are part of the encoded value.

If Base64 Output shows “Encoding failed,” the text contains a character this encoder cannot process directly. See the character limitation below before using the result in an application.

What Base64 encoding does

Base64 is a way to represent bytes using a restricted set of printable characters: uppercase and lowercase letters, digits, +, and /. It is useful when a format or system needs text rather than raw bytes. The result may also end in = or ==, depending on the input length.

The encoded string is not a different meaning for your text; it is another representation of the input bytes. Someone can recover those bytes with a Base64 Decoder. Base64 therefore provides neither encryption nor secrecy. Avoid treating an encoded password, token, or other sensitive value as protected merely because it is difficult to read at a glance.

Base64 output is usually longer than its input: every three bytes become four characters, an increase of about one-third before any surrounding formatting is added. For a short input, padding can make the proportional increase larger. The formula above gives the output length for an input of \(n\) bytes; it does not tell you what the encoded characters will be. Those characters depend on the actual byte values.

Character support and practical limits

This calculator uses the browser’s btoa() function. It accepts text whose individual character codes fit in one byte, from 0 to 255. Ordinary English letters, numbers, spaces, and punctuation work. Many other characters, including emoji and most non-Latin scripts, cause “Encoding failed.” This page does not first convert the text to UTF-8.

That distinction matters for accented characters too. A character such as é can be accepted as a single byte here, but its output is not the Base64 encoding of the character’s UTF-8 bytes. If a receiving system expects UTF-8, use an encoder that explicitly converts text to UTF-8 before applying Base64.

Despite Base64’s common use for files, this calculator has a text field, not a file upload. Pasting the visible contents of an image or another binary file will not reliably encode that file. Use a file-aware tool when you need Base64 for a file.

Base64 also serves a different purpose from URL encoding. If you need to escape characters for placement in a URL, use a URL Encoder. Standard Base64 can itself contain +, /, and =, which may need special handling in a URL. To inspect character values rather than encode the whole input as Base64, try the ASCII Converter.

Frequently Asked Questions

How can I encode text to Base64 by hand?

Convert each input byte to eight binary digits, then split the combined bits into groups of six. Read each six-bit group as a number from 0 to 63 and look it up in the standard Base64 alphabet. For example, the bytes for “Man” produce the six-bit values 19, 22, 5, and 46, which map to “TWFu.” For an incomplete final group, add zero bits before looking up its last character.

Why does another Base64 encoder give a different result for é?

The two encoders may start with different bytes. This calculator treats é as one byte with the value 233, producing “6Q==”. A UTF-8 encoder first represents é as two bytes, 195 and 169, producing “w6k=”. Neither result is inherently wrong, but the decoder must use the same character encoding as the encoder to recover the intended text.

What happens if I encode an empty string?

An empty input encodes to an empty Base64 string, not an equals sign or a special marker. There are no bytes to convert and no final group that needs padding. This can matter when sending data to an API: an empty encoded value may be valid, but the receiving application might treat an omitted field differently from a field containing an empty string.

Is Base64 the same as Base64URL?

No. Base64URL replaces the standard alphabet’s “+” and “/” with “-” and “_”; it also commonly omits trailing padding. Those changes make it easier to place encoded data in URL components and formats such as JWTs. This calculator produces standard Base64, so check whether the receiving service specifically requests Base64URL before copying its output.

Can I remove the trailing equals signs from a Base64 string?

Only if the receiving format explicitly permits unpadded Base64. Some decoders can infer the missing padding from the string length, while others require it. Removing “=” does not change the original data, but it can make the string invalid for a strict decoder. Keep the padding when copying this calculator’s result unless your destination specifies otherwise.

Does capitalization or whitespace matter in Base64?

Capitalization matters: uppercase and lowercase letters represent different values, so changing a letter’s case can change the decoded bytes. Whitespace is different. Some decoders ignore line breaks inserted into long Base64 strings, while strict decoders reject them. For the most reliable copy-and-paste result, preserve every character exactly and avoid adding spaces or line breaks.

Leave a Reply

Your email address will not be published. Required fields are marked *

2 thoughts on “Base64 Encoder”