What is Base64? Complete Guide with Examples

3 min readdeveloper

Base64 is a binary-to-text encoding scheme that represents binary data using 64 ASCII characters (A-Z, a-z, 0-9, +, /) plus = for padding. It converts every 3 bytes of binary data into 4 ASCII characters, increasing size by approximately 33%. Base64 enables binary data (images, files, encrypted content) to be safely transmitted through text-only channels like email, JSON, XML, and URL parameters.

Try It Yourself

Use our free Base64 Encoder/Decoder to experiment with base64 encoding.

How Does Base64 Encoding Work?

Base64 encoding takes groups of 3 bytes (24 bits) and divides them into 4 groups of 6 bits each. Each 6-bit value (0-63) maps to a character in the Base64 alphabet. If the input isn't a multiple of 3 bytes, padding characters (=) are added to make the output a multiple of 4 characters. Decoding reverses the process: each character maps back to its 6-bit value, groups of 4 are combined into 3 bytes. Base64URL is a variant that replaces + with - and / with _ for URL-safe encoding.

Key Features

  • Encodes any binary data into safe ASCII text using 64 printable characters
  • Deterministic encoding — same input always produces the same output
  • Base64URL variant for URL-safe encoding without special characters
  • Padding with = to ensure output length is always a multiple of 4
  • Universal support across all programming languages and platforms

Common Use Cases

Data URIs

Images and fonts can be embedded directly in CSS/HTML using Base64-encoded data URIs: data:image/png;base64,... This eliminates extra HTTP requests for small files at the cost of increased file size.

Email Attachments (MIME)

Email protocols (SMTP) were designed for 7-bit ASCII text. Base64 encoding allows binary attachments (images, documents) to be transmitted safely through email as MIME-encoded content.

API Payloads

When APIs need to transmit binary data within JSON (which only supports text), Base64 encoding converts the binary content to a JSON-safe string. JWTs use Base64URL for their header and payload sections.

Frequently Asked Questions

Related Guides

Related Tools