EthicalFusion

Base64 Encoder

Encode any text to Base64 (Unicode-safe).

Was this tool helpful?

Thanks for the feedback!

The Base64 Encoder converts any text you type or paste into a Base64 string. It first turns the text into UTF-8 bytes and then encodes those bytes, which is what "Unicode-safe" means here: Hindi, Bengali, emoji and the ₹ sign all encode correctly, while the browser's bare btoa() function throws an error on them.

The 3-bytes-to-4-characters rule

Base64 (RFC 4648) reads the input three bytes at a time, splits those 24 bits into four 6-bit numbers, and writes each number as one character from the alphabet A–Z, a–z, 0–9, +, /. Take the word "Man":

  • M = 77 = 01001101, a = 97 = 01100001, n = 110 = 01101110
  • Regrouped into sixes: 010011 010110 000101 101110 = 19, 22, 5, 46
  • Characters 19, 22, 5 and 46 of the alphabet are T, W, F and u, so "Man" becomes TWFu

When the last group is short, = fills the gap: "Ma" encodes to TWE= and "M" to TQ==. The output length is always 4 × ⌈bytes ÷ 3⌉, which makes Base64 about 33% larger than the original. "Hello, World!" is 13 bytes and becomes the 20-character SGVsbG8sIFdvcmxkIQ==.

Details that change the output

  • Every character counts. The input is not trimmed, so a trailing line break is encoded too: "Hello" gives SGVsbG8= but "Hello" plus Enter gives SGVsbG8K. This is the usual reason two encoders disagree.
  • Non-English text grows fast. Most Devanagari letters take three bytes in UTF-8, so the six-character word नमस्ते (18 bytes) becomes a 24-character string, 4KSo4KSu4KS44KWN4KSk4KWH.
  • Standard alphabet, one line. The result uses +, / and padding, with no line wrapping. For a URL, either percent-encode it with the URL Encoder or convert it to Base64URL by swapping + for -, / for _ and dropping the =.

Where encoded text is needed

HTTP Basic authentication. Encode username:password and send it as Authorization: Basic dXNlcjpwYXNz (that string is "user:pass"). Only do this over HTTPS, because the header can be decoded by anyone who sees it.

Kubernetes Secrets and config files. Values under a Secret's data: key must be Base64. Because the tool encodes exactly what is in the box, make sure there is no trailing newline, the same mistake people make with echo instead of echo -n on the command line.

Embedding text in JSON, XML or data URIs. Base64 lets you carry text with quotes, line breaks or unusual symbols through systems that would otherwise mangle them, for example data:text/plain;base64,SGVsbG8=.

What this encoder is not for

It encodes text only; to turn a picture into a data URI, use the Image to Base64 Converter. It also provides no secrecy, since decoding needs no key. Encoding happens in your browser, so the text you enter stays on your device.

Frequently asked questions

Why is the Base64 output longer than my text?
Base64 uses four characters for every three bytes, so output is about a third larger. Non-English letters take two to four bytes each in UTF-8, which adds more.
Why does another encoder give me a different result?
Usually one of the inputs had a trailing space or line break, or the other tool encoded UTF-16 instead of UTF-8. Line wrapping every 76 characters is another harmless difference.
Can I encode a file or image here?
No, this page encodes typed or pasted text. Use the Image to Base64 Converter for pictures.
Is it safe to store passwords as Base64?
No. Anyone can decode Base64 instantly. Passwords should be stored as a slow hash such as bcrypt.
How do I get URL-safe Base64?
Replace + with -, / with _, and remove the trailing = signs. That is the Base64URL variant from RFC 4648 used in JWTs.

Related tools

Embed this tool on your site

Paste it into any blog or website. Free, with a credit link.