Where does Base64 code turn up?
Base64 writes a file using only letters, digits and a couple of symbols. That is why images often travel as text — and sooner or later you need to turn that text back into a picture. The most common cases:
- API and JSON responses. Services that generate images, scan documents or capture signatures often return the picture as Base64 inside a JSON field.
- HTML and CSS sources. When you want a logo, icon or background embedded in a page as a separate file.
- Raw email source. In the raw form of an email, attachments and inline images sit there as blocks of Base64.
- Databases and settings files. Some apps store profile photos or thumbnails in a text column.
- Debugging. To check that the Base64 your code produces really gives the right picture.
Step-by-step help for finding and copying the code is in How do you save Base64 code as an image file?. To go the other way and turn a picture into Base64 text, use Image to Base64.
Which types are recognised?
| Type | Code usually starts with | Saved as |
|---|---|---|
| PNG | iVBORw0KGgo | .png |
| JPG | /9j/ | .jpg |
| GIF | R0lGOD | .gif |
| WebP | UklGR | .webp |
| SVG | PHN2Zy or PD94bWwg | .svg |
| ICO | AAABAA | .ico |
| BMP | Qk | .bmp |
| AVIF | something like AAAAHGZ0eXBhdmlm | .avif |
These openings also help you tell at a glance what a piece of code is: text starting with /9j/ is almost always a JPG photo.
If something goes wrong
"This is not valid Base64 code." The code was most likely copied only in part. The end of a long text is easy to cut off, so make sure you selected all of it at the source. If other text got mixed into the middle, remove that too.
The picture looks half-finished or grey. The code decodes, but its end is missing. With JPG this shows up as a blank lower part of the picture. Copy the code again, in full.
The picture looks tiny. Embedded images are often icon-sized; the size in pixels is shown underneath. Enlarging won't add detail, but if you need to, use Resize image.