What Is Base64 and When Should You Use It?
Base64 is not encryption. Here is what it does, where you see it, and how to encode and decode safely.
Sooner or later every developer meets a long string of letters ending in one or two equals signs. That is usually Base64, and it is often misunderstood.
What it does
Base64 turns binary data into plain text made of letters, digits, plus and slash. It lets you send an image or file through systems that only handle text, such as JSON, email or URLs. The price is size: the output is about a third larger than the input.
It is not encryption
Anyone can decode Base64 in a second. Never use it to hide a password. If something is "protected" only by Base64, it is not protected at all. Use the Base64 decoder to see how easily it opens.
Where you will see it
Images embedded in CSS or HTML as data URIs, email attachments, basic authentication headers and the parts of a JWT token. To make your own, use the Base64 encoder.
The URL-safe variant
Regular Base64 contains plus and slash, which have special meaning in URLs. The URL-safe form replaces them with minus and underscore. If you work with tokens, the Base64URL tool handles it. For ordinary query strings, URL encoding is the better choice.
When to avoid it
Do not embed large images in your CSS as Base64. They cannot be cached separately, and the page gets heavier. Small icons are fine.