A Base64 encode decode tool converts data to and from Base64, a way of writing any data using only 64 plain characters: A–Z, a–z, 0–9, + and /. Base64 lets binary data or text with special characters travel safely through systems built for plain text, such as email, JSON, HTML data URLs and HTTP headers. Type text to encode it, or paste Base64 to decode it.
How to Base64 encode and decode text
- Choose a direction. Encode turns text into Base64; Decode turns Base64 back into text.
- Type or paste your input. The result appears straight away.
- Copy the result. Switch direction to check the round trip gives back what you started with.
How Base64 works
Base64 is defined in RFC 4648. The input is split into groups of 3 bytes, which is 24 bits. Each group is read as four 6-bit numbers, and each number from 0 to 63 is written as one character of the Base64 alphabet. So every 3 bytes become 4 characters, which makes Base64 text about a third larger than the original. When the input doesn't divide evenly into groups of 3, the output is padded with one or two = signs.
Examples
| Text | Base64 |
|---|---|
| f | Zg== |
| fo | Zm8= |
| foo | Zm9v |
| foobar | Zm9vYmFy |
These are test values from RFC 4648, and this tool gives exactly the same results.
URL-safe Base64
The standard alphabet uses + and /, which have special meanings in web addresses and file names. RFC 4648 also defines a URL and filename safe alphabet that uses - instead of + and _ instead of /. Tick URL-safe to use it; the = padding is left off too, as is common in URLs and tokens. The decoder accepts both alphabets, with or without padding.
Text, languages and emoji
Base64 works on bytes, not letters, so text has to be turned into bytes first. This tool uses UTF-8, the encoding used by most of the web, so Hindi, Chinese, Arabic and emoji round-trip correctly. If decoding gives an error, the Base64 may hold a file such as an image rather than text.
Base64 is not encryption
Anyone can decode Base64, so it doesn't hide or protect information. Never use it to store passwords or secrets. To create a strong password, use the password generator.
Worked example: encoding “Hello, World!”
- Leave the direction on Encode.
- Type Hello, World! in the Input box.
- The Output box shows SGVsbG8sIFdvcmxkIQ==, and the line under it reads “13 characters in, 20 characters out.”
- Press Decode. The result moves into the input and turns back into Hello, World!.
MDN uses the same text in its data URL examples and gives the same Base64, SGVsbG8sIFdvcmxkIQ==.[4] The 13 bytes fill four groups of three, which become 16 characters. The last byte is on its own, so it becomes two characters plus two = signs.
You can follow one full group by hand. The word Man is three bytes: 77, 97 and 110. In binary that is 01001101 01100001 01101110. Cut those 24 bits into four pieces of six: 010011, 010110, 000101 and 101110. Those are the numbers 19, 22, 5 and 46, which are the letters T, W, F and u in the Base64 alphabet. So Man encodes to TWFu.
Characters, bytes and other languages
The browser’s built-in btoa() function only accepts a string where every character fits in one byte. MDN warns that passing characters that take more than one byte gives an error, because that is not treated as binary data.[3] This tool avoids the problem by turning your text into UTF-8 bytes first and encoding those bytes.
That is why the counts under the result can look odd for accented letters and other scripts:
| Text | Characters in | Base64 | Characters out |
|---|---|---|---|
| Man | 3 | TWFu | 4 |
| café | 4 | Y2Fmw6k= | 8 |
| नमस्ते | 6 | 4KSo4KSu4KS44KWN4KSk4KWH | 24 |
The letter é takes two bytes in UTF-8, so café is five bytes, not four. Each Devanagari character in नमस्ते takes three bytes, so six characters become 18 bytes and then 24 Base64 characters.
When to use a Base64 encode decode tool
MDN lists email through MIME, storing complex data in XML, and putting binary data into a data: URL as common uses.[2] A data URL starts with data:, then an optional media type, then ;base64 when the data is Base64, then a comma and the data.[4] For example, data:text/plain;base64,SGVsbG8sIFdvcmxkIQ== is the text Hello, World!.[4]
This tool is built for text. To turn a picture into Base64 for a web page, use the image to Base64 converter instead.
Standard or URL-safe: which to pick
Most of the time you want the standard alphabet. MDN notes that you only need the URL-safe version when the data goes into a path segment or a query parameter of a web address, and that data URLs can use standard Base64.[2] The difference only shows when the output contains a plus sign or a slash. For example, the text <<???>> encodes to PDw/Pz8+Pg== with the standard alphabet. With URL-safe ticked, it becomes PDw_Pz8-Pg, with no padding.
If the other side expects standard Base64 with padding, leave URL-safe off, since a strict decoder may reject the missing = signs.
Line breaks and decoding errors
Base64 copied from an email or a key file is often split into lines. RFC 4648 explains that MIME limits Base64 lines to 76 characters and that PEM uses lines of 64 characters.[1] It also says software must not add line breaks unless the format that uses Base64 asks for them.[1] So this encoder gives one long line, and the decoder ignores spaces and line breaks, which lets you paste wrapped Base64 as it is.
Any other character outside the alphabet makes the decoder stop with an error. That matches RFC 4648, which says encoded data with characters outside the alphabet must be rejected unless the format says otherwise.[1] A string cut short, or Base64 that holds a file rather than text, also gives an error.
What next
Use this often? Add Base64 Encod to your Home screen.
Frequently asked questions
How do I use the Base64 encode decode tool?
Choose Encode or Decode, then type or paste your input. The result appears straight away and you can copy it with one click.
Why is Base64 longer than the original?
Every 3 bytes of input become 4 Base64 characters, so the encoded text is about a third longer.
What are the = signs at the end?
They are padding. When the input isn’t a multiple of 3 bytes, one or two = signs fill out the last group of 4 characters.
Is Base64 a form of encryption?
No. Base64 is an encoding that anyone can reverse, so it doesn’t protect data.
What is Hello, World! in Base64?
It is SGVsbG8sIFdvcmxkIQ== with the standard alphabet. The 13 characters become 20, and the two = signs pad out the last group because 13 bytes don’t divide evenly by three.
Can I decode Base64 that is split over several lines?
Yes. The decoder ignores spaces and line breaks, so you can paste Base64 from an email or a key file as it is. Any other character outside the Base64 alphabet gives an error.
Sources
Was this tool helpful?
What went wrong?
We only receive the reason you pick, never what you typed into the tool.
Thanks for your feedback.