Convert Any File to Base64
Turn a PDF, ZIP, audio file or font into Base64 text or a data URI
Your files stay with you. Conversion happens inside the browser; no file is ever uploaded to a server.
Did this tool do the job?
Thanks, your feedback came through.
How it works
Choose your file by tapping or clicking the box, pick an output format and press Convert to Base64; each file comes back as a text file with .txt appended to its name. A 300 KB contract in PDF form, for example, becomes roughly 400 KB of text on a single line, ready to drop into a JSON field, a configuration file or the body of an API request. With the data URI option the type is written in front of the data, and that type comes from the first bytes of the file rather than its name, so a file saved with the wrong extension is still labelled correctly. The result line reports the source size, the output size and the character count — Base64 grows data by about a third, which is why the limit is 20 MB per file. All of it happens inside your browser; the file is never uploaded.
This tool is also known as file to base64, pdf to base64, base64 encode file, convert file to data uri, base64url encoder, encode binary file as text.
What is Base64URL?
Base64URL is the variant of Base64 that survives inside a URL. The + and / characters of the standard alphabet carry special meaning in addresses and file names, so they are replaced with - and _, and the trailing = padding is usually dropped as well. Encoded data can then sit in a link, a query parameter or a JWT segment without a second round of escaping. Decoding it is trivial: swap the two characters back and restore the missing padding.
What is File signature (magic bytes)?
A file signature is a fixed pattern in the first few bytes of a file that gives away its type. PDFs open with %PDF, ZIP-based formats with PK, PNG with an eight-byte header of its own. Operating systems mostly guess the type from the extension, but an extension is a label anyone can change by renaming, whereas the signature is part of the content. This tool derives its MIME label from the signature, so files with a wrong or missing extension are still described correctly.
What is MIME type?
A MIME type is the standard two-part label that says what a piece of data is: application/pdf, image/png, font/woff2. It was invented to describe e-mail attachments and is now used everywhere on the web; a browser decides whether and how to display data by reading this label. In a data URI the label is written in front of the encoded bytes, which is why a single data:application/pdf;base64,… line carries both the content and the description of what that content is.
How is this different from the "image to Base64" tool?
Both apply the same encoding; they differ in scope and in what the output tells you. The image to Base64 tool accepts image files only and returns lines built for images: a CSS background-image declaration, an HTML img tag, a preview of what you encoded. This page makes no distinction by type — PDFs, ZIP archives, DOCX files, fonts, audio and video all go through — and shapes the output around where you will paste it: plain Base64, a data URI or the URL-safe form, wrapped at 76 characters if you want. If you are embedding an icon in a stylesheet, the image tool takes fewer steps; in every other case this is the page you want.
An extension can lie, the first bytes cannot
The extension at the end of a file name is a convention, not a fact about the content. A PDF saved as .txt, a font that lost its extension in a chat app, a PNG named .jpg — all of these are everyday occurrences. If the type in front of a data URI is wrong, the browser either refuses to open the content or opens it as the wrong thing.
So the type is read from the file's signature instead: PDFs start with %PDF, ZIP-based formats with PK, PNG with its own eight-byte header. For the ZIP-shelled formats — DOCX, XLSX, EPUB — one more step is taken and the name of the first entry inside the archive is inspected, so a Word document and a zipped folder do not end up with the same label. When no signature matches, the type reported by your operating system is used, and failing that the generic application/octet-stream.
Base64 output is bigger: which format to pick
Encoding writes three bytes as four characters, so the output is about a third larger than the source. That cost is invisible on small files and painful on a few megabytes, where the text starts to strain your editor and your browser; hence the 20 MB limit. Encoding a video or a large archive is rarely a good idea in the first place — those belong in a binary channel.
Which format you want depends on where the text is going. A data URI cannot be split: it has to stay on one line, so wrapping is skipped when you choose it and the result line says so. The URL-safe form replaces + and / with - and _ and drops the trailing = padding, which is what you need for data travelling in a URL, a JWT segment or a file name.
- Plain Base64 → JSON fields, API bodies, configuration files
- Data URI → a small file embedded in HTML, CSS or an e-mail template
- Base64URL → URLs, JWT segments, file names and query parameters
- Wrap at 76 → PEM certificates and e-mail attachments use this layout
Frequently asked questions
How do I convert a PDF to Base64?
Choose the PDF by tapping or clicking the box, select Plain Base64 or Data URI as the format and press the button. The output downloads as a text file whose single line is the whole PDF written as text.
Can I turn the Base64 text back into a file?
For images, yes: the Base64 to image tool on this site decodes what you paste and hands the file back. For other types this page is currently one-way; if your Base64 holds a text document, the Base64 encode and decode tool will turn it back into readable text.
Is my file uploaded anywhere?
No. The file is read into your browser's memory and encoded there; neither the file nor its name crosses the network. This site's security headers block the page from sending data in the first place, so the tool also works offline.
Why the 20 MB limit?
Because Base64 output is about a third larger than the source, a 20 MB file becomes nearly 27 MB of text in one piece. Beyond that the tab starts fighting for memory and copying, opening or pasting the result stops being practical.