Base64 File to String
Encode a file of up to 5 MB to Base64 or a data URI, or decode Base64 back to a downloadable file named from its data URI type or first bytes. How it works
Use the Base64 File to String
About the Base64 File to String
Base64 writes every 3 bytes as 4 characters, so the text is about a third larger than the file: the 3 bytes of Man are TWFu. The tool encodes a file of up to 5 MB to plain Base64 or a data URI, and decodes pasted Base64 or a data URI back to a file you can download, shown as text when it is valid UTF-8.
Decoding examples
| Pasted | Result | Download name |
|---|---|---|
| TWFu | 3 bytes, text: Man | decoded.bin |
| SGVsbG8gV29ybGQ | 11 bytes, text: Hello World | decoded.bin |
| data:text/plain;base64,SGVsbG8gV29ybGQ= | 11 bytes, text: Hello World | decoded.txt |
| iVBORw0KGgo= | 8 bytes, binary | decoded.png |
| -_8= | 2 bytes, binary, URL-safe alphabet | decoded.bin |
| +_8= | Error: the text mixes the standard (+ /) and URL-safe (- _) alphabets | (none) |
| = | Error: the text holds only padding (=), no data | (none) |
With the file name field empty. iVBORw0KGgo= is the 8-byte PNG signature, so the extension comes from the first bytes; the data URI gives text/plain, so .txt.
Download names for a decoded PNG
| Name typed | Saved as |
|---|---|
| (empty) | decoded.png |
| photo | photo.png |
| report.pdf | report.pdf |
| a/b:c*?.txt | a_b_c__.txt |
| ...hidden | hidden.png |
Slashes and characters Windows refuses become _, leading dots go, and a name without an extension gets the one found for the file. Names are cut to 100 characters.
Frequently asked questions
- How do I convert a file to Base64?
- Choose Encode, then drop a file on the box or click it to pick one of up to 5 MB. Choose Plain Base64 String or Data URI, then Copy or Download Base64, which saves photo.png as photo.png.base64.txt. The file is read in your browser and is not uploaded.
- How do I convert Base64 back to a file?
- Choose Decode, paste the Base64 or the whole data URI, optionally type a file name, and press Decode. The page shows the byte count and, for text, the content; Download saves the file under the name shown on the button, and binary results can also be copied back as standard Base64.
- How much larger is Base64 than the file?
- About a third: characters = 4 × ceil(bytes ÷ 3). A 5 MB file (5,242,880 bytes) becomes 6,990,508 characters, and a data URI adds its data:<type>;base64, header in front.
- Does it decode URL-safe Base64 and missing padding?
- Yes. The URL-safe - and _ (as in JWT segments) are read, as long as they are not mixed with + and /, and the = padding may be left off: SGVsbG8gV29ybGQ decodes to the 11 bytes of Hello World. White space and line breaks are ignored.
- How does it know the file type?
- From the data URI type when there is one (text/plain gives .txt), otherwise from the first bytes: PNG, JPEG, GIF, WebP, PDF, ZIP and GZIP are recognised. Anything else is saved as .bin unless you type a name with its own extension. A result found to be PNG, JPEG, GIF or WebP from its first bytes, or BMP, ICO or SVG from its data URI type, is also shown as an image.
- Can a link fill in the Base64 to decode?
- Yes: the q parameter fills the Base64 box, mode chooses Encode or Decode, and filename fills the download name. A link only fills the fields; nothing is decoded or downloaded until you click.
Related Tools
View all toolsSVG to CSS Background Converter
Convert SVG markup to a CSS background-image data URI, URL-encoded or Base64. Adds a missing xmlns, rejects non-SVG input, gives url() or inline-style output.
Hex to ASCII
Convert hex to ASCII text: 48 65 6C 6C 6F is Hello. Bytes are read as UTF-8, and odd digit counts or bad characters get an error.
Base64 Converter
Encode text to Base64 or decode Base64 to text. UTF-8, standard and URL-safe alphabets, optional padding on decode, up to 250,000 characters.
Chmod Calculator
Type a chmod mode such as 755 or 4755 to see rwxr-xr-x, or paste rwxr-xr-x or tick read, write and execute for owner, group and public to get the octal number.
Hash Generator
Compute the MD5, SHA-1, SHA-256, SHA-384 or SHA-512 hash of text or a file and compare it with an expected checksum. The file is hashed in your browser.
HTML Entity Encoder
Encode text to HTML entities (& < > " ') or decode any of the 2,231 named references in the HTML standard and numeric ones such as é.