Tutorial

How to Decode Base64 Online — Step-by-Step Guide

Learn how to decode Base64 strings back to text, images, and files. Step-by-step guide with code examples in JavaScript, Python, Java, and command line.

Published on September 7, 20265 min read

Decoding Base64 is the process of reversing an encoded ASCII text string back into its original form — whether that original content was a readable text message, a JPEG photo, a PDF document, or an executable binary file. In this step-by-step guide, you will learn what happens during Base64 decoding, how to decode strings into text, files, and images online, how to write decoding logic in major programming languages, and how to troubleshoot common decoding errors.

What Does Decode Base64 Mean?

To decode Base64 means to take an ASCII string generated by a Base64 encoder, map each character back to its original 6-bit integer value (from 0 to 63), and reconstruct the original 8-bit byte stream.

The arithmetic is the exact mirror image of encoding:

  1. Read 4 characters:The decoder looks at 4 consecutive Base64 characters (representing 4 × 6 = 24 bits).
  2. Lookup binary values: Each character is translated to its 6-bit numerical equivalent using the Base64 alphabet index table.
  3. Reassemble 3 bytes:The 24 bits are re-partitioned into three 8-bit bytes (3 × 8 = 24 bits).
  4. Handle padding: If the string ends with = or ==, the trailing null padding bits are discarded so only the true original bytes remain.

Once the original bytes are reconstructed, they can either be interpreted as UTF-8 or ASCII text, or saved directly to a file as a binary image, document, or archive.

How to Decode Base64 to Text Online

When you encounter an encoded authorization header, an obscure API parameter, or a serialized text string, you can decode it immediately using our Base64 Decoder tool.

Follow these simple steps:

  1. Open the Decoder: Visit our online Base64 Decoder.
  2. Paste your encoded string: Paste the Base64 snippet into the input box. For instance, pasting SGVsbG8sIFdvcmxkIQ== will automatically trigger the real-time decoder.
  3. View and copy the decoded text: The reconstructed plaintext (e.g., Hello, World!) will immediately appear in the result box. Click Copy to transfer it to your clipboard.

Our decoder automatically handles UTF-8 multi-byte characters, emojis, and auto-detects whether the string is plain Base64 or a prefixed Data URI scheme.

How to Decode Base64 to Files

Oftentimes, a Base64 string represents a binary document, such as an emailed PDF, an encrypted export, a compressed ZIP archive, or an audio clip. You cannot view these properly in a text box — they must be decoded back into binary bytes and downloaded as a file.

You can restore any binary file using our Base64 Decode to File tool:

  1. Paste the Base64 string: Paste the raw Base64 data or upload a .txt / .b64 file containing the encoded payload.
  2. Automatic file type detection: The tool examines the decoded magic bytes (file signatures) to identify whether the file is a PDF (%PDF-), ZIP archive (PK), MP3, MP4, or Office document.
  3. Download the recovered file: Click Download File to save the decoded binary directly to your local drive with its appropriate file name and extension.

How to Decode Base64 to Images

If you have a Base64 string from a database or a CSS file and want to see the image it contains, use our dedicated Base64 to Image Decoder.

Here is how it works:

  • Paste your Base64 or Data URI: Paste raw Base64 strings or full Data URIs starting with data:image/png;base64,....
  • Instant visual preview: The tool renders a crisp live preview of your image (PNG, JPG, WebP, SVG, GIF, or ICO) directly in the browser viewport.
  • Image details & download: View dimensions (width × height), color depth, and decoded byte size, and click Download Image to export the graphic as a regular image file.

Decode Base64 in Code

Here is how to decode Base64 data programmatically in your projects using JavaScript, Python, Java, and CLI commands.

1. JavaScript / TypeScript

In web browsers, you can decode Base64 strings using atob(). To correctly handle UTF-8 text with non-ASCII or multi-byte characters, use TextDecoder:

// In Browser (with safe Unicode / UTF-8 decoding):
function decodeBase64(base64) {
  const binaryString = atob(base64);
  const bytes = Uint8Array.from(binaryString, (char) => char.charCodeAt(0));
  return new TextDecoder().decode(bytes);
}

console.log(decodeBase64("SGVsbG8sIPCfjI0=")); // "Hello, 🌍"

// In Node.js:
const decoded = Buffer.from("SGVsbG8sIFdvcmxkIQ==", "base64").toString("utf-8");
console.log(decoded); // "Hello, World!"

2. Python

In Python, use the base64.b64decode() function to convert Base64 strings back to bytes or decoded strings:

import base64

# Decode to string
encoded = "SGVsbG8sIFdvcmxkIQ=="
decoded_bytes = base64.b64decode(encoded)
decoded_text = decoded_bytes.decode("utf-8")
print(decoded_text)  # Hello, World!

# Decode Base64 string to a binary file
b64_image_data = "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg=="
with open("output.png", "wb") as f:
    f.write(base64.b64decode(b64_image_data))
print("Image saved successfully!")

3. Java

Java 8+ provides standard decoders through the java.util.Base64 class:

import java.util.Base64;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;

public class Main {
    public static void main(String[] args) throws Exception {
        String encoded = "SGVsbG8sIFdvcmxkIQ==";
        byte[] decodedBytes = Base64.getDecoder().decode(encoded);
        String decodedText = new String(decodedBytes, StandardCharsets.UTF_8);
        System.out.println(decodedText); // Hello, World!

        // Save binary file
        Files.write(Paths.get("output.bin"), decodedBytes);
    }
}

4. Terminal & Command Line

Decode strings directly from the shell or command prompt:

# Linux & macOS (bash/zsh):
echo "SGVsbG8sIFdvcmxkIQ==" | base64 --decode
# Output: Hello, World!

# Decode a Base64 file back to binary on Linux/macOS:
base64 -d input.b64 > output.pdf

# Windows PowerShell:
[System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String("SGVsbG8sIFdvcmxkIQ=="))

# Windows PowerShell (saving to a file):
[System.IO.File]::WriteAllBytes("output.pdf", [System.Convert]::FromBase64String("...base64..."))

Common Base64 Decoding Errors

If your decoding operation fails or produces unexpected gibberish, you are most likely facing one of these four common issues:

1. Invalid Characters

Base64 only permits A-Z, a-z, 0-9, +, /, and padding =. Unintended spaces, line breaks (CRLF), quotes, or URL prefixes like data:text/plain;base64, will cause parsers like atob() to throw an InvalidCharacterError. Always strip headers and whitespace before decoding.

2. Incorrect Padding (Length Not a Multiple of 4)

Standard Base64 strings must always have a length divisible by 4. If trailing = padding characters are stripped or truncated, strict decoders in Java or Python will reject the string with an Incorrect padding exception. You can repair missing padding by appending = until length % 4 == 0.

3. Standard vs URL-Safe Variant Mismatch

URL-safe Base64 (used in JWT tokens and URL query strings) replaces + with - and / with _. If you pass a URL-safe string into a standard Base64 decoder without converting characters first, decoding will fail.

4. Character Encoding Mismatch (Mojibake)

If the decoded output looks like scrambled characters (e.g. é instead of é), the binary bytes were interpreted using Latin-1 / Windows-1252 instead of UTF-8. Always decode raw byte arrays with UTF-8 encoding.

Try Our Free Base64 Converter

Need to decode or convert data right now? Check out our complete suite of free browser utilities:

  • Base64 Converter — Instant two-way encoder and decoder for all general conversions.
  • Base64 Decoder — Clean, fast text decoding with UTF-8 and formatting support.
  • Base64 Decode to File — Reconstruct and download PDFs, ZIP archives, and docs from Base64.
  • Base64 to Image — Preview and export Base64 images in PNG, JPEG, SVG, and WebP.

All decoding happens 100% locally in your browser for total security and privacy.