What Base64 is
Base64 is a way to write any data using only 64 safe characters: the letters A to Z and a to z, the digits 0 to 9, and the symbols + and /. It was designed for systems that can only carry plain text, such as email and some web forms. With Base64, an image, a PDF or text in any language can travel through those systems without being damaged.
You meet Base64 in many places: email attachments, images embedded in CSS as data URLs, JSON Web Tokens, API keys, basic HTTP authentication headers and configuration files.
How to use this Base64 tool
Encode text. Type or paste text into the Text box. The Base64 appears in the right-hand box as you type. Press Copy to take it.
Decode Base64. Paste Base64 into the right-hand Base64 box. The original text appears on the left. Spaces, line breaks, missing padding and a data:...;base64, prefix are all accepted.
Options.
- URL-safe (- and _) swaps
+for-and/for_and removes the=padding. Use it for links, cookies and file names. - Split lines at 76 breaks the output into lines of 76 characters, the layout used in email (MIME).
Clear empties both boxes.
File to Base64. Choose a file of up to 25 MB. Pick Base64 only for the raw string or Data URL for a ready-to-use data:image/png;base64,... value. Then press Copy.
Base64 to file. Paste Base64 or a data URL. The tool detects common types such as PNG, JPEG, GIF, WebP, PDF and ZIP, suggests a file name, and shows a preview for images. Press Download file to save it.
How Base64 works
Base64 reads the input three bytes (24 bits) at a time. It splits those 24 bits into four groups of 6 bits. Each 6-bit group is a number from 0 to 63, and that number picks one character from the Base64 alphabet. Three bytes in, four characters out. This is why Base64 output is about one third larger than the input.
Text is first turned into bytes with UTF-8. That is why accented letters and emoji work here: café becomes 5 bytes, and those bytes are encoded. Some older tools use the browser function btoa directly, which fails on any character outside Latin-1.
Examples
| Input | Base64 | URL-safe |
|---|---|---|
M |
TQ== |
TQ |
Ma |
TWE= |
TWE |
Man |
TWFu |
TWFu |
Hello, World! |
SGVsbG8sIFdvcmxkIQ== |
SGVsbG8sIFdvcmxkIQ |
café |
Y2Fmw6k= |
Y2Fmw6k |
Zoë |
Wm/Dqw== |
Wm_Dqw |
<?> |
PD8+ |
PD8- |
The last two rows show why the URL-safe form exists. A / or + inside a link can break it, while _ and - are safe.
Tips and limits
- Base64 is not security. It hides nothing. Treat Base64 text the same as the original data.
- Check the error message. If you paste something with a character such as
*, the tool tells you which character is not valid Base64. - Binary data needs a file. If the decoded bytes are not valid UTF-8 text, the tool says so. Paste the same Base64 into Base64 to file and download it instead.
- Size grows. A 3 MB image becomes roughly 4 MB of Base64. Inline data URLs are handy for small icons but slow for large photos.
- Padding is optional when decoding. The tool adds the missing
=signs for you.
Other ways to encode Base64
Command line (macOS and Linux). echo -n 'Hello, World!' | base64 prints SGVsbG8sIFdvcmxkIQ==. Use base64 -d (or base64 -D on older macOS) to decode. Leave out -n and you encode a trailing new line too.
Windows. certutil -encode input.txt output.txt encodes a file. In PowerShell, [Convert]::ToBase64String([Text.Encoding]::UTF8.GetBytes('Hello, World!')) encodes text.
JavaScript (Node). Buffer.from('Hello, World!').toString('base64') returns SGVsbG8sIFdvcmxkIQ==, and Buffer.from('SGVsbG8=', 'base64').toString() returns Hello.
Python. base64.b64encode('Hello, World!'.encode()).decode() gives the same result. Note that base64.urlsafe_b64encode keeps the = padding, so Zoë becomes Wm_Dqw==.
Related tools
To make text safe for a web address, use the URL encoder and decoder. To see the raw bytes behind your text, try the hex to text converter or the UTF-8 encoding tool.