Image to Base64 Converter

The left side is the image: drop a file onto it, or choose one from the bar below. The right side is those same file bytes as text. A data URL puts data:image/…;base64, in front of the payload; Base64 only is the text after the comma. The bar under the text switches between the two spellings.

Base64 turns file bytes into text a document can hold

Base64 maps every three bytes onto four characters from a 64-letter alphabet, so an image file can sit inside JSON, XML, or an HTML attribute. A data URL adds a media type in front of that text, which tells a parser what kind of image the bytes are. Turn the text back into a file with Base64 to image. After it is inside a tag, tidy the page in the HTML formatter.

The alphabet is A–Z, a–z, 0–9, plus, and slash. An equals sign at the end is padding. It is not a byte from the image.

What those characters actually encode

How three bytes become four Base64 characters

  1. Twenty-four bits are split into four indexes of six bits each.
  2. Each index picks one character from the 64-letter alphabet.
  3. A final group of one or two bytes is padded with = so the length is a multiple of four.
  4. The characters are ASCII text. The image bytes appear only after decoding.

What the prefix and the payload each mean in a data URL

  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.

Why the payload is the whole file and not a decimal of each pixel

  1. A PNG signature, a JPEG start-of-image marker, a GIF header, and a WebP RIFF chunk travel with the bytes.
  2. Transparency, animation frames, and compression tables are inside that file.
  3. Decoding restores those bytes bit for bit. It does not rebuild a table of red, green, and blue numbers.
  4. A PNG and a JPEG of the same picture are different byte strings, so their Base64 differs too.

Why the text is about one third longer than the file

  1. Each character carries 6 bits, so four characters cover three bytes. The ratio is 4/3.
  2. A 300 KB JPEG is about 400 KB of text before the data URL prefix.
  3. The prefix adds a few dozen characters and does not change the payload.
  4. Text nested in a page is not a separate response, so it does not get its own cache entry the way an image URL does.

Where the text has to stand in for the file

An img src or a CSS url()

The whole data URL is the value: scheme, media type, and payload. A raw payload has no media type, so the characters alone do not say whether the file is a PNG or a JPEG. Rules around that image belong in the CSS formatter.

A JSON field that stores the picture apart from its type

The payload is the field value. The type is another field, or a header. Putting the data: prefix into a field that expects only the alphabet duplicates the type.

Frequently asked questions

How do I convert an image to Base64 online?
Use the file picker or drag-and-drop on this page, wait for encoding to finish, then copy the output. Toggle raw Base64 vs data URL depending on whether your target needs the data:image/…;base64, prefix. PNG, JPEG, GIF, and WebP are supported.
What is the difference between Base64 and a data URL?
Base64 is only the encoded bytes as text. A data URL wraps that payload with a scheme and MIME type, e.g. data:image/webp;base64,XXXX. Browsers require the wrapper for inline img/CSS; REST APIs often want XXXX alone plus their own type field.
Which image formats can I encode?
PNG (lossless, transparency), JPEG (photos), GIF (animation or flat graphics), and WebP (modern compression). The MIME prefix in a data URL reflects the file you selected—image/png, image/jpeg, image/gif, or image/webp.
How is Base64 related to binary?
Images on disk are binary. Base64 maps every 3 bytes to 4 ASCII characters so the file can travel in JSON, XML, or HTML attributes. Decoding Base64 recreates the original PNG/JPEG/GIF/WebP bytes bit-for-bit—it is not a numeric conversion of pixel channels.
Why does the string look longer than the file size?
Base64 uses 6 bits per character and pads to multiples of four characters, so encoded length is roughly 4/3 of the original byte length. Data URLs add a few dozen characters for the prefix. A 300 KB JPEG often becomes ~400 KB of text.
Is there a file size limit?
There is no hard server cap because encoding runs in your session, but very large files consume memory and produce strings that are slow to paste into editors. A few megabytes is comfortable; multi-megabyte photos are better linked by URL.
Can I decode Base64 back to an image here?
This page encodes files to Base64 or data URLs. To paste Base64 or a data URL and preview or download the image, use the Base64 to image tool in the same convert section—it accepts raw payloads and full data:image/…;base64, strings.
Should I use Base64 images in production?
Large assets should stay on a CDN or static path so HTTP caching and image CDNs work. Base64 fits tiny UI icons, test fixtures, seeded demo data, and one-off documents. Measure HTML weight and Time-to-Interactive if you inline many images.