Sooner or later every front-end developer meets a string that starts with data:image/png;base64,iVBORw0KGgo... and wonders whether they should be doing that too. Turning an image into Base64 text is easy. Knowing when it's a good idea is the useful part. This post covers what the conversion actually does, a worked example with real numbers, and a simple rule for when to use it.
What "image to Base64" really means
An image file is just bytes. Base64 is a way of writing any bytes using only 64 safe text characters (A–Z, a–z, 0–9, + and / , with = as padding). It works by taking 3 bytes (24 bits) at a time and splitting them into four 6-bit groups, each of which maps to one character.
So the conversion doesn't compress, resize or encrypt anything. It only changes how the same bytes are written down, so they can travel through places that expect text: HTML attributes, CSS files, JSON payloads, email bodies, or environment variables.
A quick way to see this: the three ASCII bytes of Man become TWFu .…