Blog · Base64 How-To
How to Convert Base64 to a Downloadable File
Got a Base64 string and need the actual file back? Turn any Base64-encoded data into a downloadable file — images, PDFs, ZIPs, and more. No upload, no install, free.
Someone sent you a Base64 string, or you pulled one from a JSON API, and now you need the actual file — an image, a PDF, a spreadsheet. Converting Base64 back to a file is straightforward once you know the steps. This guide covers every method, from clicking a button to writing a script, following the standard defined in RFC 4648.
atob() + Blob, Python base64.b64decode(), or the base64 -d command.What Does "Base64 to File" Actually Mean?
When a file gets encoded to Base64, its raw binary data turns into a long string of letters, numbers, and + / / characters with optional = padding. Converting it back means decoding that string into the original binary format — bytes — and saving those bytes as a file with the correct extension and MIME type. The process is deterministic: the same Base64 string will always produce the same file, bit for bit.
Method 1: Use the Free Online Tool (One Click)
The quickest path: our free Base64 to file converter does the heavy lifting in your browser. Nothing leaves your computer — all decoding happens locally via JavaScript.
- Paste your Base64 string into the input field on base64go.com
- Click Decode — the tool auto-detects the file type
- Click Download to save the reconstructed file
For data URIs (strings starting with data:image/png;base64,...), the tool strips the prefix automatically and figures out the right file extension. You do not need to manually extract the MIME type.
Method 2: JavaScript (Browser Download)
Use this snippet to trigger a file download from a Base64 string directly on a webpage:
const byteChars = atob(base64.replace(/^data:.*?;base64,/, ''));
const bytes = new Uint8Array(byteChars.length);
for (let i = 0; i < byteChars.length; i++) {
bytes[i] = byteChars.charCodeAt(i);
}
const blob = new Blob([bytes], { type: mimeType });
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = filename;
a.click();
URL.revokeObjectURL(url);
}
// Usage: base64ToFile(encodedStr, 'photo.png', 'image/png');
Method 3: Python
def base64_to_file(b64_string, output_path):
with open(output_path, "wb") as f:
f.write(base64.b64decode(b64_string))
# Decode and save as a file
base64_to_file(b64_str, "output.pdf")
Method 4: Command Line
base64 -d encoded.b64 > output.png
# Or pipe directly (macOS):
base64 -D <<< "iVBORw0KGgoAAAANS..." > image.png
# Linux / WSL:
echo "iVBORw0KGgoAAAANS..." | base64 -d > image.png
How to Identify the File Type from a Base64 String
Most Base64 strings don't carry a label telling you what kind of file they represent. Here is how to figure it out:
- Check for a data URI prefix. If the string starts with
data:image/png;base64,, the MIME type is right there. Strip that prefix before decoding. For more on this, see our Base64 pictures guide. - Decode the first few bytes. PNGs start with
‰PNG, PDFs start with%PDF, ZIPs start withPK. Decode a small sample and look at the bytes. - Check the Base64 header. Some tools prepend the Base64 with a hint, like
JVBERi0for PDFs oriVBORw0KGgofor PNGs. Our tool scans for these patterns automatically. - When in doubt, try common extensions. If the decoded file won't open, rename it to
.png,.pdf, or.zipand try each. Most Base64 strings come from one of these three formats.
Common Base64 Headers by File Type
| File Type | Base64 Prefix | Binary Magic Bytes |
|---|---|---|
| PNG | iVBORw0KGgo | 89 50 4E 47 |
| JVBERi0 | 25 50 44 46 | |
| ZIP | UEsDBBQ | 50 4B 03 04 |
| JPEG | /9j/ | FF D8 FF |
| GIF | R0lGOD | 47 49 46 38 |
Common Pitfalls
- Missing padding. Some systems strip the trailing
=characters. Most decoders handle this, but if yours doesn't, add padding until the string length is a multiple of 4. - Line breaks in the string. Remove all whitespace before decoding — newlines inside a Base64 string will break the output.
- Wrong MIME type. If the downloaded file won't open, try renaming it with the correct extension. A
.pdfsaved as.pngwon't render. - Truncated strings. If your Base64 string is cut off mid-way, the last few bytes will be corrupted. Always verify you have the complete string before decoding.
Frequently Asked Questions
Is this Base64 to file converter really free?
Yes. Our tool at base64go.com is completely free. No sign-up, no payment, no usage limits. Everything runs in your browser — we never see your data.
Can I convert Base64 back to any file type?
Yes. Base64 can represent any binary data — images, documents, archives, audio, executables. As long as the original file was properly encoded, decoding it will reconstruct the exact same file, byte for byte.
Do I need to install software to convert Base64 to a file?
No. Our online tool works in any browser with no installation. If you prefer offline tools, Python's built-in base64 module, the Unix base64 command, and JavaScript's atob() are all pre-installed on most systems.
Is Base64 the same as encryption? Can I use it to protect files?
No. Base64 is encoding, not encryption. Anyone can decode it — there is no password or key. Read our guide on why Base64 is not encryption to understand the critical difference.
Convert Base64 to file now. Free, no upload.
Paste your Base64 string and download the original file in seconds.
Open Base64 Tool