Base64 Encoder and Decoder
Turn text or a small file into Base64, or paste Base64 to get the original back as text or as a downloadable file. Accents, other scripts and emoji survive the round trip because the text is encoded as UTF-8 first. The work happens in this browser tab and nothing is uploaded.
Any type, up to 5 MB. The file is read in this tab and never uploaded.
Limits: Up to 8 MB of pasted text or a file of up to 5 MB. Larger input is refused with a message.
Results
- Input
- -
- Output
- -
- Size change
- -
- Read as
- -
Result
How to use the Base64 Encoder and Decoder
- Type or paste text into the box, or choose a file to encode instead.
- Pick the direction. For encoding, set the alphabet, the padding and MIME line breaks in the settings.
- Read the result. Decoded text appears in the result box, and binary data is offered as a download.
- Copy the result, or press Download to save it as a file.
Worked example
A short German greeting: plain ASCII letters, three letters outside ASCII that take two bytes each, and a four byte emoji. Press Load the example to encode it with the standard alphabet and padding. The + in the output would change to - in the URL safe alphabet.
Grüße aus München 👋
- Direction
- Text to Base64
- Alphabet for encoding
- Standard, with + and /
- End with = padding
- on
- Break lines at 76 characters (MIME)
- off
- Input
- 25 bytes
- Output
- 36 characters
- Size change
- +44%
- Read as
- UTF-8 text
- Result
R3LDvMOfZSBhdXMgTcO8bmNoZW4g8J+Riw==
How to read the results
- Input
- When encoding, the size of the text in UTF-8 bytes or the size of the file. When decoding, the number of Base64 characters, not counting spaces, line breaks and padding.
- Output
- The number of Base64 characters produced, line breaks included, or the number of bytes decoded.
- Size change
- How much longer or shorter the output is than the input, as a whole percent.
- Read as
- UTF-8 text, a file, or binary data when the decoded bytes are not valid UTF-8.
- Result
- The Base64, the decoded text, or for binary data a hexadecimal preview of its first 64 bytes. Copy takes the whole text, even where the box shows only its start, and for binary data the hexadecimal preview; Download saves the whole result, and for decoded data the exact bytes.
- Notes
- An info note reports a choice the decoder made, such as restoring missing padding or removing a data: URL prefix. A warning flags something to check, such as a text that mixes both alphabets.
How this tool works and its limitations
To encode, the page turns text into UTF-8 bytes with TextEncoder, or reads the chosen file into memory, then passes the bytes to the browser's btoa in pieces and joins the results. The URL safe option swaps + and / for - and _ afterwards, the padding option removes the trailing = signs, and the MIME option cuts the text into lines of 76 characters joined by CR LF.
To decode, the page first checks every character, so a stray symbol is reported with its line and position instead of a bare error. It then uses the same helpers as Base64 to Image: one removes whitespace, maps - and _ back and restores the padding, the other runs atob to get the bytes. TextDecoder with its fatal option decides whether the bytes are valid UTF-8 text. Downloads are made from a temporary object URL that is revoked a second after the click. The text and files stay in this tab, and these limits apply:
- Base64 is not encryption and this page adds none: anyone with the encoded text can read the original.
- Text is encoded as UTF-8 with the line breaks the box holds, which browsers store as line feeds. RFC 2045 wants CR LF line breaks in text before MIME encoding, so convert them first if an email system insists.
- Decoded bytes are shown as text only when they are valid UTF-8. Text in another character set, such as Windows 1252, is treated as binary and offered as a download.
- Decoding forgives spaces, line breaks, a data: URL prefix, missing padding and either alphabet; it refuses any other character, padding in the middle and impossible lengths.
- Files are capped at 5 MB and pasted text at 8 MB, limits this page sets. In Chromium on the test machine a 5 MB file encoded in about 30 ms and its Base64 decoded in about 50 ms. Past 100,000 characters the result box shows the beginning only, while Copy and Download still take the whole result.
- Only the first 64 bytes of binary output are shown, in hexadecimal; Download saves all of them, with a file name based on the first bytes for PNG, JPEG, GIF, WebP and PDF.
Features
- UTF-8 encoding through TextEncoder, so characters beyond Latin 1 never make the browser throw.
- Standard or URL safe alphabet, padding on or off, and 76 character lines for email.
- Decoding that ignores spaces and line breaks and names the exact character it cannot read.
- Files up to 5 MB to encode, and decoded bytes saved as a file through a temporary link that is freed right after the download.
Base64 hides nothing
Base64 rewrites bytes using 64 printable characters so they can pass through systems built for text, such as email, JSON and URLs. It has no key. RFC 4648, the standard that defines it, says the encoding visually hides recognizable information but does not provide any computational confidentiality. A password or token in Base64 is as exposed as the password itself, so protect it the same way and never treat an encoded value as a secret.
Why encoded text is about a third longer
Every 3 bytes become 4 characters, because each character carries 6 bits and 3 bytes hold 24. MDN's Base64 glossary puts the result at roughly a third larger than its source, depending on the length and the padding. Short inputs grow more: the 25 bytes of the worked example become 36 characters, 44 percent more, since the last group is padded to four. MIME line breaks add two characters for every 76.
Alphabets, padding and line breaks
The standard alphabet in section 4 of RFC 4648 ends with + and /, two characters that mean something in URLs and file names. Section 5 defines a URL and filename safe alphabet that uses - and _ in their place, and MDN notes that a data: URL is fine with the standard form. The = signs only round the text up to a multiple of four; the RFC asks encoders to include them unless the format using Base64 says otherwise. It also forbids line breaks unless a format asks for them, which RFC 2045 does for email, at most 76 characters a line.
Frequently asked questions
How do I encode a file to Base64?
Choose the file in the field marked Or encode a file, and its Base64 appears in the result box, with your alphabet, padding and line break settings applied. Any type of file works up to 5 MB, and a larger one is refused with a message. Typing in the box, or setting the direction to decode, drops the file and returns to text.
Why does btoa throw an error on my text?
btoa works on single bytes, and MDN notes that any character above U+00FF makes it throw. Text must first become UTF-8 bytes, which is what this page does, so an emoji or a Greek letter encodes without trouble.
Why does decoding give me garbled characters or a download?
The bytes are not UTF-8 text. They may be a binary file, such as an image or a PDF, or text saved in an older character set. The page then shows the first bytes in hexadecimal and offers the whole file.
How do I see an image I have as Base64?
Use Base64 to Image, which previews the picture, reads its format and saves it with the right extension. This page saves the same bytes as a file but does not draw them.
Can I decode Base64 that has line breaks in it?
Yes. Spaces, tabs and line breaks anywhere are skipped, so a block copied from an email decodes as one piece.
What do the = signs at the end mean?
They are padding. One = means the last group held two bytes and two mean it held one. Some formats drop them, and this page restores them before decoding.
Is URL safe Base64 the same as URL encoding?
No. URL safe Base64 only swaps two characters of the alphabet so the output needs no escaping. URL encoding replaces unsafe characters with % escapes and leaves the rest of the text readable.
Last updated .