Base64 to Image Converter

Paste a data URL or raw Base64 on the left. The picture on the right updates as you type. A data URL names the type in data:image/…;base64,; raw Base64 has no prefix, so the type comes from the file header after decoding. Download uses the type that header names.

Decoding turns four characters back into three bytes

Each Base64 character carries 6 bits. Four characters make 24 bits, which split back into three bytes. A data URL writes the media type in front of that payload. Without the prefix, the type has to be read from the file header those bytes begin with. Turn a file into this text with Image to Base64.

A trailing = is padding. It is not a byte from the image. A character outside the alphabet, or a length that is not a multiple of four, cannot be turned back into bytes. After the bytes are an image again, the tag around them can be tidied in the HTML formatter.

How the restored bytes name the picture

How four Base64 characters become three bytes

  1. Each character is an index from 0 to 63 in the alphabet A–Z, a–z, 0–9, plus, and slash.
  2. Four indexes join into 24 bits.
  3. Those bits are cut into three bytes of 8 bits each.
  4. One trailing = means the last group was one byte short. Two mean it was two bytes short.

What a data URL prefix already says before the bytes are read

  1. The scheme is data:.
  2. The media type is image/png, image/jpeg, image/gif, or image/webp.
  3. ;base64, marks the payload as Base64 rather than percent-encoded bytes.
  4. The text after the comma is the same payload as raw Base64. The prefix only names the type.

How the file header names the picture when there is no prefix

  1. PNG begins with the bytes 89 50 4E 47.
  2. JPEG begins with FF D8 FF.
  3. GIF begins with the ASCII text GIF87a or GIF89a.
  4. WebP is a RIFF container whose bytes at offset 8 are WEBP.
  5. If none of those headers match, the text is not one of these four pictures.

Why the file is shorter than the text, and why padding is not a byte

  1. The ratio reverses to 3/4: three bytes were stored as four characters.
  2. About 300 KB of payload text becomes about 225 KB of file, before removing a data URL prefix.
  3. The prefix never enters the file. It only named the type.
  4. = pads the length and is dropped when the bits are cut. Spaces and line breaks are not in the alphabet, so they have to be removed before the indexes line up.

Where the text is standing in for a file

An img src that holds the whole data URL

The value needs the scheme, the media type, and the payload. The payload alone has no type, so a parser cannot tell a PNG from a JPEG by the characters. Rules around that image belong in the CSS formatter.

A JSON field that stores only the payload

The field value is the alphabet, padding included. The type is another field, or the file header after decoding. Joining the data: prefix onto that field and then decoding treats the prefix as characters outside the alphabet.

Frequently asked questions

How do you turn Base64 back into an image?
Four characters become three bytes. A data:image/…;base64, prefix already names the type. Raw text has no prefix, so the type is the PNG, JPEG, GIF, or WebP header at the start of those bytes.
Does a data URL decode to the same bytes as raw Base64?
When the payload matches, the bytes match. The data URL writes the media type before the comma. Raw text needs the file header to tell a PNG from a JPEG.
Which image formats can those bytes be?
PNG, JPEG, GIF, and WebP. The media types are image/png, image/jpeg, image/gif, and image/webp. Any other header is not one of these four.
Should the trailing equals signs stay?
Yes. One = means the last group was one byte short. Two mean it was two bytes short. The signs are not image data, and decoding drops them. Removing them leaves a length that is not a multiple of four.
Why does Base64 image decoding fail?
The usual causes are a character outside the alphabet, a cut that leaves a length other than a multiple of four, or bytes that do not start with a PNG, JPEG, GIF, or WebP header. Spaces and line breaks can be removed first. They are not part of the alphabet.
Why is the image smaller than the Base64 text?
Four characters cover three bytes, so the file is about three quarters of the payload text. The data URL prefix does not enter the file.
What do the PNG, JPEG, GIF, and WebP headers look like?
PNG starts with 89 50 4E 47. JPEG starts with FF D8 FF. GIF starts with GIF87a or GIF89a. WebP is a RIFF container with WEBP at byte offset 8.
Does encoding the file again produce the same string?
The same file bytes produce the same payload. A data URL also puts the media type in front. A different compression or a different format is a different byte string, so the text differs too.