Drop any file to get its Base64 string, a ready-to-paste data URI, CSS, HTML or JSON. The file type is detected from its content, and the conversion happens on your device, so the file is never uploaded.
Last updated:
Drop files here or choose files
Any type: PDF, images, fonts, audio, ZIP, JSON… · or paste with Ctrl+V
No file yetYour file is read locally with the FileReader API. It is never uploaded.
FILE
File size
-
Base64 length
-
Overhead
-
Detected as
-
Preview
Advertisement
Advertisement
How to use the File to Base64
Add a file: drop it on the box, click to choose one or more files, or paste a copied file or screenshot.
Check the MIME type detected from the file's content and change it if needed.
Choose the output: plain Base64, data URI, CSS, HTML or JSON.
Set line wrap or URL-safe if the target system expects it, for example 76 characters for email MIME or 64 for PEM.
Copy or download the result. With several files, click a file in the list to show its output.
How Base64 encoding works
Base64 turns binary data into plain text using 64 safe characters: A–Z, a–z, 0–9, + and /. Every 3 bytes (24 bits) are split into four 6-bit groups, and each group becomes one character. If the file length is not a multiple of 3, the last group is padded with =.
Output length = 4 × ⌈bytes ÷ 3⌉ characters. A 1,000-byte file becomes 1,336 characters, about 33% larger. Line breaks add one or two more characters per line.
Common file signatures used for MIME detection
File type
First bytes (hex)
Base64 starts with
MIME type
PDF
25 50 44 46 (%PDF)
JVBERi
application/pdf
PNG
89 50 4E 47
iVBORw0KGgo
image/png
JPEG
FF D8 FF
/9j/
image/jpeg
GIF
47 49 46 38 (GIF8)
R0lGOD
image/gif
ZIP, DOCX, XLSX
50 4B 03 04 (PK)
UEsDB
application/zip, Office types
Gzip
1F 8B
H4sI
application/gzip
WOFF2 font
77 4F 46 32 (wOF2)
d09GMg
font/woff2
MP3 with ID3 tag
49 44 33 (ID3)
SUQz
audio/mpeg
The "Base64 starts with" column is handy for recognising an unknown Base64 string: JVBERi is almost always a PDF and iVBORw0KGgo a PNG.
When to use a data URI, and when not to
Good fits: small icons, fonts or images in a single-file HTML page or email template, test fixtures, and JSON APIs that accept file contents as Base64.
Poor fits: large images and videos on websites. A data URI cannot be cached separately, is 33% larger and blocks the HTML or CSS that contains it.
Email: MIME attachments use Base64 with lines of at most 76 characters, which is what the 76-character wrap option produces.
Frequently asked questions
How do I convert a file to Base64?
Drop the file onto the box above or click it to choose a file. The Base64 string appears instantly. Click Copy result to put it on the clipboard or Download .txt to save it. The conversion uses your browser's FileReader, so the file never leaves your computer.
What is the difference between Base64 and a data URI?
Base64 is just the encoded bytes, for example JVBERi0xLjQK... for a PDF. A data URI adds a prefix with the MIME type, data:application/pdf;base64,JVBERi0xLjQK..., so a browser can use it directly in an href, src or CSS url(). APIs and JSON payloads usually want plain Base64.
Why is the Base64 output bigger than the file?
Base64 represents every 3 bytes with 4 ASCII characters, so the output is about 33% larger than the original (plus padding, and line breaks if you wrap). A 300 KB file becomes about 400 KB of text. That is why large files are better linked than embedded.
How is the MIME type detected?
The tool reads the first bytes of the file and matches known signatures, such as 89 50 4E 47 for PNG, 25 50 44 46 (%PDF) for PDF and 50 4B 03 04 for ZIP-based files. If the signature is unknown it falls back to the type reported by your system and the file extension. You can always type a different MIME type.
When should I wrap Base64 lines?
Email (MIME, RFC 2045) limits encoded lines to 76 characters and PEM files for certificates and keys use 64. JSON, data URIs, HTML and most APIs expect one unbroken line, so leave wrapping off unless the target requires it.
What is URL-safe Base64?
Base64url (RFC 4648 section 5) replaces + with - and / with _ and usually drops the = padding so the string can be used in URLs and file names without escaping. It is used by JWT tokens and many web APIs. Data URIs always use standard Base64.
Is there a file size limit?
There is no upload, so the limit is your device's memory. Files of tens of megabytes convert in a second or two. For very large files the output box shows only the beginning to keep the page responsive, while Copy and Download still use the full string.
Are all the tools on FreeToolCabin tested for quality and accuracy?
Yes! Every tool on our site undergoes automated Q/A testing in real browser environments to ensure high precision, correct output, and zero errors. If you happen to spot a bug or have a suggestion, please contact us at [email protected] and our team will review it right away.