How to encode and decode Base64
- Choose Encode to Base64 to turn text or a file into Base64, or Decode from Base64 to turn it back.
- Type or paste into the left box. To encode a file, press Open a file or drag a file onto the box; the file can be up to 10 MB. The result updates as you type.
- When decoding, text appears as text. If the Base64 holds a picture, the picture is shown. Anything else is shown as its first bytes in hexadecimal, and you can download it.
- Press Copy result or Download. Use result as input flips the direction so you can check a round trip.
What Base64 is, and what it is not
Computers store everything as bytes, but many places that carry data, such as email, JSON files, web addresses and configuration files, are built for text and can mangle other bytes. Base64 solves this by writing any data using only 64 safe characters: the letters A to Z and a to z, the digits 0 to 9, and two symbols (+ and / in the standard form). Three bytes of data become four characters, and one or two = signs at the end pad the last group when the data does not divide evenly by three.
Base64 is an encoding, not encryption. There is no key and no secret: anybody can decode it in a second, with this page or with built-in tools. Passwords, tokens and private data are not protected by being in Base64. Treat a Base64 string as if it were the readable data itself.
The encoding options
- URL-safe writes - and _ instead of + and /, so the result can sit in a web address or file name without being altered. This is the form called Base64URL (RFC 4648 section 5).
- Leave off the = padding removes the = signs at the end. Many URL-safe uses, including JSON Web Tokens, leave them off. The decoder here accepts text with or without padding.
- Lines of 76 characters breaks the result into lines of at most 76 characters, the layout used by email (MIME) and by PEM files such as certificates and keys.
- Start with data: adds a prefix such as
data:image/png;base64,in front of the result, using the type of the file you opened. A web page or a style sheet can use text in that form directly as a picture, without a separate file.
Text is always converted to bytes as UTF-8 before it is encoded, which is what nearly every modern system expects. Accented letters, other alphabets and emoji all survive a round trip.
What the decoder accepts
The decoder is forgiving about the way the text was written. It ignores spaces, tabs and line breaks, reads both the standard and the URL-safe characters, adds missing = padding, and removes a data:…;base64, start if you pasted a whole data URL. When something is wrong it says which character is the problem and where it is, instead of just saying “invalid”.
The most common causes of an error are a character that does not belong, such as a quotation mark or bracket copied along with the text, a % code that means the text was URL-encoded and needs decoding first, a text that was cut short, and text that mixes the standard and URL-safe characters.
Base64 to a file or a picture
When the decoded bytes are not text, the tool recognizes the common file types by their first bytes. PNG, JPEG, GIF and WebP pictures are shown on the page, and you can download them with the right file extension; PDF and ZIP files are named as such. Other data is shown as a hex dump, the way a developer would inspect it, and can be downloaded as a .bin file. Going the other way, you can open any file up to 10 MB and get its Base64 text, for example to put a small image directly into a web page or a JSON message.
Where you will meet Base64
- Email attachments are carried as Base64 inside the message.
- Data URLs put a small picture, font or file inside a web page or style sheet.
- JSON Web Tokens (JWT) are three Base64URL parts separated by dots. Decoding the first two shows their contents, usually JSON, which you can tidy with the JSON formatter. Decoding does not check the signature, so it cannot tell you whether a token is genuine.
- HTTP Basic authentication sends “username:password” as Base64 in a header. That is encoding, not protection, which is why it should only travel over HTTPS.
- Certificates and keys in PEM files are Base64 text between the BEGIN and END lines.
- APIs and JSON files use Base64 when they need to hold a file or other binary value inside a text format.
Tips
- Mind the size. Base64 is about 33% larger than the data it carries. For a large picture on a web page, a normal image file loads faster than a data URL; use the image compressor first if you do want to embed it.
- Check round trips. To be sure a value survives, encode it, press Use result as input and confirm that the decoded text is identical. The text compare tool shows any difference.
- Use the right form. If the Base64 goes into a web address or a file name, tick URL-safe; for email and most other uses, the standard form is expected.
- Do not trust decoded files blindly. A file that has been through Base64 is just as capable of being harmful as any other download.
Your data stays on your device
Some Base64 sites send text to a server, or upload files and delete them later. This page does neither: the conversion runs in your browser, for text and for files, so nothing is sent anywhere. The page remembers your latest text and settings in your browser on this device, so they are still there after a reload. Clear removes the text, and clearing the site’s data in your browser removes everything.
Frequently asked questions
Is Base64 a form of encryption?
No. Base64 only changes how data is written so that it can travel through systems that handle plain text. Anyone can turn it back into the original with a tool like this one, so never use it to hide a password or any secret.
Is my text or file uploaded?
No. Encoding and decoding both happen in your browser, for text and for files, so nothing you paste or open is sent to this website or anywhere else. The page keeps the text you typed and your settings on this device so they survive a reload; press Clear to remove the text.
Why does Base64 make my data bigger?
Base64 writes every 3 bytes of data as 4 characters, so the result is about one third (33%) larger, plus a little more if you choose the 76-character lines. That is the price of being able to put binary data, such as a picture, inside text such as an email, a web page or a JSON file.
What is URL-safe Base64?
Standard Base64 uses the characters + and /, which have special meanings in web addresses and file names. The URL-safe form, also called Base64URL, uses - and _ instead and often leaves off the = padding. It is what JSON Web Tokens (JWT) use. The decoder reads both forms without being told which one you have.
Why does decoding show a hex dump instead of text?
The decoded bytes are not valid text, so they are probably a file such as a picture, a PDF, a ZIP archive or compressed data. The page shows the first bytes as hexadecimal numbers beside their characters and offers a download. If it is a picture, you see the picture itself.
My Base64 text fails to decode. What should I check?
The message gives the position of the first wrong character. The usual causes are a character that is not part of Base64 (such as a quotation mark, a % code or a stray bracket copied along with the text), text that was cut off so a character is missing at the end, and = padding signs in the middle instead of at the end. Spaces and line breaks are fine; they are ignored.