Base64 is a method of encoding binary data — images, audio, arbitrary byte sequences — into a string of 64 ASCII characters. It exists because many systems were designed to handle only text. When you need to pass an image through a JSON API, embed it in an HTML email, or store binary data in a text-only database, Base64 bridges the gap.
How it works
Base64 takes every 3 bytes of binary data and converts them into 4 printable characters (A–Z, a–z, 0–9, +, /). The encoded output is roughly 33% larger than the original binary data. For example, a 100 KB image becomes approximately 133 KB when Base64-encoded. The tradeoff is larger data in exchange for universal text compatibility.
Common use cases
- Data URIs in HTML/CSS: Embedding images directly in CSS or HTML as
data:image/png;base64,strings. Useful for small icons and inline assets that avoid an extra HTTP request, but not practical for large images due to the 33% size overhead. - Email attachments (MIME): The email protocol is text-based. Base64 encoding allows binary attachments to travel through email servers that would otherwise corrupt or strip binary data.
- API authentication: HTTP Basic Authentication sends credentials as
Authorization: Basic base64(username:password). This is not encryption — it is simply encoding so the credentials can travel as a text header. - Embedding in JSON: When an API endpoint does not support multipart file uploads, you can Base64-encode the file and include it as a string field in the JSON payload.
- Storing binary in text databases: Some systems that handle only text (certain logging frameworks, configuration files) can store Base64-encoded binary as a workaround.
When to avoid it
Base64 is not encryption — the encoded data is trivially reversible and provides zero security. Do not use it to hide sensitive information. It is also a poor choice for large files. The 33% size increase compounds quickly: a 10 MB video becomes 13.3 MB, which is wasteful when you could simply send the binary file through a system that supports it.
If you need to check or generate Base64 strings for development, a dedicated tool can handle the conversion without manual effort.