What is Base64 Encoding?
Base64 is a binary-to-text encoding scheme that converts binary data into an ASCII string format. It's commonly used to transmit data over media that are designed to deal with textual data, such as embedding images in HTML or sending binary files via email.
Key Features of Base64
Not Encryption
Base64 does not provide confidentiality — it just encodes data.
Alphabet
Uses A–Z, a–z, 0–9, +, and /.
Padding
Output is padded with =
to make it a multiple of 4 characters.
Readable
Encoded result is plain text and safe for most text-based systems.
Common Use Cases
Embedding Binary Files
Embedding binary files in XML or JSON.
HTML/CSS Data
Sending image or font data in HTML/CSS.
Email Attachments
Email attachments (MIME).
Simple Obfuscation
Simple obfuscation of data in URLs or tokens.
How Base64 Works
Base64 breaks input data into 3-byte chunks (24 bits) and splits each chunk into four 6-bit groups. Each 6-bit group maps to one character in the Base64 alphabet.
- 3 bytes (24 bits) → 4 Base64 characters
- 1 byte → 2 padding
=
- 2 bytes → 1 padding
=
This ensures the encoded output is always a multiple of 4 characters. Padding helps decode correctly when original data isn't divisible by 3.
Example Encodings
Input | Base64 Output |
---|---|
Hello | SGVsbG8= |
Hi! | SGkh |
✓ | 4pyT |