In this article
What Is Base64?
Base64 is an encoding scheme that converts binary data into a string of ASCII characters. It uses 64 safe characters (A-Z, a-z, 0-9, +, /) to represent any binary data, making it safe for transmission over text-based protocols like HTTP headers, email (MIME), and JSON.
Base64 is not encryption — it is encoding. Anyone can decode Base64 back to the original data without any key. The purpose of Base64 is to allow binary data to pass through systems designed for text, not to provide security.
How Base64 Encoding Works
Base64 converts each group of 3 bytes (24 bits) into 4 Base64 characters (6 bits each), padding with = characters if the input is not divisible by 3.
- Byte grouping — input bytes are grouped in sets of 3 and converted to 4 output characters
- Character mapping — each 6-bit group maps to one of 64 printable ASCII characters
- Padding — = characters are added to ensure output length is always a multiple of 4
Try it free — no signup required
Encode or Decode Base64 →When To Use Base64
Base64 is used whenever binary data needs to be embedded in text-based formats.
- Email attachments — MIME encoding uses Base64 to attach binary files to email messages
- Data URIs — embed images directly in HTML/CSS as data:image/png;base64,... to avoid HTTP requests
- API authentication — Basic Auth credentials are Base64-encoded in the Authorization HTTP header
Frequently Asked Questions
Does Base64 increase data size?
Yes. Base64 encoding increases size by approximately 33% because every 3 bytes of input produce 4 bytes of output. This is an inherent trade-off of making binary data text-safe.
What is the difference between standard Base64 and URL-safe Base64?
Standard Base64 uses + and / which have special meanings in URLs. URL-safe Base64 (Base64url) replaces + with - and / with _ to produce strings safe for use in URLs and filenames without percent-encoding. JWTs use Base64url encoding.
How do I handle Base64 with non-UTF8 data?
Base64 works with raw bytes, not text. When encoding binary data like images or encrypted content, treat it as a byte array rather than a string. In JavaScript, use Uint8Array or Buffer; in Python use bytes objects to avoid encoding issues with non-UTF8 data.