File to Base64 Converter - Encode Images to Data URL
Convert files and images to Base64 strings (Data URLs) or decode Base64 back to files.
File → Base64
Convert any file into Base64 text.
Drop file here or click to browse
20 MB
Base64 → File
Decode a Base64 or Data URL string back into a file.
History
How it works
This tool lets you encode files to Base64, and decode Base64 strings back to files. Everything is executed locally in your browser using HTML5 FileReader and Blob APIs.
Data URL vs. Raw Base64
- Data URL: Includes a definition of the file type and encoding at the start (e.g. `data:image/png;base64,...`). This format can be pasted directly into CSS (`background-image`) or HTML (`<img src="...">`).
- Raw Base64: Contains only the raw encoded data payload without any prefix.
About this tool
Converts files (images, PDFs, documents, etc.) to Base64 text strings, and back. Base64 is a standard way of representing binary data as plain text, used to embed files directly into HTML/CSS/JSON, embed images as "data URLs" in email, or send files over text-based protocols without binary support. The tool supports drag-and-drop, copying the result to clipboard, and generating a complete `data:` URI with the right MIME type. Everything happens locally in your browser, your file is never uploaded anywhere.
How to use it
- Drag and drop the file into the tool, or click "Choose file".
- The Base64 string is generated instantly. Size is shown as new and original.
- Pick "Base64 only" or "full data URL" (data:image/png;base64,…).
- Click "Copy" to put the result on the clipboard.
- To go the other way: paste a Base64 string and the file appears as download or preview.
Examples
16×16 PNG (400 bytes)data:image/png;base64,iVBORw0KGgoAAAA…PDF (12 KB){"filename":"faktura.pdf","data":"JVBERi0xLjQKJa…"} (16 KB)Logo (5 KB SVG)<img src="data:image/svg+xml;base64,PHN2Zy…">Common use cases
- Embedding small images or icons in CSS/HTML without extra HTTP requests.
- Sending files in JSON-based APIs that don’t support multipart/form-data.
- Storing file data in a text field of a database or config file.
- Signing and encryption operations where data must be textual.
- Email clients without attachment support: images as inline data URLs.
- Debugging API integrations by inspecting Base64 content.
Frequently asked questions
- Why is the Base64 string ~33 % larger than the file?
- Base64 uses 6 bits per character (64 possible values: A–Z, a–z, 0–9, + and /), while a byte is 8 bits. Three bytes (24 bits) become four characters, overhead of 4/3 ≈ 33 %. Additionally, `=` padding is added if the length isn’t a multiple of 3. A 900 KB file becomes about 1.2 MB as Base64.
- Is Base64 a form of encryption?
- No. Base64 is an encoding, not encryption. Anyone can decode Base64 back to original binary, there’s no key, no secret. Use Base64 for transport, not for confidentiality. For secrecy, use encryption (AES, RSA) and optionally Base64-encode the ciphertext for transport.
- Should I always use data URLs instead of external files?
- No. Data URLs save one HTTP request, but the images can’t be cached separately in the browser, every page view reloads them as part of the HTML/CSS. For very small icons (< 2 KB) data URLs are often worth it. For larger images, especially reused ones, separate cacheable files are better.
- Is my file safe while I use the tool?
- Yes. All conversion happens in your browser via JavaScript and the `FileReader` API. The file is not sent to any server, not stored in cookies or localStorage, and never leaves your device. The tool also works offline (after the initial page load).
Technical background
Base64 is defined in RFC 4648. The alphabet is A–Z, a–z, 0–9, + and /, with `=` as padding. The tool uses the browser’s built-in `btoa()`/`atob()` for text strings and `FileReader.readAsDataURL()` for files, which already returns a complete data URL in the format `data:<mime>;base64,<content>`. For URL-safe Base64 (RFC 4648 §5), `+` is replaced with `-` and `/` with `_`, used in JWT and OAuth. Base64 decoding is faster than encoding and requires no memory shuffling. For very large files (> 100 MB), use streaming-based decoding to avoid browser memory issues.