On-device AI — professional-grade, fully private.

Documents

How to Convert Base64 to an Image (and an Image to Base64)

Turn a Base64 string or data:image URI into a downloadable PNG, JPG or GIF, or turn an image into Base64. Fix truncated strings, bad characters and more.

Updated November 7, 20267 min read

To turn Base64 into an image, paste the string into the Base64 decoder. It strips any data:image/png;base64, prefix, decodes the bytes, works out from the first few bytes that the result is a PNG, JPEG or GIF, shows you a preview and lets you download it with the right extension. To go the other way, drop the picture into the Base64 encoder and switch on Wrap as a data URI. The rest of this guide covers the details that decide whether it works: what to paste, what the errors mean, and when embedding an image as text is a bad idea. For what Base64 is in the first place, see what is Base64 encoding.

What you are holding: a bare string or a data URI

Images turn up as text in two shapes. A bare Base64 string is just the characters, often starting with iVBORw0KGgo (a PNG) or /9j/ (a JPEG). A data URI is the same characters with a label in front, such as data:image/png;base64, followed by the string. Browser developer tools, CSS files, HTML emails and API responses mostly give you the second shape. The decoder accepts both, so you never need to cut the prefix off by hand.

What you pastedLooks likeWhat the decoder does
Bare stringiVBORw0KGgoAAAANS…Decodes it and identifies the file from its bytes
Data URIdata:image/jpeg;base64,/9j/4AAQ…Removes the prefix, then decodes the rest
URL-safe stringUses - and _ instead of + and /Recognised automatically, padded or not
Wrapped linesBroken into lines of 64 or 76 charactersLine breaks are ignored in the default mode

Converting Base64 to an image, step by step

1

Open the decoder

Go to the Base64 decoder. Leave Input format on Auto so it can detect a data URI by itself.

2

Paste the string

Paste the whole thing, prefix included, into the Base64 box. Anything up to 256 KB decodes as you paste; for larger input, press Decode. You can also drop a .txt or .b64 file that contains the string.

3

Check the preview and the Detected line

The result panel shows the format it found, the decoded size in bytes and, for images, a preview. If the Detected line says PNG, JPG, GIF, WebP, AVIF or similar, you have a real image.

4

Download

Press Download. The file is saved with the extension its own bytes call for, so a decoded PNG is saved as .png and opens with a double click.

Paste a string or data URI and download the image. Free: up to 25 MB of Base64, one input at a time, every format and view included. Pro: up to 20 inputs at once, downloaded as one ZIP. It all runs on your device, not our servers.

Decode Base64 to an image

How the image type is detected

Base64 says nothing about what it contains, so the tool reads the signature that almost every binary format starts with. Among images it recognises PNG, JPEG, GIF, WebP, BMP, ICO, TIFF, AVIF and HEIC. It also recognises PDFs, ZIP-based files such as DOCX, audio and video, and fonts, so you learn quickly if you were handed something other than a picture.

Decoded bytes begin withDetected asSaved as
89 50 4E 47 (the letters PNG)PNG image.png
FF D8 FFJPEG image.jpg
GIF87a or GIF89aGIF image.gif
RIFF … WEBPWebP image.webp
An opening <svg tagSVG, a text format.svg
Nothing recognised, no NUL bytesPlain text.txt

SVG is the odd one out. It is text, not binary, so it is identified from its opening tag and offered as an .svg file rather than shown as a picture preview. If a string decodes to readable XML mentioning svg, save it and open it in a browser.

Converting an image to Base64 or a data URI

1

Open the encoder

Go to the Base64 encoder and drop your image where it says to drop a file. Free handles files up to 25 MB, one at a time.

2

Choose the shape

Turn on Wrap as a data URI if the string is going into HTML or CSS. The media type is read from the file's own bytes and added to the prefix. A data URI has to be one unbroken line with the standard alphabet and padding, so the tool switches off URL-safe, wrapping and per-line mode for you and tells you it did.

3

Encode and copy

Press Encode, then copy or download the result. For a very large result only the first 32,768 characters are previewed on screen, but Copy and Download always give you the whole string.

Leave the data URI switch off when you want only the raw string, for example to put into a JSON field that an API will decode itself. If you want both directions on a single page, the combined Base64 encoder and decoder has them.

Common errors and how to fix them

When a string cannot be decoded, the tool does not just say invalid. It names the character position, the line and column, and the character itself, which is what lets you fix a string with thousands of characters.

MessageUsual causeFix
Not valid Base64A stray character such as a quote, a comma or a non-breaking space picked up when copyingGo to the reported position and delete the character
The string is truncatedPart of the string was cut off, often by a chat app, a spreadsheet cell or a text limitCopy the full value again from the source
Data after the = paddingTwo Base64 strings were joined togetherSplit them and decode each one separately
Decodes but is not an imageThe string holds a PDF, a ZIP or plain textRead the Detected line and use the matching format

URL-safe strings and whitespace

Some systems swap + and / for - and _ so the string can sit in a URL. You do not need to convert it back: the decoder recognises both alphabets, with or without the = padding at the end. Spaces and line breaks are stripped before decoding. Missing padding is added for you unless you turn on Strict mode, which refuses malformed input instead of repairing it. Leave strict mode off for ordinary recovery work.

One trap is a string that arrived percent-encoded, with %2B and %3D in place of + and =. That is a second layer of encoding on top. Run it through the URL decoder first, then decode the Base64.

When embedding an image as Base64 is a bad idea

Base64 writes four characters for every three bytes, so the text is about a third larger than the file, before the prefix and any line breaks are counted. A 1 MB image becomes roughly 1.37 MB of text. That is a fair price for a 2 KB icon and a poor one for a photograph.

SituationEmbed as Base64?Why
Small icon or bullet used on one pageYesSaves a request and nothing is large
Image in an email signature or Markdown fileOften yesThere may be nowhere to host a file
Photo or hero imageNoAbout 33% heavier, and the page cannot show anything until it has been downloaded
Image used on many pagesNoA separate file is cached once; embedded text is downloaded again with every page
Image that changes oftenNoEvery change invalidates the whole HTML or CSS file that contains it

The caching point matters most. A normal image file can be stored by the browser and reused on every page. An embedded one is part of the document, so it is fetched again whenever the document is. If you do embed an image, shrink it first with Compress Image so the text stays short.

Frequently asked questions

How do I convert a Base64 string to an image?

Paste the string into the Base64 decoder. It detects the image type from the decoded bytes, shows a preview and lets you download the file with the right extension, such as .png or .jpg. A data:image prefix is removed automatically.

Do I need to remove the data:image/png;base64, part first?

No. With Input format on Auto, the decoder recognises a data URI, strips the prefix and decodes the rest. Pasting the whole data URI is the easiest way.

How do I convert an image to Base64?

Drop the image into the Base64 encoder and press Encode. Turn on Wrap as a data URI if you need the data:image/...;base64, prefix for HTML or CSS. Free works with files up to 25 MB, one at a time.

Why does my Base64 string say it is truncated or invalid?

Usually part of the string was lost or an extra character crept in when it was copied. The error shows the exact position, line and column of the first bad character, and a truncated string means the end is missing, so copy the full value again.

Does the decoder handle URL-safe Base64 with - and _?

Yes. It recognises the URL-safe alphabet automatically, padded or unpadded. Whitespace and line breaks are ignored in the default mode.

Is embedding an image as Base64 good for page speed?

Only for tiny images. Base64 adds about a third to the size and the image cannot be cached separately, so photos and shared images are better served as normal files.

Keep reading

More in Documents →