File ↔ Base64 Converter

Encode any file as Base64 or a data URL, or paste Base64 to get the original file back, with its type detected from the bytes. Image mode adds a preview and ready-to-paste CSS, <img> and Markdown snippets.

Converter Media & Files Updated Oct 4, 2026
How to Use
  1. Pick a mode: Encode a file, Decode Base64 back to a file, or Image for pictures you want to embed in a page. Each mode opens with a worked sample.
  2. Encode: drop any file. Choose plain Base64 or a data URL, the standard or URL-safe alphabet, and line wrapping (76 columns for MIME email, 64 for PEM).
  3. Decode: paste Base64 or a whole data: URL. The file type is detected from its first bytes, images are previewed, and Download saves the file with the right extension.
  4. Image: drop a picture to get a data URL, a CSS background rule, an <img> tag or Markdown. Formats a browser cannot show, such as TGA, TIFF or PCX, can be re-encoded as PNG, JPEG or WebP first.
  5. Copy the result or download it. Show Work traces how the first three bytes of your file become four Base64 characters. Nothing is uploaded.
Input
Presets
Base64 Output
File Size
—
Base64 Length
—
Overhead
—
Detected Type
—
Result

Worked Example

Encoding “Man”. The three bytes are 4D 61 6E, or 01001101 01100001 01101110 in binary. Read as four 6-bit groups, 010011 010110 000101 101110, they are 19, 22, 5 and 46. In the alphabet A–Z (0–25), a–z (26–51), 0–9 (52–61), + (62), / (63) those are T, W, F, u: “Man” → TWFu.

A whole sentence. “Many hands make light work.” is 27 bytes, exactly 9 groups of 3, so it encodes to 4 × 9 = 36 characters with no padding: TWFueSBoYW5kcyBtYWtlIGxpZ2h0IHdvcmsu. As a data URL it gains the 23-character prefix data:text/plain;base64,.

An image. A 200,000-byte photo needs 4 × ⌈200,000 ÷ 3⌉ = 4 × 66,667 = 266,668 characters, 33.3% more than the file.

The common mistake: decoding a data URL as plain Base64. Pasting data:image/png;base64,iVBOR… into a strict decoder fails or gives garbage, because “data:image/png;base64,” is not Base64. Strip everything up to and including the comma first; this tool does that for you and keeps the MIME type for the file name.

Show Work

Encode or decode something to see the bits regrouped step by step.

Formulas

Encoded length
L = 4 × ⌈n ÷ 3⌉
n bytes in, L characters out (with padding)
Padding
p = (3 − n mod 3) mod 3
Number of = signs at the end
Decoded size
n = 3L ÷ 4 − p
From a padded Base64 string
One group
c₁…c₄ = (b₁b₂b₃ ≫ 18, 12, 6, 0) & 63
24 bits split into four 6-bit indexes
Data URL
data:mime;base64,…
RFC 2397: “data:” (5) + the MIME type + “;base64,” (8)

Where Base64 Came From

Early email could only carry 7-bit text, so binary files had to be disguised as letters and digits. Mary Ann Horton’s uuencode (1980, UC Berkeley) did it for Unix mail and Usenet. Base64 as we know it was defined for Privacy-Enhanced Mail in RFC 989 in 1987, and MIME (RFC 2045, 1996) made it the standard way to attach files to email, with lines of at most 76 characters.

Larry Masinter’s RFC 2397 (1998) defined the data: URL, which lets a page carry a small file inside its own text. RFC 4648 (2006) gathered the variants into one standard, including base64url, the URL- and filename-safe alphabet now used in JSON Web Tokens.

About This Tool

This converter encodes any file as Base64 or a data URL in the standard or URL-safe alphabet, with optional MIME or PEM line breaks, and decodes Base64 or data URLs back into a downloadable file. The file type is detected from its signature bytes rather than trusted from the name, and images are previewed through the same engine as the Universal Image Converter, so a pasted TGA or TIFF shows too.

Image mode turns a picture into a data URL, CSS background rule, <img> tag or Markdown, and can re-encode it as PNG, JPEG or WebP so formats a browser cannot display still work inline. Files up to 50 MB can be encoded. Everything runs in your browser; nothing is uploaded.

Related tools: Base64 Encoder / Decoder, Hex Viewer, and File Inspector.

Frequently Asked Questions

How does Base64 encoding work?

It takes the file 3 bytes (24 bits) at a time and splits them into four 6-bit numbers from 0 to 63, each written as one character from A–Z, a–z, 0–9, + and /. The bytes of “Man” are 01001101 01100001 01101110; regrouped as 010011 010110 000101 101110 they are 19, 22, 5 and 46, which are the characters TWFu.

Why is Base64 about 33% bigger than the file?

Every 3 bytes become 4 characters, so the length is 4 × ⌈n ÷ 3⌉. A 3,000-byte file becomes 4,000 characters and a 200,000-byte image 266,668. MIME email also adds a line break every 76 characters, a little over 2.6% more.

What do the = signs at the end mean?

They are padding for a final group of fewer than 3 bytes. One leftover byte gives two characters and ==, two leftover bytes give three characters and =. “M” encodes as TQ== and “Ma” as TWE=. URL-safe Base64 usually leaves the padding off, and this decoder accepts it either way.

When should I use a data URL?

For small files that would otherwise cost an extra request, such as icons under a few kilobytes, CSS backgrounds and images in HTML email. A data URL is data:, the MIME type, ;base64, and the encoded bytes. Large images are better as normal files: inlined, they grow by a third and cannot be cached separately from the page.

What is URL-safe Base64?

The base64url variant from RFC 4648 swaps + for - and / for _, so the text can sit in a URL or file name without escaping, and it usually drops the = padding. It is used in JSON Web Tokens. The bytes FB FF FE are +//+ in standard Base64 and -__- in base64url.

How do I use the File ↔ Base64 Converter?

Just type or paste your value. The answer shows up right away — there is no button to press. Change anything and it updates by itself.

Does it cost anything or need an account?

No. The tool is completely free, there is no account to create, and it keeps working offline after the page first loads.

Is anything I type uploaded?

No. The tool works entirely on your device, so the values you enter never leave your browser.

Common Use Cases

Inline icons in CSS

A 1,200-byte icon becomes a 1,600-character data URL that sits in a background-image rule, saving one request per page.

Files inside JSON or XML

APIs that only carry text send attachments as Base64: a 30,000-byte PDF becomes a 40,000-character string field.

Images in HTML email

Embed a small logo as a data URL so it shows even when remote images are blocked.

Recover a file from text

Paste Base64 copied from a log, an API response or a page source and download it; the type is detected from bytes such as 89 50 4E 47 (PNG) or 25 50 44 46 (PDF).

Test fixtures

Store a small binary sample in a unit test as one Base64 string instead of a separate file.

Tokens and URLs

Produce URL-safe Base64 without padding for query strings, file names and JWT segments.

Last updated: