File to Base64
Encode any file into a Base64 data URL text.
What is File to Base64
The File to Base64 tool converts any file — fonts, JSON, PDF, whatever — into a data URL text. It reports the file name, size, MIME type and Base64 length, then prints the full data URL ready to paste into HTML or CSS. Runs in your browser; the file never leaves your device (4 MB limit). For images only, the Image ↔ Base64 tool adds a preview.
File
🔒 Everything runs in your browser. Nothing is uploaded.
What this tool actually does with your file
- Where it runs
- In your browser, on this page
- Upload
- None — the file never leaves your device
- Offline
- Works with the network disconnected
Any file, as text, locally
The file is read into an ArrayBuffer and encoded to Base64 in the page — useful for APIs that accept attachments only as a JSON string, for embedding a small binary in a config file, and for pasting a payload into an environment where file upload is blocked.
Encoding happens on the raw bytes, so the result is exact and lossless: decoding returns the identical file, verified by its original checksum. There is no interpretation of the content and therefore no charset problem, unlike text-oriented tools.
The 33% tax and where it stops you
Base64 grows the payload by roughly a third, and API gateways usually cap request bodies well below the file sizes people expect to send. A 10 MB PDF becomes about 13.4 MB of JSON, which then exceeds a 10 MB limit — so the failure appears at the transport layer, far from the encoding decision.
Memory is the second ceiling. The browser holds the file, the byte array and the encoded string at once, so peak usage is roughly three times the file size. Large files will stall or kill the tab well before any server limit is reached.
Decoding back to a file
A decoded payload must be written to a Blob with the correct MIME type and saved with the right extension; writing the text to a .txt file produces a file that cannot be opened. If the tool offers a download, check that the first bytes match the format you expect.
Watch for line wrapping and truncation on the way in. Base64 embedded in an email or copied out of a log often arrives broken at 76 characters with CRLF, or cut at a length limit with no error. A decoder that ignores whitespace handles the first; nothing recovers the second, which is why the decoded size should be compared with what the sender announced.
How to use it
- 1.Choose a file
- 2.Run to generate the data URL
- 3.Copy the output into your HTML/CSS
How File to Base64 works under the hood
Encoding tools convert between representations of the same bytes: Base64, percent-encoding, hex, HTML entities, Unicode escapes. A correct encoder is reversible; a lossy one silently changes the data.
- 1
Get the exact bytes
Text is encoded to UTF-8 bytes with TextEncoder first; binary input is read as an ArrayBuffer. Encoding the wrong byte sequence is the most common cause of a wrong result.
- 2
Apply the encoding rule
Each format has an exact specification: Base64 uses a 64-symbol alphabet with padding, percent-encoding escapes reserved characters as UTF-8 bytes.
- 3
Decode back to verify
Round-tripping the output back to the input is the only honest proof that an encoder is correct. The tool keeps the reverse path available on the same page.
Processing pipeline
Base64 is not encryption
Base64 increases size by about a third and hides nothing: anyone can decode it. It exists to carry binary data through text-only channels such as JSON, email headers and data URLs. If you need confidentiality, use encryption with a key, not an encoding.
Where encoders break
Percent-encoding applied twice turns %20 into %2520; Base64 without padding fails strict decoders; UTF-16 input decoded as UTF-8 produces replacement characters that cannot be recovered. When output looks wrong, check the byte sequence before checking the tool.
Verify it yourself
Encoders are pure functions over bytes. Decode the output again and you should get the input back exactly.
- 1.Open DevTools on this page and switch to the Network tab
- 2.Keep the filter on Fetch/XHR and run the tool
- 3.Confirm no request carries your file — you should see only page assets and fonts
Frequently asked questions
Does it work with any file?
Yes. For images the Image ↔ Base64 tool is more convenient (it previews), but this one handles fonts, JSON, PDFs and anything else.
What is the size limit?
4 MB. Note the Base64 text is about 1.33× the original file size.
What this kind of conversion cannot keep
Encoding and hashing run through the browser's Web Crypto API or a pure-JavaScript implementation. The output is deterministic: the same input always produces the same digest, so you can verify a result against any other tool.
More in Encoding
On this page
- What is File to Base64
- What this tool actually does with your file
- How it actually behaves
- How to use it
- How it works inside
- Frequently asked questions
Excel formula reference
29 functions with syntax, arguments and a table you can retype.
Browse the list →