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:
- 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 Uses:
- Embedding binary files in XML or JSON
- Sending image or font data in HTML/CSS
- Email attachments (MIME)
- 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.
Security Notes
Pros:
- Encodes binary safely in text systems
- Widely supported in web and email standards
- Easy to implement and decode
Cons:
- Not secure — anyone can decode it
- Increases size by ~33%
- Can expose sensitive data if used improperly
Example Encodings
Input | Base64 Output |
---|---|
Hello | SGVsbG8= |
Hi! | SGkh |
✓ | 4pyT |