Base64 Encoder and Decoder
Convert text or a file to Base64 and back, and see what decoded data is. The data is processed on your device and is never uploaded.
Runs in your browser. Your input is not sent anywhere.
What this tool does
Base64 writes arbitrary bytes with 64 harmless characters, so that binary data can travel through places that only accept text, such as JSON fields, HTML attributes or email bodies. It is an encoding, not encryption: anyone can decode it.
The tool encodes text or a file, and decodes Base64 back to text or to a file. It works with the standard alphabet and with the URL-safe alphabet, both defined in RFC 4648, and writes and reads data URIs. Decoded images are previewed, PDFs can be opened, and every recognized file is saved with the right extension.
How to use it
- Choose the direction: encode or decode.
- Type or paste the text. To encode a file of up to 20 MB, choose it with the file field instead.
- For encoding, choose the alphabet and whether the result ends with = padding.
- Copy the result or download it. After decoding, the download contains the decoded bytes, so this is how you restore a file. For an image or a PDF the file gets its proper extension, such as .png or .pdf.
- For CSS or HTML, turn on “Output as a data URI” to get data:image/png;base64,… ready to paste into url() or an src attribute.
When decoding you do not need to say which alphabet the text uses. The tool recognizes it, accepts text with or without padding, ignores spaces and line breaks, and removes the prefix of a data URL.
How the result is derived
Text is first converted to bytes with UTF-8. The bytes are then taken in groups of three, which are 24 bits. Each group is split into four parts of 6 bits, and each part selects one of the 64 characters of the alphabet. Three bytes therefore become four characters, and the encoded form is about one third longer than the data.
If one or two bytes are left at the end, they produce two or three characters. Padding with = fills the last group up to four characters, so that the length of padded Base64 is always a multiple of four.
Decoding reverses the steps. If the decoded bytes are valid UTF-8, they are shown as text. If they are not, the data is something else, for example an image, and the tool shows the first bytes in hexadecimal instead of inventing characters.
Worked example
The word “foo” consists of the bytes 66 6f 6f in hexadecimal. As bits that is 011001 100110 111101 101111, four groups with the values 25, 38, 61 and 47. In the alphabet these are the characters Z, m, 9 and v.
f -> Zg==
fo -> Zm8=
foo -> Zm9v
foob -> Zm9vYg==
fooba -> Zm9vYmE=
foobar -> Zm9vYmFyThe two alphabets differ only where the values 62 and 63 occur. The four bytes fb ff bf fe give +/+//g== in the standard alphabet and -_-__g in the URL-safe alphabet without padding.
Reference: Base64 variants
| Variant | Characters 62 and 63 | Padding | Typical use |
|---|---|---|---|
| Standard (RFC 4648, section 4) | + and / | Yes | Email attachments, data URLs, PEM files |
| URL-safe (RFC 4648, section 5) | - and _ | Often omitted | JSON Web Tokens, values in URLs and file names |
The URL-safe alphabet exists because + and / have a meaning in URLs. The padding character = has one as well, which is why formats such as JSON Web Tokens leave it out; the length of the text tells the decoder how many bytes the last group holds.
Some formats break Base64 into lines. The standard says that encoders must not add line breaks unless the format that uses Base64 asks for them. This tool writes one line and accepts line breaks when decoding.
A data URL, or data URI (RFC 2397), has the form data:image/png;base64, followed by the data. The tool removes such a prefix before decoding and reports the media type it found. When it writes one, it always uses the standard alphabet with padding, as RFC 2397 refers to the Base64 of MIME (RFC 2045), and takes the media type from the file’s first bytes, otherwise from the type your browser reports for the file; text is labeled text/plain;charset=utf-8.
Recognizing decoded files
A file name or a data URI label can be wrong; the first bytes of the data rarely are. After decoding, the tool compares them with the byte patterns that browsers use to recognize files, from the WHATWG MIME Sniffing Standard. If a data URI claims one type and the bytes show another, the tool says so.
| Type | First bytes (hexadecimal) | Shown as |
|---|---|---|
| PNG | 89 50 4E 47 0D 0A 1A 0A | Image preview, .png |
| JPEG | FF D8 FF | Image preview, .jpg |
| GIF | 47 49 46 38 37 61 or …39 61 (GIF87a, GIF89a) | Image preview, .gif |
| WebP | RIFF, 4 bytes, then WEBPVP | Image preview, .webp |
| BMP | 42 4D (BM) | Image preview, .bmp |
| ICO | 00 00 01 00 | Image preview, .ico |
| CUR (cursor) | 00 00 02 00 | .cur |
| 25 50 44 46 2D (%PDF-) | Open in a new tab, .pdf | |
| ZIP | 50 4B 03 04 | .zip |
| gzip | 1F 8B 08 | .gz |
| RAR | 52 61 72 21 1A 07 00 | .rar |
The preview and the opened PDF come from the decoded bytes in the page’s memory, through a temporary blob: address that exists only in your browser. Other data is shown as text when it is valid UTF-8, and otherwise as hexadecimal and saved as decoded.bin.
Common mistakes
- Treating Base64 as protection. It hides nothing; use encryption for secrets.
- Decoding URL-safe text with a decoder for the standard alphabet, or the other way round. The characters - and _ are then reported as invalid.
- Encoding text with another character set than UTF-8 in one program and decoding it as UTF-8 in another. Letters outside ASCII then come out wrong.
- Losing characters when copying. Base64 with 1, 5 or 9 characters and so on cannot exist, because one character alone holds only 6 bits. The tool reports such text as incomplete.
- Putting standard Base64 into a URL without percent-encoding. A + in a query string is read as a space.
Sources
Frequently asked questions
- Is my text or file uploaded?
- No. Text and files are read and converted by a script in the page. The file field hands the file to that script only; nothing is sent to a server.
- Is Base64 a form of encryption?
- No. Base64 has no key. Everyone who sees the encoded text can decode it, with this tool or any other.
- Why is the result longer than my input?
- Every three bytes become four characters, so the result is about 33 percent longer than the data, plus up to two padding characters.
- How do I turn Base64 into an image or a PDF?
- Choose “Decode Base64” and paste the text, with or without a data: prefix. If the bytes are an image, the tool shows it; a PDF gets an “Open the PDF” link. “Download result” saves the bytes with the matching extension, such as decoded.png. Base64 itself stores no file name, so rename the file as you like.
- What does the warning about unused bits mean?
- When the data does not fill the last group, some bits of the last character are unused and an encoder sets them to zero. Text in which they are not zero still decodes to the same bytes, but it was not written by a standard encoder or it was altered.
Last updated: September 29, 2026