File to Base64 Encoder – Free

Choose a file and get its contents as a Base64 string. This file to Base64 encoder reads the file in your browser, accepts any type up to 20 MiB and never uploads it.

How to use the File to Base64 tool

  1. Select the File field and choose a file from your device. Any file type is allowed.
  2. Select Encode file. The browser reads the bytes and encodes them.
  3. Find the Base64 string in the Result box.
  4. Select Copy for the clipboard, or Download to save the string as a text file named after the original with .base64 added.

What File to Base64 produces

The tool reads the raw bytes of the file with the browser's File API and encodes them with the standard Base64 alphabet of RFC 4648. No character set is involved and nothing is interpreted, so a text file keeps its byte order mark and line endings, and a binary file is reproduced bit for bit when decoded.

The output is the Base64 alone, on a single line with = padding. It contains no data URL prefix, no file name and no media type. If the receiving system needs those, send them in separate fields or add the prefix yourself.

Worked example

A text file named hello.txt that holds the 13 bytes of a short greeting, with no trailing newline, encodes to 20 characters. The Download link offers hello.txt.base64, a plain text file with exactly that string. The command line equivalents are shown for comparison; all three produce the same Base64 for the same file.

hello.txt (13 bytes)  →  SGVsbG8sIHdvcmxkIQ==
Download name:           hello.txt.base64

Linux:       base64 -w 0 hello.txt
macOS:       base64 -i hello.txt
PowerShell:  [Convert]::ToBase64String([IO.File]::ReadAllBytes("C:\path\hello.txt"))

The 20 MiB limit and output size

Files larger than 20 MiB (20,971,520 bytes) are refused with the message Choose a file up to 20 MiB. At that size the result already runs to 27,962,028 characters, all of which are placed in the Result box.

Base64 output is always four characters per three bytes, rounded up. A 1 MiB file gives 1,398,104 characters. For results of several megabytes, prefer the Download link over Copy; clipboards and text fields in other programs often struggle with strings that long.

Typical reasons to encode a file

Base64 lets binary content travel through channels that accept only text. These are the situations where developers reach for it.

  • Sending an attachment inside a JSON or XML API request.
  • Storing a certificate, keystore or signing key in a CI secret or environment variable.
  • Filling a binary value in a Kubernetes Secret or a ConfigMap binaryData field.
  • Embedding a small font or image in CSS or HTML as a data URL.
  • Creating fixtures for tests that must not depend on external files.

Frequently asked questions

Is my file uploaded to the server?

No. The file is read in your browser through the File API and encoded in memory. There is no upload request, so the tool also works for confidential documents and keys.

What is the maximum file size?

20 MiB, which is 20,971,520 bytes. A larger file triggers the message Choose a file up to 20 MiB. For bigger files, use the base64 command of your operating system or a short script.

Does the output include a data: URL prefix?

No. You get only the Base64 characters. To form a data URL, put data:, the media type, ;base64, and then the string together, for example data:application/pdf;base64, followed by the output.

How is this different from Image to Base64?

The encoding is identical. Image to Base64, Audio to Base64 and Video to Base64 only filter the file picker to one media family. This page shows every file, which suits archives, documents and binaries.

How do I turn the Base64 back into the file?

Paste the string into Base64 to File and select Decode file. The decoder restores the bytes and suggests an extension for common formats. Your original file name is not stored in the Base64, so rename the download.

Can I encode several files at once?

No. The File field takes one file per run. Encode files one after another, or put them in a ZIP archive first and encode the archive.

Related tools