Skip to content
ToolPlankDEV
Encoders & Decoders
100% In-Browser Execution

Updated:

File to Base64 Converter

Drop any file and get its Base64 text. This file to base64 converter gives plain, URL-safe, MIME line-wrapped or data URI output, and shows the file type, the exact size cost and a SHA-256 hash. The file never leaves your device.

Processing in browser...

Loading the tool. It runs entirely in your browser, so your data is never uploaded.

More free tools you may need next.

Quick Guide

How to use File to Base64

Simple step-by-step instructions to get the exact output you need.

  1. 01

    Choose a file

    Drop any file on the left panel or press Select file. Files up to 20 MB work. Example loads a small gradient PNG so you can see the result first.

  2. 02

    Pick the output format

    Choose plain Base64, a data URI, MIME style with a line break every 76 characters, or URL-safe Base64. The note under the menu explains each one.

  3. 03

    Check the summary

    The panel shows the file name, its size, the Base64 length with the exact cost in percent, the detected file type and a SHA-256 hash of the original file.

  4. 04

    Copy or download

    Press Copy to put the whole result on your clipboard, or Download .txt to save it. Swap sends the text straight to Base64 to File so you can check it round trips.

How to convert a file to Base64

Base64 writes any bytes using 64 plain characters, so a file can travel inside JSON, an email, a URL or a line of CSS. To convert a file to base64, the tool reads its bytes in your browser and encodes every group of 3 bytes as 4 characters.

The built-in example is a 96 by 64 pixel gradient, 16,607 bytes. It becomes 22,144 Base64 characters, which is 33.3% more, and starts like this:

Text
iVBORw0KGgoAAAANSUhEUgAAAGAAAABACAIAAABqVuVZAABApklEQVR42g3aiUv6/h8H8N9f8uVD

Every PNG starts with the same eight bytes, so every PNG in Base64 starts with iVBORw0KGgo. A PDF starts with JVBERi0 and a ZIP file with UEsDB. Seeing one of these is a quick way to tell what a string holds.

File to Base64 online: the four output formats

  • Plain Base64: one unbroken line. This is what most JSON APIs and database fields expect.
  • Data URI: data:type;base64,..., where the type is the one your browser reports for the file, or the type found from the bytes when it reports none. You can use it in an HTML src or a CSS url().
  • MIME, 76 per line: the same text with a line break every 76 characters, the style used in email bodies. Decoders ignore the breaks.
  • URL-safe: - and _ replace + and /, and the = padding is dropped. It can sit in a URL or a file name without escaping.

Why the Base64 is a third bigger

Three bytes hold 24 bits. Base64 cuts those bits into four pieces of 6 bits, and each piece becomes one character. Four characters for every three bytes is 33.3% more, plus up to two = signs at the end. The summary shows the exact figure for your file. A line break every 76 characters adds a little more, while compression, if the receiving server uses it, can take back part of the cost.

For large files a data URI is rarely a good idea. It cannot be cached on its own, and the browser has to decode it each time. Use it for small icons and fonts. For a download or an upload, send the file itself.

Convert a zip, font or audio file to Base64

The tool does not care what the file is. A zip, a font, an audio clip or a spreadsheet all work the same way, because only the bytes matter. The type line is there to help you: it is read from the first bytes of the file, so it is right even when the name has the wrong extension.

If you only have a picture, Image to Base64 adds CSS, HTML and Markdown snippets. For a PDF, PDF to Base64 can also write a JSON field or a cURL command. To encode text instead of a file, use Base64 Encode.

The SHA-256 hash

The summary includes a SHA-256 hash of the original file, calculated by your browser. If you send the Base64 to someone, they can decode it, hash the result and compare. When the two hashes match, every byte arrived. The hash is of the file, not of the Base64 text, and it needs a secure page (https) to be calculated.

File to Base64 on the command line and in code

Bash
base64 -w 0 report.docx > report.b64      # Linux, one line
base64 -i report.docx -o report.b64       # macOS
powershell
[Convert]::ToBase64String([IO.File]::ReadAllBytes("report.docx"))
JavaScript
const base64 = require("fs").readFileSync("report.docx").toString("base64");

To turn Base64 back into a file, use Base64 to File, which also finds the type, shows a preview and warns about programs.

Limits and privacy

  • Files up to 20 MB are accepted. The result is about a third larger, and very long strings can be slow to paste into editors or send to an API.
  • The preview shows the first 20,000 characters. Copy and Download include the whole string.
  • Swap needs the file to be 10 MB or smaller, which is the limit of Base64 to File.

The file is read and encoded in your browser. It is not uploaded or stored. See the Privacy Policy for details.

Frequently Asked Questions

Technical Q&A for File to Base64

Common questions about edge cases, character encoding, and privacy guarantees.

Drop the file on the left panel. The Base64 text appears on the right straight away. Press Copy to use it, or Download .txt to save it.

Base64 uses four characters for every three bytes, which is 33.3% more, plus a little padding. The summary shows the exact increase for your file.

A data URI puts a file inside text, as data:type;base64,... You can use it in an HTML src or a CSS url() for small icons and fonts. It is a poor choice for large files.

It means a line break after every 76 characters, the format email uses for attachments. Decoders skip the breaks, so the wrapped text decodes to the same file.

It is Base64 that uses - and _ in place of + and /, and drops the = padding, so it can go in a URL or a file name without escaping.

Yes. This tool accepts files up to 20 MB. Larger files make very long strings that many tools and APIs cannot handle.

No. The file is read and encoded in your browser, so it never leaves your device.

On Linux run base64 -w 0 file. In PowerShell run [Convert]::ToBase64String([IO.File]::ReadAllBytes("file")). Or drop the file on this page.

Yes. The tool works with any file because it only reads bytes. The detected type is shown so you can confirm it is the file you meant.

It lets the person who receives the Base64 check that the decoded file is identical to yours. If their hash matches, no byte was lost or changed.