Advertisement
728×90
Configure AdSense ID to enable
Base64 Encoder / Decoder - free online calculator on CalcCircuit

Base64 Encoder / Decoder

Encode text to Base64 or decode Base64 back to text.

Results

Output SGVsbG8gV29ybGQ=
Share:
Advertisement
300×250
Configure AdSense ID to enable

About Base64 Encoder / Decoder

Base64 is one of the most widely used binary-to-text encoding schemes in modern computing. Originally standardized in RFC 4648, it transforms arbitrary byte sequences into a printable ASCII string using a 64-character alphabet: uppercase letters A-Z, lowercase letters a-z, digits 0-9, and the symbols + and /. Because the resulting text only contains characters that survive email headers, URL query strings, JSON values, and XML payloads, Base64 is the default bridge when systems cannot safely transport raw binary. A single Base64 character carries 6 bits of information, so every group of 3 input bytes—24 bits total—is expanded into 4 output characters. That expansion creates an unavoidable 33% overhead: a 1 MB file becomes roughly 1.33 MB after encoding, a 12-byte string becomes 16 characters, and a 1,000-byte payload becomes 1,336 characters once padding is included. Despite the bloat, the format is nearly universal. JWT tokens use Base64URL for their header and payload segments, stripping + and / to make the result URL-safe. Data URIs embed small images directly into CSS and HTML, letting a 4 KB PNG travel as a single src attribute. Email MIME attachments still rely on Base64 to cross text-only mail gateways. Developers also use it to stash binary secrets in environment variables, to pass signed payloads between microservices, or to serialize cryptographic nonces into databases. This tool lets you encode plain text into Base64 or decode Base64 back into readable text instantly, making it invaluable for debugging APIs, inspecting tokens, preparing test fixtures, and teaching encoding mechanics without installing command-line utilities like openssl or base64.

How It Works

The tool accepts two inputs: a mode (encode or decode) and the text to process. When encoding, the input string is first converted to its UTF-8 byte representation. Those bytes are concatenated into a long bit stream and then sliced into 6-bit chunks. Each 6-bit value maps to one of the 64 characters in the Base64 alphabet: 0-25 map to A-Z, 26-51 map to a-z, 52-61 map to 0-9, 62 maps to +, and 63 maps to /. If the final byte group contains only 1 or 2 bytes, the remaining 6-bit chunks are padded with zeros and one or two equals signs (=) are appended so the output length is always a multiple of 4. Decoding reverses the pipeline: each Base64 character is converted back to its 6-bit index, the bits are reassembled into bytes, and any padding is discarded to recover the original text.

Formula & Calculation Logic

For a string of n bytes, the encoded length in characters is ceil(n / 3) × 4. The ceil accounts for partial 3-byte groups that still need a full 4-character block. For example, 3 bytes encode to 4 characters, 4 bytes encode to 8 characters, and 7 bytes encode to 12 characters. The decoding formula is the inverse: after removing padding, n Base64 characters represent floor(n × 3 / 4) bytes. The 64-character alphabet assumes standard Base64; URL-safe variants replace + with - and / with _ and usually omit padding, but this tool uses the canonical alphabet unless you manually adapt the output.

Step-by-Step Guide

  1. Step 1: Choose Encode if you want text-to-Base64, or Decode if you have Base64 to reverse.
  2. Step 2: Paste the input into the text field. For encode, use plain text; for decode, paste valid Base64.
  3. Step 3: The tool splits the text into bytes and groups them into 6-bit chunks.
  4. Step 4: Each 6-bit chunk is translated into a character from the Base64 alphabet.
  5. Step 5: Padding (=) is added so the output length is a multiple of 4 when encoding.
  6. Step 6: The result appears instantly; copy it or switch modes to reverse the operation.

Example Calculations

  • Scenario 1: Encoding the greeting 'Hello World' produces 'SGVsbG8gV29ybGQ='.
  • Scenario 2: Decoding 'Q2FsY3VsYXRvcg==' returns the word 'Calculator'.

Common Use Cases

  • Embedding small images or fonts directly into HTML/CSS via data URIs.
  • Encoding JWT token headers and payloads for OAuth and API authentication.
  • Transporting binary attachments through email MIME boundaries.
  • Storing binary configuration or secrets in text-only environments.

Pro Tips

  • Use URL-safe Base64 (- and _ instead of + and /) when embedding values in URLs or cookies.
  • Remember that Base64 is encoding, not encryption—anyone can decode it.
  • Strip line breaks before decoding; line wrapping is for human readability only.
  • Account for the 33% size increase when estimating bandwidth or storage for encoded payloads.

Common Mistakes to Avoid

  • Treating Base64 as encryption and using it to protect passwords or secrets.
  • Forgetting to remove whitespace or newlines before decoding.
  • Mixing standard Base64 with URL-safe Base64 without converting characters.
  • Ignoring the padding requirement, which causes some strict decoders to fail.

Why Use This Tool?

  • Guarantees ASCII-safe transport across text-based protocols.
  • Universally supported by virtually every programming language and platform.
  • Preserves binary integrity without corruption by mail or HTTP gateways.
  • Self-contained: no external libraries or command-line tools are required.

Frequently Asked Questions

What is Base64 used for?
Encoding binary data as text for transfer in URLs, emails, and JSON.
Is Base64 encryption?
No, it is encoding only and not secure for sensitive data.
Why does encoded text end with equals signs?
Padding ensures the output length is a multiple of 4 characters.
Can Base64 contain spaces?
Standard output should not; remove whitespace before decoding.
What is Base64URL?
A variant that replaces + with - and / with _ to be safe in URLs.
How much larger is Base64 than the original?
About 33% larger due to 4 output characters per 3 input bytes.
Can I encode binary files?
Yes, but this tool accepts text input; use a file-based encoder for binaries.

Related Tools & Concepts

Advertisement
728×90
Configure AdSense ID to enable

Frequently Asked Questions

What is Base64 used for?
Encoding binary data as text for transfer in URLs, emails, and JSON.
Is Base64 encryption?
No, it is encoding only and not secure for sensitive data.

Related Tools

Mobile Anchor Ad (320×50)