Enter text to convert to Base64
Hello World
{"name":"John","age":30}
!@#$%^&*()_+
こんにちは世界
Base64 encoding works by converting every 3 bytes (24 bits) of binary data into 4 ASCII characters (6 bits each):
1. Divide the input into 3-byte (24-bit) chunks
2. Convert each 3-byte chunk into four 6-bit values (4 × 6 = 24 bits)
3. Map each 6-bit value to a character in the Base64 alphabet
4. If the final chunk has fewer than 3 bytes, add padding '=' characters to maintain 4-character alignment
When encoding the word "Man":
M = 77, a = 97, n = 110
01001101 01100001 01101110
These 24 bits are regrouped into four 6-bit chunks: 010011 010110 000101 101110
Each 6-bit value corresponds to a Base64 character: T W F u
So, "Man" in Base64 is "TWFu"
Base64 encoding is used in various applications and technologies:
Small images can be embedded directly in HTML or CSS using data URLs to reduce HTTP requests:
When binary data needs to be included in JSON responses, Base64 encoding is often used since JSON doesn't support binary data directly.
JWTs use Base64URL encoding (a URL-safe variant of Base64) to encode JSON payloads in authentication tokens.
Base64 is sometimes used to encode file data for upload in environments where binary uploads aren't well-supported.
Base64 is an encoding scheme, not encryption. It provides no security or confidentiality.
Base64 encoding increases data size by approximately 33%, impacting bandwidth and storage efficiency.
When encoding text, UTF-8 encoding is typically applied first to handle international characters properly.
In JavaScript, you can use these built-in functions for Base64 encoding and decoding:
// Encoding (handle UTF-8 properly)
const encoded = btoa(unescape(encodeURIComponent('Hello World')));
// Result: SGVsbG8gV29ybGQ=
// Decoding (handle UTF-8 properly)
const decoded = decodeURIComponent(escape(atob('SGVsbG8gV29ybGQ=')));
// Result: Hello World