At some point every developer discovers Base64 and has approximately the same reaction:
“Wait. I can turn the entire file into text?”
Yes. An image can become text. A PDF can become text. A tiny icon can become an intimidating wall of characters:
iVBORw0KGgoAAAANSUhEUgAA...Magic? Not really. Encoding.
And it comes with a bill paid in payload size and memory.
Computers do not need Base64 to understand files
JPEG, PDF and MP3 files are already bytes. Computers are perfectly happy with bytes. Base64 becomes useful when binary data has to travel through something that prefers text: JSON, certain protocols, embedded HTML or CSS, data URLs and some APIs.
Why Base64?
A common Base64 alphabet contains 64 symbols. Since 2^6 = 64, each character represents 6 bits.
Normal bytes contain 8 bits, producing the classic relationship:
3 bytes = 24 bits
24 bits = 4 Base64 charactersThat immediately creates the famous cost.
It gets larger by about one third
4 / 3 ≈ 1.33A 3 MB block of data may become roughly 4 MB of Base64 text before surrounding JSON or other framing is added. Transport compression can sometimes reduce the practical network penalty, but the encoding itself did not become smaller.
Data URLs make it look especially magical
<img src="data:image/png;base64,iVBORw0...">The image is embedded directly instead of fetched from a separate URL. That can be useful for tiny icons, placeholders or self-contained documents.
Put a huge photograph there and your page source becomes an archaeological site where finding the closing quote is now fieldwork.
Memory is where browser apps get interesting
A user selects an 8 MB JPEG. Your app reads it, creates Base64, decodes it for preview and draws it to a canvas. Memory may temporarily contain the original file, a binary buffer, the Base64 string, decoded pixels and one or more preview copies.
A compressed JPEG may be only a few megabytes, but a decoded 4000 × 3000 RGBA image can require roughly:
4000 × 3000 × 4 = 48,000,000 bytesbefore counting the other copies.
This is why an image feature that feels harmless on a desktop can freeze a phone. Your 8 MB photo invited its entire family into memory.
Blob URLs are often better for local previews
const url = URL.createObjectURL(file);
image.src = url;When finished:
URL.revokeObjectURL(url);The browser can refer to the existing Blob without first manufacturing a giant Base64 string. Less copying, less drama.
Base64 is not encryption
This deserves permanent emphasis: Base64 does not provide secrecy.
hello may become aGVsbG8=. It looks less readable. It is not more secure.
Encoding changes representation. Encryption protects information using cryptographic keys.
A password hard-coded in Base64 is still a hard-coded password. It is simply wearing sunglasses.
When Base64 makes sense
- An API explicitly requires it.
- Binary data must fit inside a text-only format.
- A tiny resource belongs in a data URL.
- A protocol defines Base64 as part of its format.
Large uploads, videos, batches of images and long-term file storage usually fit Blob uploads, multipart forms or streaming better.
The final lesson
Base64 does not compress a file. It does not encrypt it. It does not turn data into a secret internet substance.
It represents binary information using a restricted set of text characters.
That is incredibly useful.
Just remember the trade: compatibility with text in exchange for more data and sometimes more memory.
The next time you see a 12,000-character image inside JSON, do not panic.
Your PNG is simply wearing a very expensive costume.