A broken image icon where your picture should be, and no error message to explain it. That is the standard experience when a base64 image fails: browsers render data URLs silently or not at all, and a string thousands of characters long offers no obvious place to look.

The good news is that the list of possible faults is short. A data URL has a strict shape, and nearly every failure is one part of it gone wrong: the prefix, the image type, the marker, or the payload itself. This guide walks through each one, and shows how the free Base64 Image Encoder and Decoder on Ovatly doubles as a diagnostic tool: its decoder checks the whole shape and tells you which part failed.

Contents

  • Quick answer
  • The shape a data URL must have
  • Mistake 1: the prefix
  • Mistake 2: the image type
  • Mistake 3: the ;base64, marker
  • Mistake 4: the paste lost characters
  • Mistake 5: spaces, or not an image
  • How to diagnose a broken string, step by step
  • Worked example: checking a healthy payload
  • Limitations and honest tradeoffs
  • Common mistakes, summarised
  • FAQs
  • Conclusion
  • References

Quick answer

When a base64 image does not display, check the string against the required shape: it must start with data:, name an image type such as data:image/jpeg;base64,, include the ;base64, marker, and the payload must be complete, untruncated base64 with no stray spaces or line breaks. The quickest way to find the fault is to paste the string into the decoder of the Base64 Image Encoder and Decoder: its rejection message names the part to fix.

The shape a data URL must have

A working image data URL looks like this:

data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAA...

Four parts do the work. The data: prefix announces embedded data, not an address. The image/jpeg part names the content type, so the browser knows how to interpret the bytes. The ;base64, marker says the payload is base64 encoded and marks where it begins. Everything after it is the payload: the image written as text, 4 characters for every 3 bytes of the original file. Every mistake below is one of these parts failing.

Mistake 1: the prefix is missing or wrong

The most common failure is also the simplest: the string does not start with data:. This happens when someone copies only the payload, or pastes a base64 string into an src attribute and expects the browser to guess. It will not guess: without the prefix, the browser treats the string as a relative address and looks for a file with a very long name.

Typos do the same damage. The Ovatly decoder rejects text that does not start with data:, with an explanation, which is why feeding it a suspect string is such a useful first test.

Mistake 2: the named image type does not match

The type in the prefix is a claim about the payload, and browsers act on it. A PNG payload introduced as data:image/jpeg;base64, asks the browser to decode PNG bytes with JPEG rules. Some browsers forgive this; many do not, and forgiveness is not a standard to rely on.

This mistake appears when a data URL is edited by hand, or a template written for one format is reused for another. Make the prefix tell the truth: data:image/png;base64, for PNG data, data:image/jpeg;base64, for JPEG. If you no longer know what the payload really is, decode it with the tool and let the preview settle it.

Mistake 3: the ;base64, marker is missing

The marker is easy to lose because it looks like punctuation clutter. Without ;base64,, the browser reads the payload as plain text rather than base64, and base64 characters are not a readable image in that form. Watch for near misses: a semicolon without the comma, or a space before the payload. The shape is exact: semicolon, the word base64, comma, then the payload immediately.

Mistake 4: the paste lost characters

Base64 payloads are long, and long strings get damaged in transit. A copy that stops a few characters early, a string a chat window or document quietly truncated, a selection that missed the final characters: all produce a string that looks right and is not.

This fault is unforgiving because of how decoding works. A data URL decoded on Ovatly is rebuilt byte by byte on your device, and a single missing character changes or breaks the result. There is no error correction. If a string used to work and now does not, suspect the copy, not the image: re-encode the original file.

Mistake 5: spaces in the copy, or not an image at all

Contamination is the other copy fault. Strings copied out of emails, PDFs and wrapped terminal output often pick up line breaks or spaces mid-payload. The valid base64 alphabet includes no spaces, so a decoder checking the character set rejects the string, and a browser may fail silently. The reliable fix is the same as for truncation: copy cleanly from the original, ideally from a text file rather than fragile copied text.

One boundary case: this decoder only decodes base64 data URLs for images. Plain base64 without the data: prefix is rejected, and so are non-image types, and the rejection message says so. If your string is not an image, no prefix repair will help.

How to diagnose a broken string, step by step

  1. Open the Base64 Image Encoder and Decoder and switch it to the decoding direction.
  2. Paste your data URL and click Decode to image. Either a preview appears, proving the string is healthy, or the string is rejected.
  3. Read the rejection message. It names the shape that failed: the data: start, the image type, the ;base64, marker, or the character set. Fix that part.
  4. If the message points at the payload, treat the copy as damaged: re-encode the original image and use the fresh string.
  5. Download the working data URL as a text file so it survives transport intact.

Worked example: checking a healthy payload

The tool's own example gives you a reference point for what correct looks like. Base64 always expands data by a factor of 4/3, so a 30,000 byte JPEG becomes about 40,000 base64 characters, plus the short prefix data:image/jpeg;base64,. If your string for a similar file is far shorter than that ratio predicts, it has almost certainly been truncated, and no prefix fix will save it.

The small end of the scale is just as useful: the payload QUJD decodes to exactly 3 bytes, the letters ABC. Pasting a tiny known-good string like that into the decoder confirms the tool works, isolating the fault to your long string.

Limitations and honest tradeoffs

A decoder can validate shape and rebuild bytes; it cannot recover data that never arrived. A truncated payload is missing real bytes, and the only fix is a clean copy from the source. If the decoder previews the image correctly, the fault is in the surrounding code of your page, and the string is exonerated. Keep the size question in view, too: for large images, our companion guide on when base64 embedding helps and when it slows your page explains why a regular file is often the better fix.

Common mistakes, summarised

  • Copying the payload without the prefix. The browser needs data: and the type, every time.
  • Trusting a long string that travelled through chat or email. Truncation and line breaks are routine.

FAQs

Why does my data URL show a broken image icon? Usually because the string breaks the required shape somewhere: the data: prefix is missing or mistyped, the named image type does not match the payload, the ;base64, marker is absent, or the payload was damaged in copying. Browsers give no detailed error, they just fail to render.

What happens if one character is missing from the string? The image is rebuilt byte by byte from the payload, so one missing character shifts or corrupts the data it belongs to. Depending on where the loss happens, the image renders wrong or not at all. Long strings copied through chat or email are especially prone to silent truncation.

Can I decode plain base64 without the data: prefix? Not with this decoder. It only accepts base64 data URLs for images, and plain base64 without the prefix is rejected with an explanation. Add the correct prefix for the image type, or re-encode the original file.

Why did the decoder reject my text? It checks the full shape: the text must start with data:, name an image type, include ;base64, and contain only valid base64 characters. The error message tells you which shape to check, so read it as a pointer to the exact problem.

Is anything uploaded when I test a string in the decoder? No. Reading and decoding happen entirely in your browser, on your device. You can test broken strings as often as you like.

Conclusion

A base64 image that will not display is failing one of four shape checks. Work through the prefix, the type, the marker and the payload in that order, and let the Base64 Image Encoder and Decoder do the checking for you: its rejection messages name exactly these faults. When in doubt, re-encode from the original file. For more guides in this series, see our Image Tools guides.

References