How to convert Base64 to a file
A Base64 string is a file written in 64 plain characters. To convert base64 to file, the tool turns every four characters back into three bytes, finds out what kind of file those bytes make, and gives you a download with a fitting name.
The built-in example decodes to a 96 by 64 pixel PNG of 16,607 bytes. The panel reports PNG image, shows the picture, and names the file gradient.png. Its SHA-256 hash begins 426a243b7751fb5b.
How the file type is found
Most file formats start with a fixed signature. The tool checks it, so the type is correct even when the string has no label. It knows PDF, PNG, JPEG, GIF, WebP, AVIF, BMP and ICO images, SVG, MP3, WAV, Ogg, FLAC, M4A, MP4, MOV and WebM media, WOFF, TrueType and OpenType fonts, ZIP, GZIP, BZIP2, 7-Zip, RAR and TAR archives, Word, Excel and PowerPoint files, SQLite databases, programs, and plain text, JSON, HTML, XML and scripts.
A data URI states a type of its own, as in data:image/png;base64,.... The tool compares it with the bytes. If they disagree, a warning appears and the file is named after the bytes, because those are what the file really is.
What this Base64 decoder accepts
- Plain Base64, with or without line breaks and spaces, including the 76-character lines used in email.
- Data URIs. The text before the comma is read and removed.
- URL-safe Base64, which uses - and _ in place of + and /.
- Text with missing
=padding. The padding is added and the panel says so. - Percent-escaped characters such as %2B and %3D, and JSON escapes such as \/.
- A JSON object or array. The longest text value in it is decoded, and the panel names the field.
Anything else, such as a stray character or a string that is too short, gives an error with the position and what to check.
Why a decoded file will not open
- The string was cut off when it was copied. A length that does not fit Base64 is reported, but a cut that falls on a boundary gives a smaller file that looks fine until you open it. Compare the size with what you expect.
- The text was encoded twice. If the decoded result is plain text that itself looks like Base64, paste that text in again.
- It was a different type of file than you assumed. The detected type line tells you what the bytes are.
- A Word, Excel or PowerPoint file is a ZIP inside. The tool names it by looking for the parts Office files contain.
To compare with the original, ask the sender for its SHA-256 hash. If your hash is the same, the decoded file is identical.
Programs and other risky files
A decoded file can be anything, including a program. The tool never opens or runs the result. Windows and Linux programs, macOS binaries, Java archives, Android packages and scripts that start with #! are marked with a warning. HTML and SVG can hold scripts too, so open a downloaded .html file only if you trust it. Only run a program if you trust where the text came from.
Images, audio and video are shown with your browser's own players, and text is shown as plain text. For a PDF, Base64 to PDF shows the page count and checks for encryption and scripts, and for pictures Base64 to Image adds more image tools. To decode Base64 that is only text, use Base64 Decode.
Base64 to file on the command line and in code
base64 --decode report.b64 > report.docx # Linux
base64 -D -i report.b64 -o report.docx # macOS[IO.File]::WriteAllBytes("report.docx", [Convert]::FromBase64String((Get-Content report.b64 -Raw)))require("fs").writeFileSync("report.docx", Buffer.from(text, "base64"));To make Base64 from a file, use File to Base64.
Limits and privacy
- Up to 15 million characters of input and 10 MB of decoded data.
- Previews are for images, audio, video and text. Other types download without a preview.
- The file type comes from the bytes. Files with no recognizable signature are shown as unknown binary data.
The text is decoded in your browser. It is not uploaded or stored. See the Privacy Policy for details.