File to Base64 Converter

Drop any file, whether a document, archive, font, certificate or program, and get its Base64 encoding as raw text or a data URI. Everything runs locally in your browser.

Runs entirely in your browser. Nothing is uploaded.

How to use

  1. Drop a file onto the upload area, or click it to choose a file from your device (up to 100 MB).
  2. Choose the output: raw Base64 for APIs and config files, or a data URI for HTML and CSS.
  3. Turn on 76-character line wrapping only if the target expects MIME-style lines, such as an email body.
  4. Check the file name, MIME type and sizes, then copy the result or download it as a .txt file.

Why encode a file as Base64?

Many formats that carry data between systems are text only. JSON, XML, YAML, HTML and email headers cannot hold arbitrary bytes, because a file may contain zero bytes, invalid character sequences or line endings that a text parser would change. Base64 maps every 3 bytes of the file to 4 characters from a set of 64 letters, digits, + and /, so any file can travel as a plain string and be decoded back to exactly the same bytes.

The trade-off is size: the encoded text is about 33% larger than the file, and line breaks add a little more. A 3 MB file becomes roughly 4 MB of Base64.

Common uses

  • JSON and XML APIs. Endpoints that do not accept multipart form uploads often expect the file as a Base64 string in one field, with its name and type in others.
  • Email attachments. MIME encodes attachments in Base64 with lines of at most 76 characters (RFC 2045). Line wrapping produces the same layout.
  • Configuration and secrets. The values under data in a Kubernetes Secret are Base64, so a TLS certificate, keystore or license file must be encoded before it goes into the manifest. CI systems often keep binary secrets in environment variables the same way.
  • Databases and source code. A small binary such as a font, a sound or a test fixture can be stored in a text column or a string constant instead of a separate file.

For pictures, Image to Base64 adds resizing and ready-made HTML and CSS snippets. To turn Base64 back into a file, use Base64 to File.

Raw Base64 or data URI?

Raw Base64 is just the encoded bytes. It is what APIs, Kubernetes, databases and most programming libraries expect, usually next to a separate field for the file name or content type.

A data URI adds a prefix with the MIME type, for example data:application/pdf;base64,, so a browser can use the whole string as a URL in src, href or CSS url(). Do not send that prefix to an API that asks for plain Base64; many decoders reject it. To set the MIME type yourself or use percent-encoding, try the Data URI Generator.

Leave line wrapping off for JSON, YAML and source code. A JSON string cannot contain raw line breaks, and wrapped values in YAML break easily.

Encode a file on the command line

# Linux (GNU coreutils): -w 0 turns off the default 76-character wrapping
base64 -w 0 report.docx > report.txt

# macOS
base64 -i report.docx -o report.txt

# Windows PowerShell
[Convert]::ToBase64String([IO.File]::ReadAllBytes("C:\files\report.docx"))

# Kubernetes encodes the file for you
kubectl create secret generic app-cert --from-file=tls.crt

Frequently asked questions

Is there a file size limit?

Files up to 100 MB can be encoded. The output is about a third larger, so a 100 MB file produces around 133 MB of text. Showing that much text can make the page slow, so for large files use Download instead of copying from the output box.

Are my files uploaded to a server?

No. The file is read and encoded by JavaScript in your browser and nothing is sent over the network, so certificates, keys and private documents stay on your device.

Does Base64 compress or encrypt the file?

Neither. Base64 makes the data about 33% larger, and anyone can decode it. If the file must stay confidential, encrypt it before encoding; if size matters, compress it first, for example as a ZIP or gzip archive.

Why does the output contain line breaks?

76-character line wrapping is turned on. It matches the MIME format used in email, but most APIs, JSON documents and Kubernetes manifests expect one unbroken line, so turn it off for those.

How is this different from the Base64 encoder?
The Base64 encoder is built for text, with character encodings and Base64 variants. This page is built for files: it reads the raw bytes of any file, shows its MIME type and can output a data URI directly.