Base64 Encode/Decode

File to Base64 Converter: Encode Any File Online

Convert any file to a Base64 string. Works with documents, images, audio, archives, and any binary format. 100% client-side, no file upload to servers.

100% client-side. Your data never leaves your browser.

📁

Drag & drop a File file here

or click to browse (max 50 MB)

Related Tools

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

  1. Drop any file onto the upload area or click to browse
  2. The tool reads and encodes the file in your browser
  3. Choose output format: plain Base64 (most versatile), data URI (includes MIME type), or CSS background (for images)
  4. 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 signatureMIME typeExample
%PDFapplication/pdfPDF documents
PK (ZIP header)application/zipZIP archives, DOCX, XLSX
\x89PNGimage/pngPNG images
\xFF\xD8\xFFimage/jpegJPEG images
ID3audio/mpegMP3 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 sizeBase64 sizeOverhead
1 KB1.33 KB+0.33 KB
100 KB133 KB+33 KB
1 MB1.33 MB+0.33 MB
10 MB13.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.