Base64 Encoder / Decoder

What is Base64 Encoding?

Base64 is a binary-to-text encoding scheme that represents arbitrary binary data using a set of 64 printable ASCII characters. It was originally designed to solve a fundamental problem: how to transmit binary data (images, files, compressed archives) over protocols that only support text, such as email (SMTP/MIME) and early HTTP.

The encoding works by taking every 3 bytes (24 bits) of input and splitting them into four 6-bit groups. Each 6-bit value (0-63) maps to one character from the Base64 alphabet: A-Z (0-25), a-z (26-51), 0-9 (52-61), + (62), and / (63). If the input length is not a multiple of 3, the output is padded with = characters to make it a multiple of 4. The scheme is defined in RFC 4648.

Why Base64 Exists

Many protocols and data formats are designed for text, not binary. Email was originally limited to 7-bit ASCII, so attaching a photo or a PDF required encoding it into printable characters. Base64 became the standard way to do this in MIME (Multipurpose Internet Mail Extensions), and the same principle extends to modern use cases:

How to Use This Tool

  1. Paste or type your text into the input field.
  2. Click Encode to convert it to Base64, or Decode to convert Base64 back to plain text.
  3. Click Auto to let the tool detect whether your input is Base64 or plain text and process it accordingly.
  4. The size ratio below the output shows the overhead — Base64 encoded output is always roughly 133% of the original size.
  5. If your input is a Base64 data URI for an image, an image preview will appear automatically.

Everything runs entirely in your browser using the Web APIs btoa(), atob(), TextEncoder, and TextDecoder. No data is sent to any server.

Base64 vs. Base64URL

Standard Base64 uses + and / as its 62nd and 63rd characters, but both have special meaning in URLs (+ can mean space, / is a path separator). Base64URL (also defined in RFC 4648) replaces them with - and _, and typically omits the = padding. This makes the output safe for use in URLs, filenames, and HTTP headers without percent-encoding. Base64URL is the encoding used in JSON Web Tokens (JWT), OAuth tokens, and URL-safe identifiers.

The 33% Size Overhead

Base64 always increases data size by approximately 33%. This is an inherent property of the encoding: 3 input bytes become 4 output characters, so the ratio is exactly 4/3 (133.3%). For small assets like icons, the overhead is negligible and often worth it to save an HTTP request. For large files, the overhead matters — a 1 MB file becomes about 1.33 MB in Base64. This is why Base64 data URIs are typically recommended only for assets under 10-20 KB.

Base64 Encoding in Code

Frequently Asked Questions

What is Base64 encoding?

Base64 is a binary-to-text encoding scheme that represents binary data using 64 printable ASCII characters (A-Z, a-z, 0-9, +, and /), plus = for padding. It converts every 3 bytes of input into 4 ASCII characters, allowing binary data to be safely transmitted over text-based protocols like email, HTTP headers, and URLs.

Why is Base64 used?

Base64 exists to safely transmit binary data through channels designed for text. It is used in email attachments (MIME), data URIs to embed images in HTML/CSS, HTTP Basic Authentication headers, JSON Web Tokens (JWT), and any API payload that needs to carry binary content inside JSON or XML.

Does Base64 encrypt data?

No. Base64 is an encoding, not encryption. It provides no security whatsoever — anyone can decode a Base64 string instantly. It is designed for data transport compatibility, not confidentiality. If you need to protect data, use actual encryption (AES, RSA, etc.) before or instead of Base64.

What characters does Base64 use?

Standard Base64 uses 64 characters: uppercase A-Z, lowercase a-z, digits 0-9, plus (+), and forward slash (/). The equals sign (=) is used for padding. Base64URL replaces + with - and / with _ to be safe in URLs and filenames.

Why does Base64 increase file size?

Base64 encodes every 3 bytes of input into 4 characters of output, resulting in a 33% size increase. Three bytes (24 bits) are split into four 6-bit groups, each mapped to one of 64 ASCII characters. The overhead is the trade-off for representing arbitrary binary data as safe, printable text.

What is Base64URL?

Base64URL is a variant of Base64 that replaces + with - and / with _, making the output safe for use in URLs and filenames without percent-encoding. It typically omits padding (=). Base64URL is used in JSON Web Tokens (JWT), OAuth tokens, and anywhere Base64 data appears in a URL.

How do I Base64 encode in JavaScript/Python?

In JavaScript: btoa('hello') encodes and atob('aGVsbG8=') decodes. For UTF-8, use btoa(unescape(encodeURIComponent(str))). In Python: import base64; base64.b64encode(b'hello').decode() encodes and base64.b64decode('aGVsbG8=').decode() decodes. In Bash: echo -n 'hello' | base64.