Skip to main content
CalcChef

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

PastedResultDownload name
TWFu3 bytes, text: Mandecoded.bin
SGVsbG8gV29ybGQ11 bytes, text: Hello Worlddecoded.bin
data:text/plain;base64,SGVsbG8gV29ybGQ=11 bytes, text: Hello Worlddecoded.txt
iVBORw0KGgo=8 bytes, binarydecoded.png
-_8=2 bytes, binary, URL-safe alphabetdecoded.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 typedSaved as
(empty)decoded.png
photophoto.png
report.pdfreport.pdf
a/b:c*?.txta_b_c__.txt
...hiddenhidden.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 tools