Base64/Hex File Encoder & Decoder

Encodes an uploaded file's raw bytes to Base64 or hex text, or decodes pasted Base64/hex text back into a downloadable binary file, handling actual binary content correctly rather than treating the file as text. A free online tool from Staaarter, right in your browser.

Runs locallyUpdated 2026-07-25

Overview

Introduction

Base64-encoding a real binary file, an image, a PDF, an archive, by pasting it into a text-based encoder corrupts it, because that path assumes your input is text in the first place.

This tool reads an actual uploaded file's raw bytes and encodes them correctly, and decodes text back into a real downloadable file, entirely in your browser.

What Is Base64/Hex File Encoder & Decoder?

A real file-upload Base64/hex encoder and decoder: encoding reads a file with the browser's File API and converts its raw bytes to Base64 or hex text; decoding reverses that, turning pasted text back into a downloadable binary file.

It's the binary-safe counterpart to this site's text-based Base64 Encoder/Decoder tools, which are meant for text content, not arbitrary files.

How Base64/Hex File Encoder & Decoder Works

Encoding reads the selected file as an ArrayBuffer, then converts its bytes to Base64 (via a binary-string bridge to `btoa()`, chunked to avoid call-stack limits on large files) or to lowercase hex.

Decoding reverses either format: Base64 text is decoded with `atob()` back into raw bytes, and hex text is parsed two characters at a time into a byte array, then offered as a downloadable file.

When To Use Base64/Hex File Encoder & Decoder

Use it when you need to embed a real file's content as text, for a data URI, an API payload, or a config file, and a text-based encoder isn't safe for the binary content.

It's also useful for the reverse: reconstructing a real file from Base64 or hex text you've extracted from an API response, log, or embedded resource.

Features

Advantages

  • Handles genuinely binary files correctly, since it reads raw bytes rather than assuming text content.
  • Supports both Base64 and hex output, covering the two most common text encodings for binary data.
  • Round-trips: encode a file, then decode the result, and get back the exact original bytes.

Limitations

  • Capped at 25 MB per file to keep everything in-memory and responsive in the browser's main thread.
  • Doesn't validate that decoded bytes form a well-structured file of any particular type, only that the text was valid Base64 or hex.

Examples

Encoding a small image file to Base64

Input

icon.png (1.2 KB)

Output

iVBORw0KGgoAAAANSUhEUgAA...

The file's raw bytes are read and converted directly to a Base64 string, suitable for embedding in a data URI or JSON payload.

Best Practices & Notes

Best Practices

  • Use hex output when you need a fixed-width, easily-diffable representation; use Base64 when you need the most compact text representation (about 33% smaller than hex for the same bytes).
  • Verify a round trip (encode, then decode the result) once when integrating with a new downstream system, to confirm nothing is being altered along the way (like whitespace being inserted into the Base64).
  • Remove or account for the `data:<mime-type>;base64,` prefix separately if you're extracting Base64 from a data URI; this tool expects the raw encoded text.

Developer Notes

Encoding converts the file's `ArrayBuffer` to a binary string in 32 KB chunks (via `String.fromCharCode(...)` on `Uint8Array.subarray()` slices) before calling `btoa()`, since spreading a very large typed array directly into `String.fromCharCode` can exceed the JS engine's maximum argument count. Hex decoding parses two hex characters at a time into a `Uint8Array` with `parseInt(..., 16)` per byte.

Base64/Hex File Encoder & Decoder Use Cases

  • Embedding a real file's content as a Base64 data URI or in a JSON/config payload
  • Reconstructing a downloadable file from Base64 or hex text extracted from an API response or log
  • Converting between hex and Base64 representations of the same binary content

Common Mistakes

  • Using a text-based Base64 encoder on a binary file instead of this tool, which silently corrupts non-text content by treating it as UTF-8 text first.
  • Forgetting to strip a `data:image/png;base64,` prefix before pasting Base64 text in for decoding, which will otherwise fail to decode as valid Base64.

Tips

  • If decoding fails, check whether the source Base64 uses URL-safe characters ('-' and '_' instead of '+' and '/'); this tool expects standard Base64, so URL-safe text needs those characters swapped back first.

References

Frequently Asked Questions