What Base64 is, and when to use it on a Mac
What the encoding does, where it came from, and how to try each of these ideas for yourself in B64 on your own Mac.
Base64 is a way of writing binary data using only printable characters. That is the whole idea. A picture is a sequence of bytes, and many of those byte values are not characters you can type, mail, or put inside a JSON string. Base64 takes those bytes and re-expresses them using a fixed set of 64 safe characters, so the file can travel anywhere text can travel.
How the encoding works
Three bytes of input — 24 bits — are split into four groups of six bits. Six bits can hold 64 values, and each value maps to one character from the alphabet A–Z, a–z, 0–9, + and /. When the input does not divide neatly into threes, the output is padded with one or two = characters, which is why so many Base64 strings end in an equals sign.
Two consequences follow from that, and they explain almost everything people find surprising about Base64:
- It is exactly reversible. No information is lost, so decoding returns the original file byte for byte — the same pixels, the same metadata, the same checksum.
- It is always bigger. Four characters out for every three bytes in is a fixed 33% increase, before any line breaks.
It is an encoding, not a cipher. Anyone who has the string can decode it with no key and no effort — including in this app, for free. Never treat a Base64 payload as a way of hiding anything.
Where it came from
Base64 was standardised as part of MIME in the early 1990s, to solve a specific problem: email was a text-only medium, and people wanted to send files. Mail systems of the day could mangle anything that was not plain, seven-bit text, so attachments had to be expressed as characters that would survive the journey.
That history is still visible. The 76-character line length offered when you encode is the MIME line limit. The 64-character width you see in certificates and key files comes from the same family of conventions. Both survive because the systems that expected them survive.
When turning an image into text is the right answer
Base64 is a means, not an end. It is the right tool when the destination can only take text, or when you want one file instead of two.
| Situation | Why Base64 helps | Format to use |
|---|---|---|
| An HTML email | Mail clients block remote images; an embedded one always shows | HTML |
| A single-file page or demo | No second request, nothing to host | Data URI |
| A stylesheet that must be self-contained | The asset travels with the CSS | CSS |
| A README or a spec | The screenshots cannot go missing later | Markdown |
| A JSON payload or an API field | A binary file inside a text protocol | Plain Base64 |
| A test fixture | A known image checked in alongside the test | Plain Base64 |
When it is the wrong answer
The 33% overhead is real, and it is paid every time the string is sent. A large photograph embedded in a page is downloaded with the page, cannot be cached separately, and cannot be skipped by a reader who never scrolls that far. For a big hero image on a public site, a normal image file usually wins.
The rule of thumb that survives contact with reality: embed the small things that must not go missing, and leave the big things as files.
The characters at the start tell you what it is
Because the encoding is deterministic, a file's header always produces the same opening characters. It is a quick way to recognise a payload on sight.
| Starts with | The file is |
|---|---|
iVBORw0KGgo | PNG |
/9j/ | JPEG |
R0lGODlh | GIF |
JVBERi0 | |
UklGR | WebP |
PHN2Zy or PD94bW | SVG |
You never have to memorise these. Paste the payload into B64 and it tells you the format, the dimensions and the size — and shows you the picture, which settles it faster than any table.
Try each of these
- See the overhead for a real file. Encode one of your own images and open the Inspector: it shows the character count and the exact percentage. How to see how much bigger Base64 makes a file.
- Prove it is lossless. Encode a file, decode the result, and compare the two SHA-256 checksums in the Inspector. They match, every time.
- Watch the padding appear. Encode files of slightly different sizes and look at the end of the string.
Frequently asked questions
Is Base64 a compression format?
No — it is the opposite. Base64 makes data about a third larger. It exists to make binary data safe to put in text, not to make it smaller.
Is Base64 secure?
No. It is an encoding, not encryption. Anyone with the string can decode it instantly and without a key. Never use it to conceal anything.
Why do Base64 strings end in = signs?
Padding. The encoding works on groups of three bytes; when the input does not divide evenly into threes, one or two equals signs are added so the output length is a multiple of four.
What do the 64 and 76 column options mean?
They are line lengths. Seventy-six is the MIME standard line length that Base64 was originally defined around; sixty-four is the older convention you see in certificates and key files. Either is decoded identically.
Does Base64 change my image quality?
Not at all. The encoded string represents the exact bytes of the original file, so decoding gives the identical image back — same resolution, same compression, same metadata.