Base64 encoder and decoder
Turn text or a file into Base64, or turn Base64 back into text or a file. Emoji and Chinese come out right, the URL-safe version is one click away, and wrong input gets the exact character and position. Nothing is uploaded: it all runs in this page.
Text and Base64
18 bytes of UTF-8 became 24 characters, which is 33.3% larger.
File to Base64
Pick a file to get its Base64 and a ready-to-paste data: URI. It uses the alphabet, padding and wrapping options above (the data: URI is always one line). The file is read in this page and not uploaded.
Base64 to file
Paste Base64 or a data: URI to turn it back into a file. If the bytes start with a PNG, JPEG, GIF or WebP signature, a preview is shown. Other types are not previewed; they only download.
Paste Base64 above and press Decode.
How it works
- •Text is first turned into bytes with UTF-8, and those bytes are what Base64 encodes. That is why 世界 and emoji give the same result as python3 or the base64 command. Decoding does the reverse and tells you if the bytes are not valid UTF-8 text, instead of showing garbled characters.
- •Base64 writes every 3 bytes as 4 characters, so the result is about one third larger. The page shows the real numbers for your input, counted from the actual lengths, not a rule of thumb. Line wrapping at 76 characters (MIME) adds a few more.
- •The URL-safe alphabet uses - and _ instead of + and /, so the result can sit in a URL or a file name. Padding is the = at the end that rounds the length up to a multiple of 4. Many systems, JSON Web Tokens among them, leave it out.
- •The decoder is more forgiving than most command line tools on purpose: it ignores spaces and line breaks, accepts a missing = padding, accepts both alphabets, and unwraps a data: URI. It is stricter about anything else. A character that does not belong, an = in the middle, or an impossible length is reported with its position instead of being skipped, because silently dropping characters can change your data.
- •Base64 to file shows a preview only when the first bytes match a PNG, JPEG, GIF or WebP signature. The file name is never trusted for that, and other types are never rendered, only downloaded. Files up to 10 MB are read in the page.
Questions
- Is anything uploaded?
- No. Encoding, decoding, file reading, previews and downloads all happen in this page on your device. The page makes no requests with your text or files.
- Is Base64 a way to hide or protect data?
- No. It is an encoding, not encryption. Anyone can decode it without a key, as this page shows. Do not use it to protect passwords, tokens or personal data.
- Why does my decoded text show as not valid UTF-8?
- The Base64 is fine, but the bytes are not text in UTF-8. They may be an image, a compressed file, text in another encoding such as GBK or Latin-1, or encrypted data. Use Base64 to file to download them and open them with the right program.
- How is this different from python or the base64 command?
- The encoded output is identical for standard and URL-safe Base64. On decoding, Python's default b64decode silently throws away characters it does not know and fails on missing padding, whereas this page accepts missing padding and reports unknown characters instead. macOS and Linux base64 differ from each other in how they treat wrapping and some invalid input, so check which one your scripts use.