✨ 170+ free browser tools — zero uploads, zero signup, zero limits.  Explore All Tools →
Free · No Upload · Encode + Decode + Image + File
⭐⭐⭐⭐⭐ 4.9/5 (11,240 reviews)

Base64 Encoder
& Decoder Free
Online

Encode text, images & files to Base64 — decode back instantly. Supports text, URL-safe Base64, image to Base64 data URI, file to Base64, and Base64 back to file/PDF download. Code snippets for Python, PHP, JavaScript, Java & Bash. 100% private — runs in your browser.

Text, Image & File support URL-safe Base64 mode Decode Base64 to PDF / file download 100% private, zero upload
🔤 Base64 Encoder / Decoder — WebToolTrix
1 Input Text
How It Works

How to Encode & Decode Base64 Online

4 powerful modes — text, image, file, and decode-to-file. All instant, all free.

📝

Text Mode

  1. Paste any text into the input box
  2. Click Encode to Base64 or Decode from Base64
  3. Copy the output or click Swap to re-process
Enable URL-Safe to replace + with - and / with _ for safe use in URLs
🖼️

Image Mode

  1. Switch to the Image tab
  2. Drop or upload any image (JPG, PNG, GIF, WebP, SVG)
  3. Copy the Base64 Data URI for use in HTML/CSS/JS
Use Base64 Only to copy the raw string without the data:image/... prefix
📁

File Mode

  1. Switch to the File tab
  2. Upload any file — PDF, DOCX, ZIP, MP3, etc.
  3. Copy or download the Base64 encoded string
Useful for embedding files in JSON payloads, email attachments (MIME), or API calls
🔓

Decode → File

  1. Switch to the Decode→File tab
  2. Paste a Base64 string and choose the output format (.pdf, .png, .txt…)
  3. Click Decode & Download to save the file
Supports Base64 to PDF — paste a PDF's Base64 and download the original file
Features

Why Use WebToolTrix Base64 Encoder Decoder?

The most complete free Base64 tool online — handles text, images, files, and language code snippets.

🔤

Text Encode & Decode

Instantly encode any text to Base64 and decode any Base64 string back to plain text. Supports UTF-8, ASCII, and multi-language characters including Unicode and emoji.

🖼️

Image to Base64 Encoder

Convert any image (JPG, PNG, GIF, WebP, SVG) to a Base64 data URI instantly. Copy the full data:image/... string for use in HTML <img> tags, CSS backgrounds, or JavaScript.

📁

File to Base64 — Any Format

Upload any file — PDF, DOCX, ZIP, MP3, MP4, XML — and get the Base64 encoded string. Use the output in JSON APIs, email MIME attachments, or data embedding. Download as a .txt file.

🔓

Base64 Decoder to File / PDF

Paste any Base64 string and download the decoded file directly. Choose the output format: PDF, PNG, JPG, TXT, JSON, HTML, or binary. The perfect base64 decoder to pdf solution.

🔗

URL-Safe Base64

Enable URL-safe encoding to replace + with - and / with _. The URL-safe variant is required for JWTs, URL query parameters, and safe transmission over HTTP without encoding issues.

💻

Code Snippets — 5 Languages

Get ready-to-paste code in Python, PHP, JavaScript, Java, and Bash/Linux for both encoding and decoding. Never search stack overflow again — copy the snippet directly from the article below.

Comparison

WebToolTrix vs Other Base64 Tools

Not all Base64 tools are equal. Here's how we compare.

Feature WebToolTrix ⭐ base64.guru base64encode.org CyberChef
Text Encode & Decode
Image to Base64
File to Base64
Decode Base64 to File/PDF
URL-Safe Base64
Language Code Snippets
100% Private (no server uploads)
Zero sign-up
Clean, fast UI±Complex

Free Base64 Encoder Decoder Online — The Complete Guide

Base64 is one of the most widely used encoding schemes in computing — yet it is often misunderstood. Developers paste Base64 strings into APIs without knowing what the encoding actually does, why it exists, or why simply using a free Base64 encoder decoder online is the fastest way to inspect, debug, and manipulate encoded data. WebToolTrix's Base64 tool covers every real-world use case: text encoding and decoding, image to Base64 encoder for embedding images in HTML and CSS, file-to-Base64 conversion for API payloads, and a base64 decoder to file that lets you download the decoded binary — including base64 decoder to PDF. This guide explains every mode in detail and includes ready-to-paste code for Python, PHP, JavaScript, Java, and Bash/Linux.

Whether you're a frontend developer embedding images, a backend engineer building REST APIs, a DevOps engineer working with Kubernetes secrets, or a security researcher inspecting encoded payloads — this is the complete reference for Base64 in every language and environment.

Base64 encoder decoder tool interface showing text encode and image modes
Quick tip: Switch between Encode and Decode in one click using the Swap button — no need to copy-paste between boxes. URL-safe mode is available for JWT and OAuth tokens.

What Is Base64 Encoding?

Base64 is a binary-to-text encoding scheme that represents binary data using only 64 printable ASCII characters: A–Z (26), a–z (26), 0–9 (10), + and / (2), with = used as padding. The name comes from the 64-character alphabet. Every 3 bytes of binary data become 4 characters — a 33% size increase in exchange for safe transmission over text-only channels.

Why does Base64 exist? Many protocols — SMTP (email), HTTP headers, XML, JSON — were designed for ASCII text and cannot reliably transmit raw binary data. An image file, a PDF, a ZIP archive — these contain bytes across the entire 0–255 range, many of which are control characters or non-printable. Base64 encodes those bytes into the printable 64-character set, making them safe to embed in any text-based protocol. RFC 4648 is the authoritative specification for Base64 and its URL-safe variant.

Base64 Encoder — Encoding Text

Encoding text to Base64 is the most common use case. The process converts each character's UTF-8 byte representation into Base64 characters. Here's what happens step by step:

  • Input: Hello (5 bytes: 72 101 108 108 111)
  • Binary groups of 6 bits: 010010 000110 010101 101100 011011 000110 1111
  • Each 6-bit group maps to a Base64 character using the alphabet
  • Output: SGVsbG8= (the trailing = is padding to make the length a multiple of 4)

WebToolTrix's base64 encoder supports Unicode text — paste Japanese, Arabic, Chinese, or emoji-containing text and get the correct Base64 string. Input text is first encoded as UTF-8, then Base64-encoded, matching the behaviour of all major programming languages.

Base64 Decoder — Decoding a Base64 String

The base64 decoder reverses the process: it takes a Base64 string, strips padding, converts each character back through the alphabet lookup table, and reassembles the original bytes, then interprets them as UTF-8 text (for text decoding) or as raw binary (for file decoding). WebToolTrix's decoder validates the input — if the string contains characters outside the Base64 alphabet or has incorrect padding, an error is shown immediately rather than silently producing corrupted output.

Base64 Encoded String — What It Looks Like

A base64 encoded string is always composed exclusively of A–Z, a–z, 0–9, +, /, and trailing = padding. Key properties to recognise it:

  • Always a multiple of 4 characters in length (padding enforces this)
  • Contains no spaces, control characters, or non-ASCII symbols
  • Commonly ends with one or two = signs (unless the input length is divisible by 3)
  • Approximately 33% longer than the original binary data
  • URL-safe variant replaces +- and /_

Base64 Encode Image — Image to Base64 Data URI

Encoding an image to Base64 produces a data URI — a self-contained URL that embeds the image data directly in the HTML, CSS, or JavaScript, eliminating an HTTP request. The format is:

data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAA...

This is useful for:

  • CSS sprites and icon fonts — embedding small icons directly in stylesheets eliminates extra HTTP requests
  • Email templates — many email clients block external images; Base64-embedded images always display
  • React and Vue components — import images as data URIs in JavaScript without a separate asset pipeline
  • Offline/PWA apps — images embedded in Base64 are available even without network access
  • Canvas and WebGL — load textures programmatically without CORS issues

WebToolTrix's image to Base64 encoder handles all common formats: JPEG, PNG, GIF, WebP, BMP, and SVG. After encoding, you get separate copy buttons for the full data URI (with data:image/...;base64, prefix) and for the raw Base64 string alone — useful when an API expects just the encoded data without the MIME type prefix.

Base64 file to PDF decoding and image encoding use cases diagram

Base64 Decoder to PDF — Decoding Files

A very common developer task is receiving a base64 decoder to PDF challenge: an API returns a PDF file encoded as a Base64 string, and you need to decode it and open the actual PDF. WebToolTrix's Decode→File mode handles this perfectly. Paste the Base64 string, select .pdf from the format dropdown, and click Decode & Download — the browser downloads the decoded binary as a real PDF file. This works for any binary format: images, ZIP archives, audio files, Word documents. No server required — the decoding happens entirely in-browser using the Web File API.

Base64 Encode Python — Python Code

The base64 encode Python standard library module handles encoding and decoding natively:

import base64

# Encode text
text = "Hello, WebToolTrix!"
encoded = base64.b64encode(text.encode('utf-8')).decode('utf-8')
print(encoded)  # SGVsbG8sIFdlYlRvb2xUcml4IQ==

# Decode
decoded = base64.b64decode(encoded).decode('utf-8')
print(decoded)  # Hello, WebToolTrix!

# URL-safe encode (base64 decode python url-safe)
url_safe = base64.urlsafe_b64encode(text.encode()).decode()

# Encode a file (python base64 encoder for files)
with open('document.pdf', 'rb') as f:
    file_b64 = base64.b64encode(f.read()).decode()

The base64.b64encode() function operates on bytes, not strings — always .encode('utf-8') your string first. For base64 decode Python, use base64.b64decode() — it returns bytes, so call .decode('utf-8') to get a string. For base64 encode Python for files, open in binary mode ('rb') and pass the bytes directly.

Base64 Encode PHP — PHP Code

PHP has native functions for Base64: base64_encode() and base64_decode(). This is the most common base64 encode PHP pattern:

<?php
// base64 encode php
$text = "Hello, WebToolTrix!";
$encoded = base64_encode($text);
echo $encoded; // SGVsbG8sIFdlYlRvb2xUcml4IQ==

// base64 decode php
$decoded = base64_decode($encoded);
echo $decoded; // Hello, WebToolTrix!

// base64 encode image in php
$imageData = file_get_contents('logo.png');
$base64Image = 'data:image/png;base64,' . base64_encode($imageData);
// Use $base64Image in HTML: <img src="$base64Image">

// URL-safe base64 (for JWT etc)
$urlSafe = strtr(base64_encode($text), '+/', '-_');
$urlSafe = rtrim($urlSafe, '='); // Remove padding for JWT
?>

For email attachments in PHP's mail() or PHPMailer, pass the Base64 string with appropriate MIME headers. WordPress developers frequently use base64_encode() for encoding plugin license keys and API credentials stored in the database.

Base64 Encode JavaScript / Base64 Decode in JavaScript

JavaScript has two native browser functions: btoa() (binary to ASCII = encode) and atob() (ASCII to binary = decode). These are the go-to for base64 encode JavaScript in browsers:

// base64 encode javascript (browser)
const encoded = btoa("Hello, WebToolTrix!");
console.log(encoded); // SGVsbG8sIFdlYlRvb2xUcml4IQ==

// base64 decode in javascript
const decoded = atob(encoded);
console.log(decoded); // Hello, WebToolTrix!

// For Unicode strings (btoa fails with non-ASCII)
const unicodeStr = "Hello 🌟";
const safeEncoded = btoa(unescape(encodeURIComponent(unicodeStr)));
const safeDecoded = decodeURIComponent(escape(atob(safeEncoded)));

// Node.js base64 (no btoa/atob in older Node)
const buf = Buffer.from("Hello, WebToolTrix!");
const nodeEncoded = buf.toString('base64');
const nodeDecoded = Buffer.from(nodeEncoded, 'base64').toString('utf8');

// URL-safe (replace + with - and / with _)
const urlSafe = btoa("data").replace(/\+/g, '-').replace(/\//g, '_').replace(/=/g, '');

Note: btoa() throws a DOMException if the string contains characters with code points above 255 (e.g., emoji). Use the encodeURIComponent trick shown above, or use the TextEncoder API in modern Node.js for robust Unicode support.

Base64 Decoder Java — Java Code

Java 8+ includes java.util.Base64 — no third-party library needed. This is the standard base64 decoder Java approach:

import java.util.Base64;
import java.nio.charset.StandardCharsets;

// base64 encoder decoder java
String original = "Hello, WebToolTrix!";

// Encode
byte[] encodedBytes = Base64.getEncoder().encode(original.getBytes(StandardCharsets.UTF_8));
String encoded = new String(encodedBytes);

// Decode
byte[] decodedBytes = Base64.getDecoder().decode(encoded);
String decoded = new String(decodedBytes, StandardCharsets.UTF_8);

// URL-safe (for JWT, OAuth)
String urlSafeEncoded = Base64.getUrlEncoder().withoutPadding()
    .encodeToString(original.getBytes(StandardCharsets.UTF_8));

// Encode file
byte[] fileBytes = Files.readAllBytes(Paths.get("document.pdf"));
String fileBase64 = Base64.getEncoder().encodeToString(fileBytes);

Base64 Decode Bash — Linux Command Line

Linux provides native Base64 commands built into the coreutils package — no installation needed. This covers base64 decode bash, base64 encoder linux, and base64 decode Linux in one place:

# base64 encode linux — encode text
echo -n "Hello, WebToolTrix!" | base64
# Output: SGVsbG8sIFdlYlRvb2xUcml4IQ==

# base64 decode bash — decode text
echo "SGVsbG8sIFdlYlRvb2xUcml4IQ==" | base64 --decode
# Output: Hello, WebToolTrix!

# base64 encode file (linux)
base64 document.pdf > document.b64

# base64 decoder linux — decode file
base64 --decode document.b64 > decoded_document.pdf

# base64 decoder to pdf from bash
cat encoded.txt | base64 -d > output.pdf

# macOS uses -D instead of --decode
base64 -D <<< "SGVsbG8sIFdlYlRvb2xUcml4IQ=="

# One-liner: encode URL-safe (replace + and / for use in URLs)
echo -n "my-token-data" | base64 | tr '+/' '-_' | tr -d '='

The -n flag in echo -n is critical — without it, echo appends a newline character which becomes part of the Base64 string and causes mismatches when decoding. On macOS, the flag is -D rather than --decode. The base64 decoder Linux command is available on every major Linux distribution including Ubuntu, Debian, CentOS, Fedora, and Arch.

Base64 Decode URL — URL-Safe Base64 Explained

Standard Base64 uses + and / which have special meanings in URLs (+ = space in query strings, / = path separator). Base64 decode URL refers to URL-safe Base64 — also called Base64url — defined in RFC 4648 §5. It replaces:

  • +- (hyphen)
  • /_ (underscore)
  • Padding (=) is often omitted

URL-safe Base64 is the standard encoding for JSON Web Tokens (JWT) — the header, payload, and signature of a JWT are all URL-safe Base64 encoded and joined by dots. It's also used in OAuth 2.0 PKCE code challenges, Google's Firebase tokens, and AWS Cognito session tokens. WebToolTrix's URL-Safe checkbox handles the conversion automatically in both encoding and decoding directions.

Base64 Encode File — Any File Type

The File mode in WebToolTrix is one of its most powerful features. Base64 encode file works for literally any file format — because Base64 operates on raw bytes, the file type doesn't matter. Common use cases:

  • REST API binary payloads — APIs that transport files via JSON must Base64-encode them (JSON doesn't support raw binary)
  • Email attachments (MIME) — all email attachments are Base64-encoded inside the MIME multipart body
  • Kubernetes secrets — all secret values in Kubernetes manifests (.yaml) are Base64-encoded
  • Environment variables — storing binary data (certificates, keys) in environment variables by Base64-encoding them
  • Embedded fonts in CSS — font files (.woff, .woff2, .ttf) embedded as Base64 data URIs in CSS @font-face

What Is Base64 Encoder — Common Misconceptions

Understanding what is Base64 encoder means clearing up three common misconceptions:

  • Base64 is NOT encryption. It is encoding — it is completely reversible without a key. Anyone who sees a Base64 string can decode it trivially. Never use Base64 to "secure" sensitive data.
  • Base64 is NOT compression. Base64-encoded data is 33% LARGER than the original. It trades size for text-safe portability.
  • Base64 is NOT hashing. Hashing is one-way (SHA-256, MD5); Base64 encoding is two-way (encode/decode).

Base64 is purely a data representation format. Its purpose is safe transmission and storage of binary data through text-only channels. For encryption, use AES-256. For hashing, use SHA-256. For data portability across text channels, use Base64.


FAQ

Base64 Encoder Decoder — Frequently Asked Questions

Base64 is a binary-to-text encoding scheme that converts binary data (images, files, binary strings) into 64 printable ASCII characters. It's used because many protocols (email SMTP, HTTP headers, JSON, XML) are text-based and cannot reliably transmit raw binary bytes. Base64 makes binary data safe to include in text-only channels — at a 33% size overhead.
In Text mode: paste your text and click "Encode to Base64" or "Decode from Base64". For images: switch to the Image tab and upload any image to get its Base64 data URI. For files: use the File tab to convert any file to Base64. To decode a Base64 string back to a downloadable file (PDF, PNG, etc.), use the Decode→File tab.
Switch to the "Decode→File" tab, paste your Base64-encoded PDF string, select ".pdf" from the format dropdown, and click "Decode & Download". The decoded file downloads instantly in your browser. No server upload — it's all processed locally in your browser.
Switch to the Image tab and drag-and-drop or click to upload your image (JPG, PNG, GIF, WebP, SVG). The tool instantly generates the full Base64 data URI (data:image/...;base64,...). Copy the full URI for use in HTML img tags or CSS backgrounds, or use "Base64 Only" for the raw string without the MIME prefix.
URL-safe Base64 replaces + with - and / with _ so the encoded string can be safely used in URLs without percent-encoding. Enable the "URL-Safe" checkbox in Text mode. Use it for JWTs (JSON Web Tokens), OAuth tokens, URL query parameters, and any context where the Base64 string appears in a URL.
Python: import base64. Encode: base64.b64encode(text.encode('utf-8')).decode('utf-8'). Decode: base64.b64decode(encoded_string).decode('utf-8'). For files, open in binary mode ('rb') and pass the bytes directly to b64encode(). For URL-safe: base64.urlsafe_b64encode().
No. Base64 is encoding, not encryption. It is completely reversible without any key — anyone with the Base64 string can decode it in seconds. Never use Base64 to protect sensitive data. For security, use AES-256 encryption. For one-way hashing, use SHA-256. Base64 is purely for safe data transport across text-only channels.
Encode: echo -n "your text" | base64. Decode: echo "SGVsbG8=" | base64 --decode. For files: base64 file.pdf > file.b64 (encode) or base64 --decode file.b64 > output.pdf (decode). On macOS use -D instead of --decode. Always use -n with echo to avoid encoding a trailing newline.