Base64 Encoder/Decoder

Encode and decode Base64 strings

Plain Text
Base64
Understanding Base64 Encoding
TL;DR

Base64 is a binary-to-text encoding scheme that converts binary data into a set of 64 printable ASCII characters. It is used to safely transmit binary data through text-based protocols like email (MIME), HTML (data URIs), and HTTP headers. Base64 is encoding, not encryption — anyone can decode it.

What is Base64?

Base64 is a binary-to-text encoding scheme that represents binary data using a set of 64 ASCII characters. It was designed to ensure that binary data can be safely transmitted over text-based systems that may not handle raw bytes correctly — such as email (SMTP), JSON, XML, and URL parameters.

The name “Base64” refers to the 64-character alphabet used for encoding. Unlike hexadecimal (Base16), which uses 16 characters, Base64 is more compact — it represents 6 bits per character instead of 4.

How Base64 Encoding Works

The encoding process operates on groups of 3 bytes (24 bits) at a time:

  1. Take 3 bytes of input (24 bits total)
  2. Split into 4 groups of 6 bits each
  3. Map each 6-bit value to a character from the Base64 alphabet
  4. If the input length isn’t a multiple of 3, pad with = characters

The Base64 Alphabet

Index RangeCharactersCount
0-25A to Z26
26-51a to z26
52-610 to 910
62+1
63/1
Padding=

Base64URL Variant

For URLs and filenames, the standard + and / characters are problematic. The Base64URL variant (RFC 4648 §5) replaces them:

  • + becomes -
  • / becomes _
  • Padding = is often omitted

This variant is used in JWTs, OAuth tokens, and anywhere tokens appear in URLs.

Padding Explained

Base64 works on 3-byte groups. When the input doesn’t divide evenly by 3:

Input BytesBase64 OutputPadding
3 bytes4 charactersNone
2 bytes3 characters + =1 pad
1 byte2 characters + ==2 pads

Common Use Cases

  • Email attachments (MIME): Binary files are Base64-encoded to travel safely through SMTP, which only supports 7-bit ASCII
  • Data URIs: Embed images directly in HTML or CSS as data:image/png;base64,iVBORw0KGgo...
  • HTTP Basic Auth: The Authorization: Basic header carries username:password as Base64
  • JSON payloads: Binary data (files, images, certificates) can be embedded in JSON strings via Base64
  • JWT tokens: Each segment (header, payload, signature) is Base64URL-encoded

Try These Examples

ASCII Text Valid

Simple ASCII text encoded to Base64 produces 'SGVsbG8sIFdvcmxkIQ=='. The == padding indicates the input length wasn't a multiple of 3 bytes.

Hello, World!
UTF-8 with Special Characters Valid

UTF-8 text with accented characters and emoji. Multi-byte characters produce longer Base64 output since each character may be 2-4 bytes.

Café ☕ résumé
Empty String Invalid

An empty input produces no output. Base64 encoding requires at least one byte of input data.