What is Base64? — Encoding Explained
Definition
Base64 is a binary-to-text encoding scheme that represents binary data using a 64-character ASCII alphabet (A–Z, a–z, 0–9, +, /). It was designed to safely transmit binary content over channels that were originally built to handle only printable text, such as email and early HTTP. The name comes from the fact that each encoded character represents exactly 6 bits of the original data, and 2^6 = 64.
How It Works
Base64 encoding works by taking 3 bytes (24 bits) of input at a time and splitting them into four 6-bit groups. Each group is then mapped to a corresponding character in the Base64 alphabet. If the input length is not divisible by 3, one or two = padding characters are appended to make the output length a multiple of 4. Decoding reverses the process: each Base64 character is converted back to its 6-bit value, the groups are reassembled into bytes, and padding is removed.
Common Use Cases
- ▸Embedding images and fonts directly in HTML or CSS as data URIs
- ▸Encoding binary attachments in email (MIME format)
- ▸Passing binary data in JSON payloads where raw bytes are not valid
- ▸Storing cryptographic keys and certificates in PEM files
- ▸Encoding authentication credentials in HTTP Basic Auth headers
Example
Input: "Hello" Base64: "SGVsbG8=" Input bytes: 0x48 0x65 0x6C 0x6C 0x6F Binary groups: 010010 000110 010101 101100 011011 000110 111100 (padded) Characters: S G V s b G 8 =
Related Tools
FAQ
- Does Base64 encrypt my data?
- No. Base64 is encoding, not encryption. It is easily reversible by anyone without any key. Never rely on Base64 for security — use it only when you need to represent binary data as text.
- Why does Base64 increase file size?
- Every 3 bytes of input are represented as 4 Base64 characters, which is a 33% size increase. This is the trade-off for making binary data text-safe.
- What is URL-safe Base64?
- URL-safe Base64 replaces + with - and / with _ to avoid conflicts when Base64 strings appear in URLs or filenames. The = padding may also be omitted.