Other

Base64 Encode / Decode

Results

Enter values and calculate to see results.

Embed on your site

Any ezcalcs calculator can be embedded with one script tag. Copy the snippet below or use the homepage playground to preview and customize.

<!-- ezcalcs embed: base64-encode-decode — paste anywhere in the body -->
<script
  async
  src="https://ezcalcs.net/embed.js"
  data-calc="base64-encode-decode"
  data-theme="light"
  data-width="100%"
  data-height="640"
></script>

Paste any text or Base64 string into the calculator above, pick your direction (encode or decode), and get instant results. No signup, no file uploads, no data sent to a server you don't control.

Base64 is an encoding scheme that converts binary data into a string of printable ASCII characters. It is not encryption. It does not protect or obscure information. It simply reformats data so it can travel safely through systems that only handle text, like email (MIME), JSON payloads, or XML documents.

The difference between encoding and decoding is straightforward. Encoding takes your original text or binary data and converts it into a Base64 string. Decoding reverses that process, turning an encoded string back into its original format.

How to Encode and Decode Using Base64

Using this online tool takes three steps:

  1. Paste your input into the text box.
  2. Choose Encode or Decode.
  3. Copy the result.

The tool handles standard Base64 and Base64URL. If your decoded text looks unreadable, the original data was likely binary (an image, a compressed file, or encrypted bytes) rather than plain text. Base64 can encode any byte sequence, so not every decoded result will be human-readable.

Base64 Encode Binary Data to ASCII

When you need to encode binary data, such as an image, a PDF, or raw byte output from an API, Base64 converts it into a safe ASCII string format. The encoding process works like this:

  • Every three bytes of input are joined into a single 24-bit binary sequence.
  • That 24-bit sequence is converted into 4 numbers, each between 0 and 63.
  • Each number maps to one character from a set of 64 printable ASCII characters (A-Z, a-z, 0-9, +, /).

If the input length isn't divisible by three, the encoder adds = padding characters at the end. The result is roughly 33% larger than the original data.

This is why Base64 is used in email attachments, data URIs in HTML, and anywhere you need to embed binary content inside a text-only format.

Base64 Decode Encoded Text Back to Its Original Format

Decoding reverses the encoding process. The decoder reads each Base64 character, maps it back to its 6-bit value, reassembles the bits into bytes, and outputs the original data.

Common reasons to decode Base64 strings:

  • Inspecting API responses that contain Base64-encoded data.
  • Reading email attachment headers.
  • Extracting embedded images or certificates.

If the input string contains characters outside the Base64 alphabet, or if padding is incorrect, the decode will fail. Check for accidental whitespace, newline characters, or copy-paste errors.

Understanding the Base64 Format and Encoding Scheme

Base64 represents binary data in an ASCII string format. The name comes from the set of 64 characters used in the output alphabet.

The standard Base64 character set is:

  • A-Z (26 characters)
  • a-z (26 characters)
  • 0-9 (10 characters)
  • + and / (2 characters)
  • = (padding, not part of the encoding alphabet itself)

Base64 encoding converts data without regard to what that data means. It works on any byte sequence: text, images, audio, or compressed archives.

RFC 4648 and the Base64 Alphabet

RFC 4648 is the specification that formally defines the Base64 encoding scheme. It standardizes the alphabet, the padding rules, and several variants including Base64URL.

Key points from the specification:

  • The canonical alphabet uses + and / as characters 62 and 63.
  • Padding with = is required to make the output length a multiple of 4.
  • Line breaks are not part of the encoding. Some older implementations (like MIME transfer encoding) insert newline characters every 76 characters, but RFC 4648 recommends against it for general use.

When a tool says it supports "standard Base64," it means this RFC 4648 alphabet.

How Each Byte Maps to Printable ASCII Characters

Here is how three bytes become four Base64 characters:

  1. Take three input bytes (24 bits total).
  2. Split them into four 6-bit groups.
  3. Each 6-bit group (values 0 through 63) maps to one character in the Base64 alphabet.

For example, the text Hi! in ASCII is three bytes: 72, 105, 33. Combined, that is 010010000110100100100001 in binary. Split into four 6-bit groups: 010010, 000110, 100100, 100001. Those map to S, G, k, h. So Hi! encodes to SGkh.

When input is only one or two bytes, the encoder pads the output with = to keep the four-character alignment.

Base64URL: URL and Filename Safe Base64

Standard Base64 uses + and /, which have special meanings in URLs and filenames. Base64URL is a version of Base64 that replaces those two characters:

  • + becomes -
  • / becomes _

Padding (=) is often omitted in Base64URL because the = character also needs percent-encoding in URLs.

The difference between Base64 and Base64URL is only those two character substitutions and the padding behavior. The encoding logic is identical. If you decode a Base64URL string with a standard Base64 decoder, swap - back to + and _ back to / first, or use a tool that handles both.

Using Base64URL in OAuth and JSON Web Tokens

JSON Web Tokens (JWTs) are the most common place you will encounter Base64URL. A JWT has three parts separated by dots, and each part is a Base64URL-encoded JSON object.

  • Header: identifies the signing algorithm.
  • Payload: contains the claims (user ID, expiration, scopes).
  • Signature: a cryptographic hash for verification.

OAuth flows frequently pass JWTs as access tokens or ID tokens. When you need to inspect a token, paste the header or payload segment into this tool, select Base64URL decode, and read the JSON.

Keep in mind: decoding a JWT reveals its contents, but it does not verify the signature. Signature verification requires the signing key and a proper library.

Base64 Encode and Decode in JavaScript

JavaScript has two built-in functions for Base64:

  • btoa() encodes a string to Base64.
  • atob() decodes a Base64 string.

<code class="language-javascript">// Encode const encoded = btoa("Hello, world!"); console.log(encoded); // "SGVsbG8sIHdvcmxkIQ==" // Decode const decoded = atob("SGVsbG8sIHdvcmxkIQ=="); console.log(decoded); // "Hello, world!" </code>

These JavaScript functions only handle characters in the Latin-1 range (single-byte). For UTF-8 text with multibyte characters (emoji, accented letters, CJK), you need an extra step:

<code class="language-javascript">// UTF-8 safe encode const utf8Encode = btoa( new TextEncoder().encode("Héllo 🌍") .reduce((data, byte) => data + String.fromCharCode(byte), "") ); // UTF-8 safe decode const utf8Decode = new TextDecoder().decode( Uint8Array.from(atob(utf8Encode), c => c.charCodeAt(0)) ); </code>

In Node.js, use Buffer.from(string).toString('base64') to encode and Buffer.from(b64string, 'base64').toString() to decode. Both handle UTF-8 natively.

How to Debug Encoded Data with a Base64 Decoder

Decoding Base64 to inspect a payload is one of the most common debugging tasks in web development. API responses, webhook bodies, and authentication tokens frequently contain Base64-encoded data that you need to read.

Debugging steps:

  1. Copy the encoded string from your logs, network inspector, or terminal.
  2. Paste it into the decoder.
  3. Check whether the output is readable text, JSON, or binary.

If the output looks like garbled characters, the original data is probably binary or was encoded with a different text encoding (not UTF-8). Try checking the content type or documentation for the API you are working with.

Decode Base64 Strings in JSON, XML, and MIME

Base64 appears in different formats depending on the context:

  • JSON: Encoded values are plain strings, like "data": "SGVsbG8=". Copy just the string value (without quotes) into the decoder.
  • XML: Often wrapped in CDATA or element text. Extract the content between tags before decoding.
  • MIME: Email uses Base64 as a transfer encoding for attachments. Headers indicate Content-Transfer-Encoding: base64. The encoded block may contain newline characters every 76 characters. Most decoders (including this tool) handle those line breaks automatically.

When working with Base64-encoded data in any of these formats, strip surrounding markup before decoding. Extra characters will cause errors.

When to Use This Base64 Format vs Other Encoding Schemes

Base64 is not the only encoding scheme. Here is when it makes sense and when it does not.

Use Base64 when:

  • You need to embed binary data inside a text format (JSON, XML, HTML, CSS).
  • You are working with email attachments or MIME content.
  • An API specification requires Base64 input or output.
  • You need to pass data through a system that only supports printable ASCII characters.

Consider alternatives when:

  • You need to encode text for a URL. Use percent-encoding (URL encoding) instead.
  • You want to compress data. Base64 increases size by about 33%. Use gzip or another compression format first, then Base64 the result if needed.
  • You want security. Base64 is not encryption. Anyone can decode it. Use AES, RSA, or another encryption method for confidentiality.
  • You need a human-readable format. Hex encoding is easier to read for short byte sequences, though it is 100% larger than the original (compared to 33% for Base64).

Base64 solves one problem well: safe transport of arbitrary bytes through text-only channels. Use it for that purpose and choose a different tool when the problem is different.