What Is Base64 Encoding and When Should You Use It?
Base64 encoding converts binary data into a set of 64 printable ASCII characters. It is not encryption, not compression — it is a transport format.
How It Works
Every 3 bytes (24 bits) of input become 4 Base64 characters (6 bits each, mapped to A-Z, a-z, 0-9, +, /). If the input is not a multiple of 3 bytes, padding characters (=) are added at the end. This is why Base64 output is always about 33% larger than the input.
Common Use Cases
- Data URIs: Embed images or fonts directly in CSS or HTML using
data:image/png;base64,.... Reduces HTTP requests but increases file size. - Email attachments (MIME): Email protocols were designed for text. Base64 encodes binary attachments so they survive the journey.
- JSON Web Tokens: The header and payload of a JWT are Base64-encoded JSON. Use the JWT Decoder to inspect them.
- API authentication: Basic Auth sends
username:passwordas a Base64 string in the Authorization header. - Storing binary in text-only formats: Config files, XML, and databases that only support text can store binary as Base64 strings.
Try It Yourself
Open the Base64 Encoder. Type any text, click Encode, and see the Base64 output. Paste a Base64 string and click Decode to get the original back. Everything runs in your browser — the data never leaves your computer.
When Not to Use Base64
Do not use Base64 for hashing (use SHA-256 instead) or for encryption (Base64 is trivially reversible). Do not inline large files as Base64 data URIs — the size overhead and lack of caching make it a poor choice for images bigger than a few kilobytes.