Home / Encoders & Decoders

Base64 Image Encoder and Decoder

Runs locally in your browser. Your input is not uploaded.

or drop or paste an image here. It stays on your device.

A Base64 image encoder represents an image's bytes with printable characters. That representation can stand alone as Base64 or sit inside a data URI, CSS declaration, HTML image element, or Markdown image. A decoder reverses the representation so you can preview the image and save its bytes as a file.

This tool handles both directions locally in your browser. It is useful for preparing a small embedded asset, identifying an image hidden in an encoded payload, or recovering a file from a Base64 string. Encoding does not compress or protect an image, so consider size and trust before embedding the result.

How to Use the Base64 Image Encoder and Decoder

Choose a direction, then use the controls for that mode.

  1. Select Image to Base64 to encode, or Base64 to image to decode.
  2. In Image to Base64 mode, select Choose an image, drop an image into the drop area, or paste an image from the clipboard.
  3. Choose Data URI, Base64 only, CSS background-image, HTML <img>, or Markdown from the Output as select.
  4. Review the Preview and Base64 output, then select Copy.
  5. In Base64 to image mode, paste a value into Data URI or Base64.
  6. Check the Preview and detected media type, then select Download image to save the decoded bytes.

How Base64 Image Data and Data URIs Work

Base64 maps binary bytes to a restricted text alphabet. Standard Base64 commonly uses letters, digits, +, /, and optional = padding. This decoder also accepts Base64url characters, omitted padding, and whitespace, making it practical for values copied from wrapped documents or URL-oriented payloads.

A data URI adds metadata before the encoded content. A PNG value begins in this general form:

data:image/png;base64,iVBORw0KGgo...

The encoder reads the selected file as a browser data URL and preserves the file's reported image media type. The other Output as choices wrap that same URI for a particular context or remove its prefix for Base64 only. They do not resize, recompress, or convert the underlying image. Use the image compressor or image resizer before encoding when the source needs optimization.

The decode side accepts either raw Base64 or a data URI marked with ;base64. A non-Base64 data URI is rejected rather than percent-decoded. The tool attempts to identify PNG, JPEG, GIF, WebP, BMP, AVIF, ICO, and SVG from their bytes; when a data URI declares an image media type, that type can be used as a fallback.

Base64 Size Overhead and Page Performance

Base64 expands binary data because four encoded characters represent three input bytes, before any data URI or markup wrapper is added. The tool reports the original file size, the resulting data URI length, and the calculated percentage increase. For files over 100 KB, it also warns that a separate image file is usually preferable.

Embedding can be convenient for a tiny icon or a self-contained test case because the image travels with the surrounding text. The tradeoff is that the browser cannot cache the embedded image as an independent resource, and changing the containing CSS, HTML, or Markdown can require transferring the image again. A long string also makes source files and code reviews harder to navigate.

Do not treat Base64 as an automatic performance improvement. Compare the transferred, compressed document with a separately served image and account for reuse across pages. Modern image formats and appropriate dimensions often save more than replacing a request with an encoded string.

Decoding Errors, Type Detection, and Edge Cases

Invalid alphabet characters or an impossible Base64 length produce an error. Valid Base64 is not necessarily a valid image: arbitrary bytes can be encoded successfully. The decoder therefore checks known image signatures or a declared image media type, creates a local Blob, and asks the browser to display it.

Type detection is deliberately limited. The signature checks cover the formats listed above, but they are not a complete image validator. Truncated data may pass the initial signature check and then fail in the preview. A misleading data:image/... prefix can also claim a type that the bytes do not actually contain, so inspect the result before using it.

SVG is text-based and is recognized only when its decoded beginning looks like XML or an <svg element. Leading constructs outside that simple check may not be detected from raw Base64. If the original data URI supplies image/svg+xml, the declared type provides the fallback. The downloaded name is generated as image plus an extension derived from the detected media type.

Privacy and Security When Handling Encoded Images

Encoding and decoding happen in the current browser page; the selected file and pasted value are not uploaded by this tool. The preview for decoded content uses a local object URL, while an encoded file is previewed from its local data URL. This reduces unnecessary disclosure when inspecting private assets.

Base64 itself offers no confidentiality. Anyone who obtains the string can decode the image, and embedded data may remain in source control, browser history, logs, chat messages, or copied documents. Do not encode a confidential screenshot and assume the unreadable-looking text hides it.

Treat an image from an unknown source as untrusted. A recognizable header does not prove that the file is harmless or complete, and SVG can contain active or externally referenced content depending on where it is used. Preview cautiously, avoid inserting unknown SVG into a privileged document, and scan recovered files according to your normal security process.

Frequently Asked Questions

Does Base64 reduce an image's file size?

No. Base64 normally makes the representation larger because it turns three bytes into four text characters, with a little more overhead for a data URI or markup wrapper. Compress, resize, or convert the image first if reducing bytes is the goal; encoding only changes how those bytes are represented.

What image formats can the decoder recognize?

The byte checks recognize PNG, JPEG, GIF, WebP, BMP, AVIF, ICO, and SVG. A data URI's declared image/* media type can serve as a fallback when the signature is not recognized. Detection is not full validation, and the browser may still reject damaged or unsupported image data during preview.

Can I paste raw Base64 without a data URI prefix?

Yes. Paste standard Base64 or Base64url into Data URI or Base64; whitespace and missing padding are accepted. Without a prefix, the bytes must match one of the tool's recognized image signatures so it can choose an image type.

Does the tool convert the image to another format?

No. Image to Base64 preserves the selected file's bytes and media type, while Base64 to image reconstructs the decoded bytes. The CSS, HTML, and Markdown choices only wrap the same data URI. Use a dedicated converter such as PNG to WebP when you need a different format.

Is it safe to put a Base64 image in HTML or CSS?

It can be reasonable for a small, trusted asset, but it is not automatically safer or faster than a separate file. Base64 does not sanitize content, and embedded images can enlarge documents and bypass independent caching. Be especially careful with untrusted SVG and with images containing secrets or personal information.

References: RFC 4648: Base-N Encodings · MDN: Data URLs.