About Base64
What is Base64?
Base64 is a binary-to-text encoding scheme that represents binary data using a set of 64 printable ASCII characters. It converts binary data into a string of letters (A-Z, a-z), digits (0-9), and two additional characters (+ and /). The = character is used for padding when the input length is not a multiple of 3 bytes.
Base64 was originally defined in RFC 1421 (Privacy Enhanced Mail) and is now widely used across the internet. It is the standard encoding for embedding images in HTML and CSS via data URIs, for transmitting binary data in JSON and XML, for encoding credentials in HTTP Basic Authentication, and for many other purposes.
It is important to understand that Base64 is an encoding, not encryption. Base64-encoded data can be easily decoded by anyone, so it should never be used as a security measure. If you need to protect sensitive data, use proper encryption algorithms like AES.
How Base64 Works
Base64 encoding works by dividing the input data into groups of 3 bytes (24 bits). Each group of 24 bits is then split into 4 groups of 6 bits. Each 6-bit value is mapped to one of the 64 characters in the Base64 alphabet. This means that every 3 bytes of input produce 4 characters of output, resulting in an approximately 33% increase in data size.
When the input length is not a multiple of 3 bytes, the encoding handles the remainder differently: one remaining byte produces 2 Base64 characters plus two padding characters (==), and two remaining bytes produce 3 Base64 characters plus one padding character (=). The padding ensures that the decoded output is always the same length as the original input.
Our tool handles the full UTF-8 character set, so you can encode and decode text in any language, including emoji and special characters. Internally, it first converts the text to UTF-8 bytes, then applies Base64 encoding, and vice versa for decoding.
Common Use Cases
Data URIs
Base64 is commonly used to embed small images, fonts, or other binary data directly in HTML or CSS files using data URIs. For example, a small icon can be embedded as data:image/png;base64,iVBORw0KGgo... without needing a separate file. This reduces HTTP requests and simplifies deployment.
API Payloads
Many APIs use Base64 to encode binary data in JSON or XML payloads. For example, when uploading images via a JSON API, the image data is typically Base64-encoded. Email attachments in the MIME format also use Base64 encoding to represent binary files in a text-based protocol.
Authentication
HTTP Basic Authentication encodes the username and password asbase64(username:password) and sends it in the Authorization header. While this is not secure on its own (it should always be used over HTTPS), it is a widely supported authentication mechanism.
Frequently Asked Questions
Is Base64 the same as encryption?
No. Base64 is encoding, not encryption. It is a reversible transformation that anyone can decode. It provides no security whatsoever. If you need to protect data, use encryption algorithms like AES-256 with a proper key management system.
Why does Base64 increase data size?
Base64 encodes 3 bytes of input as 4 characters of output, resulting in a 33% size increase. This is because 3 bytes equal 24 bits, which are split into 4 groups of 6 bits each, and each 6-bit group is represented by one character. The overhead is the tradeoff for using only printable ASCII characters.
Can I encode non-ASCII text like Chinese or emoji?
Yes. Our tool fully supports Unicode text. It first converts the text to UTF-8 bytes, then applies Base64 encoding. When decoding, it reverses the process, converting Base64 back to UTF-8 bytes and then to the original text. This works with any language and emoji.
What does "Invalid Base64 input" mean?
This error occurs when the input contains characters that are not valid Base64 characters (A-Z, a-z, 0-9, +, /, =), or when the padding is incorrect. Common causes include extra whitespace (though our tool strips whitespace automatically), line breaks from copy-pasting, or truncated data.
This tool is provided for informational purposes only. KnowKit is not responsible for any errors in the output.