Base64 turns an image's raw bytes into text by encoding every three bytes as four characters, so a PNG, JPEG, GIF, or WebP file can be pasted into HTML, CSS, JSON, or email markup as a string instead of a separate file.
Most beginners arrive at Base64 with one of three jobs in mind: embedding a small icon in a stylesheet, sending an image inside a JSON API body, or dropping a picture into a document that only accepts plain text. Each of those jobs needs the same thing — the image's bytes represented as characters — and each begins with the same choice: do you want the raw Base64 text, or a complete data URL you can paste straight into an src attribute? The Image to Base64 Converter produces both, entirely inside your browser.

What Base64 Actually Does to Your File
An image file is just a sequence of bytes. Base64 rewrites that sequence as text using a fixed 64-character alphabet: uppercase letters, lowercase letters, digits, plus, and slash. The arrangement is defined in RFC 4648, which is also where the padding rule comes from — when the final group of bytes has fewer than three bytes in it, the encoder finishes with one or two equals signs so the character count always lands on a multiple of four.
Two misunderstandings are worth clearing up before you begin. First, Base64 is a transport encoding, not a compression format. Every three input bytes become four output characters, so the text is normally about a third larger than the file it came from. Second, Base64 conversion does not rewrite your image. The converter encodes the validated file's original bytes: it does not draw onto a canvas, resize, recompress, recolor, flatten transparency, strip metadata, repair damage, or optimize the file. Animated GIF and animated WebP bytes stay animated, because what gets encoded is the file as it was, not a single extracted frame.
Base64 is also not a substitute for ordinary image delivery. Inline strings add roughly a third to the payload and cannot be cached or served as a separate file the way a normal image URL can. Use Base64 where a text representation is specifically required — API payloads, JSON fixtures, HTML or CSS experiments, email templates, offline prototypes, test data, and debugging work — and keep ordinary image files for normal website delivery.
Plain Base64 or an Image Data URL?
These are the two output modes, and they differ in more than cosmetics. In plain mode you receive only the canonical Base64 characters and their padding, with no prefix. In data URL mode you receive a complete string beginning with data:, the detected MIME type, ;base64,, and then the payload. That MIME type is chosen from the verified file bytes, which is why a PNG renamed to photo.jpg still produces a data URL starting with data:image/png;base64, rather than the JPEG prefix its name suggests.
| What you're choosing | Plain Base64 | Image data URL |
|---|---|---|
| What you get | Base64 characters plus terminal padding only | A full data:image/...;base64, string including the prefix |
| Where the MIME type comes from | Not included in the output | Read from the file's verified bytes, never from the filename |
| Typical beginner jobs | JSON fixtures, API payloads, test data, stored image strings | CSS backgrounds, HTML image sources, email templates, offline prototypes |
| Things to watch | You add the prefix yourself if the consumer needs one | The prefix counts toward the maximum accepted output length |
Neither mode changes the payload itself. If your goal is a copy-and-paste value for a stylesheet or an <img> tag, data URL mode saves you from typing the prefix. If you are building a JSON body or storing an image as a field, plain mode keeps the stored value strictly to the encoded bytes.
Convert Your First Image, Step by Step
- Open the Image to Base64 Converter in your browser. There is nothing to install, sign up for, or download.
- Choose one local file. The converter accepts PNG, JPEG, GIF, and WebP, one file at a time, and selects it from your device.
- Select your output mode: plain Base64 for the raw characters, or an image data URL for the complete prefixed string.
- Run the conversion and read the confirmation panel. The tool reports the byte format it detected, the real decoded pixel dimensions, the file size, and a preview of the image.
- Check that the detected format is the one you expected and that the preview looks correct. No result is produced until the browser has successfully decoded the file and reported positive dimensions.
- Copy the complete output and paste it where you need it. In data URL mode, copy the whole string including the prefix.
The file is read, validated, encoded, previewed, and copied inside the current browser tab. It is not uploaded and it is not sent to an external conversion service, and temporary object URLs are released when the result changes or the tool closes.
One behavior surprises people the first time they use it: choosing another file or switching output mode immediately clears the previous preview, output, error message, and copy status. If you want both versions, copy one before changing the other. Clipboard permission can also be refused by the browser; in that case the visible output stays on screen and you can select and copy it manually.
The Checks That Run Before Any Output Appears
The converter does not trust the filename extension, the file picker's accept filter, or the MIME string your operating system reports. Those are hints that can be stale or deliberately misleading. Format detection reads the actual bytes and requires complete containers, not just a matching header: a PNG needs its full eight-byte signature, a correctly shaped first IHDR chunk, and a terminal IEND boundary; a JPEG needs to start with SOI and a following marker and end with EOI; a GIF needs a GIF87a or GIF89a header, enough bytes for its logical screen descriptor, and a terminal trailer; a WebP needs a RIFF length that exactly matches the file, the WEBP FourCC, and a bounded first chunk. Bare magic bytes and truncated containers are rejected.
Structural checks alone are not enough, so a second pass happens: the file must be decoded by the browser itself and report positive dimensions before any result is displayed. A corrupt payload that merely resembles a known header therefore cannot produce an apparently successful string.
Several hard limits apply to the input. The file must be exactly 5,242,880 bytes (5 MiB) or smaller; the exact boundary is accepted and one byte beyond it is rejected before the file body is even read, and the length of the buffer actually read is checked again. After decoding, neither edge may exceed 20,000 pixels, and total pixel area may not exceed 40,000,000 pixels — a compressed file can occupy far more memory once decoded than its size on disk suggests. The final text output may reach 6,990,531 characters. Nothing is quietly trimmed: oversized inputs produce an explicit error and no partial result.
If you want to see exactly how the format is decided from bytes, the companion piece on detecting the real image format from bytes walks through the container rules in more detail.
How Large the Text Output Will Be
The size of the result follows directly from the size of the file. The formula is:
Base64 characters = 4 × (file bytes ÷ 3, rounded up)
Worked with the maximum accepted file: 5,242,880 ÷ 3 = 1,747,626 remainder 2, which rounds up to 1,747,627 groups. Multiplying by four characters per group gives 4 × 1,747,627 = 6,990,508 Base64 characters. Add the longest supported data URL prefix, data:image/webp;base64, at 23 characters, and 6,990,508 + 23 = 6,990,531 characters, which is the maximum output length the converter accepts. A file of that size also pushes against the decoded-dimension limits, so the practical ceiling for a large image is often well below the byte cap.
Small images stay small. A logo of a few kilobytes turns into a string of a few thousand characters, which is exactly the kind of asset that reads comfortably inside a stylesheet or a JSON fixture. That is the practical reason to reach for Base64 in the first place: the text stays small enough to paste.
Where Beginners Use Base64 in Real Work
Once you have a copied string, the next step depends on where it is going. The table below maps common beginner jobs to the output mode that fits and the thing to verify afterwards.
| What you're building | Output mode | How to apply it |
|---|---|---|
| A stylesheet with an inline image | Data URL | Paste into a rule such as background-image: url("data:image/png;base64,…"); and confirm the preview in the browser |
| An HTML page with an inline image | Data URL | Use the whole string as the src value, then reload and confirm the image renders |
| A JSON API body or stored fixture | Plain Base64 | Put the string in a text field and confirm the receiving code treats it as text, not binary |
| An email template or offline prototype | Data URL | Embed the value, then open the result in the client or app that will actually display it |
| Round-tripping back to a file | Either | Use the reverse converter to turn a Base64 image string back into a validated file you can download |
Testing in the place it will actually be used matters more than it sounds. The converter's preview proves the bytes decode into a real image; it cannot prove that your mail client, your API schema, or your browser will accept the resulting string. Open the finished page, send the finished request, or load the finished template and check the result there.
To go back the other way, the Base64 to Image Converter takes a strict Base64 image string, validates it, and shows a preview you can download.
Mistakes Beginners Make and How to Avoid Them
- Expecting a smaller file. Base64 adds roughly a third to the payload, so encoding is never the way to shrink an image. If size is the goal, compress the file first with the Image Compressor, then encode the result.
- Renaming a file to change its format. Renaming photo.png to photo.jpg changes nothing inside the bytes. The converter keeps reading the actual bytes, so the detected format and the data URL MIME type stay correct regardless of the name.
- Assuming unsupported formats work. SVG, AVIF, HEIC, BMP, TIFF, PDF, and arbitrary text are outside the supported set of PNG, JPEG, GIF, and WebP, even when a browser or a file extension calls them images. Convert to a supported format first if you need one of those.
- Expecting a resized or optimized result. The payload represents the original file bytes exactly. If you need different dimensions, resize the image first with the Image Resizer, then encode it — that keeps each step predictable.
- Reading the preview as the output size. The preview is constrained so it fits the page layout. It tells you the image decoded correctly, not how large the string will be.
- Assuming a successful decode means the content is safe. Successful decoding verifies technical readability only. It says nothing about authorship, truthfulness, accessibility, copyright status, moderation safety, or hidden data.
Where to Go Next
Once your first conversion works, two paths usually come next. If your work is script-shaped rather than click-shaped, the guide on converting an image to Base64 without writing Python code shows how the same local, no-upload approach fits into a program. And if the goal is the reverse direction, the Base64 to Image Converter turns a Base64 image string back into a validated, downloadable file.
Keep the steps separated and each one stays honest: compress when you want a smaller file, resize when you want new dimensions, and convert to Base64 when you specifically need the image as text.