What Base64 encoding does
Base64 turns any data, text or binary, into a string made of only 64 safe characters: A-Z, a-z, 0-9, + and /, with = used as padding. Such a string can travel through systems that only handle plain text, such as email, JSON, XML, HTML attributes, URLs and HTTP headers. This page encodes text as UTF-8 first, so accents, Arabic, Chinese and emoji work correctly, and then converts the bytes. You can also encode a file of any type.
Example
Hello, World!
encodes to:
SGVsbG8sIFdvcmxkIQ==
and the text café (the é takes two bytes in UTF-8) becomes Y2Fmw6k=. To see exactly how the bits are regrouped, open the text to Base64 converter, which shows every step.
Options
- Line breaks. None (one long line, best for APIs and data URIs), every 76 characters (MIME, used in email, RFC 2045) or every 64 characters (PEM, used in certificates and keys).
- Remove padding. Drops the trailing
=signs. Some systems, such as JWT, expect no padding. - URL-safe alphabet. Uses
-and_in place of+and/. See the Base64URL encoder for details. - Encode line by line. Every line is encoded separately and the lines are kept, useful for lists of values.
- Encode a file. Choose a file (up to 20 MB) and its bytes are encoded exactly as they are. For images, the image to Base64 converter also gives a ready data URI.
How much bigger does Base64 get?
Every 3 bytes become 4 characters, so the output is about 33% larger than the input (plus a few percent more with line breaks). Base64 is a way to carry data safely, not a way to compress it.
Encode in code
// JavaScript (browser)
btoa(unescape(encodeURIComponent('café'))); // "Y2Fmw6k="
// Node.js
Buffer.from('café', 'utf8').toString('base64');
// PHP
base64_encode('café');
# Python
import base64
base64.b64encode('café'.encode('utf-8')).decode()
# Shell
printf 'café' | base64
Common mistakes
- Treating Base64 as encryption. Anyone can decode it. Do not use it to hide passwords or tokens.
- Calling
btoa()on Unicode text. It throws an error for characters above U+00FF. Convert to UTF-8 bytes first, as this tool does. - Adding a trailing newline.
echo hello | base64encodes the newline too. Useprintforecho -n.
Privacy
The encoding runs in your browser. Your text and files are not uploaded, stored or logged.
Next: the Base64 decoder reverses the result. The guide What is Base64? explains the alphabet, padding and variants. For links, see the URL encoder.