Convert Any File to Base64
Base64 encoding converts arbitrary binary data into a text string using 64 printable ASCII characters. This tool reads any file from your device and produces the Base64 encoded output, which you can use in API payloads, database storage, configuration files, or any context that requires text safe data.
How to Use
- Drop any file onto the upload area or click to browse
- The tool reads and encodes the file in your browser
- Choose output format: plain Base64 (most versatile), data URI (includes MIME type), or CSS background (for images)
- Copy the result
Why Convert Files to Base64
Text safe transport
Many protocols and formats only support text: JSON, XML, YAML, email (SMTP), URL parameters, HTML attributes. Base64 encoding makes any binary file safe to include in these contexts without corruption.
Simplified API payloads
Instead of multipart form data (which requires boundary handling and content-disposition headers), Base64 lets you include file data in a regular JSON field:
{
"file": "UEsDBBQAAAAIAM1Y...",
"filename": "archive.zip",
"contentType": "application/zip"
}
Self contained documents
Base64 data URIs create documents that carry their resources inline. A single HTML file can contain all its images, fonts, and even embedded PDFs without external dependencies.
Configuration and secrets
Tools like Kubernetes secrets, CI/CD pipelines, and cloud configuration often store binary data (certificates, keys, license files) as Base64 encoded strings in YAML or JSON config files.
MIME Type Detection
This tool automatically detects the file’s MIME type from its content signature (magic bytes), not just the file extension. For example:
| File signature | MIME type | Example |
|---|---|---|
%PDF | application/pdf | PDF documents |
PK (ZIP header) | application/zip | ZIP archives, DOCX, XLSX |
\x89PNG | image/png | PNG images |
\xFF\xD8\xFF | image/jpeg | JPEG images |
ID3 | audio/mpeg | MP3 audio |
If the signature is not recognized, the tool uses the MIME type reported by the browser’s file picker, falling back to application/octet-stream.
Base64 Encoding Across Languages
JavaScript (browser)
const reader = new FileReader();
reader.onload = () => {
const base64 = reader.result.split(',')[1];
};
reader.readAsDataURL(file);
Python
import base64
with open('file.bin', 'rb') as f:
encoded = base64.b64encode(f.read()).decode('ascii')
Bash
base64 < file.bin # macOS
base64 -w 0 < file.bin # Linux (no line wrapping)
Go
data, _ := os.ReadFile("file.bin")
encoded := base64.StdEncoding.EncodeToString(data)
Java
byte[] bytes = Files.readAllBytes(Path.of("file.bin"));
String encoded = Base64.getEncoder().encodeToString(bytes);
Size Overhead
Base64 increases data size by exactly 4/3 (33.3%). This is because every 3 input bytes produce 4 output characters. With padding, the formula is:
output_length = 4 * ceil(input_length / 3)
| File size | Base64 size | Overhead |
|---|---|---|
| 1 KB | 1.33 KB | +0.33 KB |
| 100 KB | 133 KB | +33 KB |
| 1 MB | 1.33 MB | +0.33 MB |
| 10 MB | 13.3 MB | +3.3 MB |
When transmitted over HTTP with gzip/brotli compression, Base64 text compresses poorly (it has high entropy). The effective overhead compared to sending the raw binary is closer to 37-40% after compression.
For image specific conversion, see Image to Base64. For PDF files, see PDF to Base64. To reverse the process, use Base64 to File. For text only encoding, the main Base64 Encoder is simpler.