πŸ”€ Base64 Encoder / Decoder

Encode and decode Base64 strings quickly and securely in your browser.

Base64 Encoder & Decoder β€” Free Online Tool

Our Base64 encoder online lets you instantly encode text to Base64, decode Base64 strings, convert images, PDFs, and any file to a Base64 data URI β€” all inside your browser with zero data ever leaving your device. Whether you are a developer embedding a Base64 image encoder result into CSS, a sysadmin running Linux Base64 encode commands, or a student learning how Python Base64 encode works, this guide covers everything you need.

Bookmark this page as your single go-to Base64 encoder and decoder online resource β€” the tool above handles the encoding; the deep-dive below gives you the conceptual understanding and language-specific code snippets you can copy straight into your projects.

What Is Base64 Encoding?

Base64 is a binary-to-text encoding scheme defined in RFC 4648. It represents arbitrary binary data using only 64 printable ASCII characters β€” the uppercase and lowercase Latin alphabet (A–Z, a–z), the digits 0–9, and the two symbols + and / β€” with = used as padding.

Every three bytes of binary input are grouped together (24 bits) and split into four 6-bit chunks. Each 6-bit chunk maps to one of the 64 characters in the Base64 alphabet. Because 2⁢ = 64, the math works out perfectly. This process is why Base64 encoding increases file size by roughly 33 % β€” three bytes become four characters.

Quick example β€” converting the string "Man" to Base64:
Input bytes Binary Base64 output
M (77) a (97) n (110) 010011 010110 000101 101110 TWFu

How to Use the EzyToolbox Base64 Encoder

Using our Base64 encode online tool is straightforward:

  1. Text to Base64 β€” Paste or type any string into the "Encode" tab and click Encode to Base64. The result appears instantly.
  2. Base64 to Text β€” Switch to the "Decode" tab, paste your Base64 string, and click Decode from Base64.
  3. File to Base64 encoder β€” Upload an image, PDF, or any binary file. The tool reads it locally and outputs the full Base64 data URI ready to embed in HTML or CSS.
  4. Image to Base64 converter β€” Same flow as file upload. The output starts with data:image/png;base64, so you can paste it directly into an <img src="…"> tag.

All processing is 100 % local β€” JavaScript running in your browser does the work. Nothing is sent to any server, making this a secure offline Base64 encoder even when you are connected to the internet.

Base64 Variants Explained

Standard Base64 vs URL-Safe Base64 (Base64URL)

Standard Base64 uses + and /, which are reserved characters in URLs and can break query strings. A URL-safe Base64 encoder (also called Base64URL encode) replaces + with - and / with _. This variant is used heavily in JSON Web Tokens (JWT) and OAuth 2.0 flows.

Base64 Encoder No Padding

Standard Base64 pads the output with = characters so the total length is a multiple of four. Some protocols (particularly Base64URL in JWTs) strip the padding entirely. A Base64 encoder no padding variant simply omits those trailing = signs. The decoder can handle this by re-adding padding before parsing.

Hex to Base64 Converter

Raw hexadecimal values (e.g., cryptographic hashes like SHA-256) are often converted to Base64 for compact representation. A hex to Base64 converter first decodes the hex string into raw bytes, then applies standard Base64 encoding.

UTF-8 to Base64 Encoder

When you need to encode text that contains non-ASCII characters (accented letters, CJK characters, emojis), you must first convert the string to its UTF-8 byte representation before Base64-encoding it. This is what a proper UTF-8 to Base64 encoder does, and it is what our tool handles automatically.

Real-World Use Cases

πŸ–ΌοΈ
Image to Base64 / PNG to Base64 String

Embed images directly into HTML or CSS without extra HTTP requests. Use <img src="data:image/png;base64,…"> or a CSS background-image to inline your graphic. Ideal for small icons in single-file email templates.

πŸ“„
PDF to Base64 Online

Many e-signature APIs (DocuSign, Adobe Sign) and payment gateways accept documents as Base64-encoded strings in a JSON payload. Use our PDF to Base64 online converter to get the encoded string in seconds.

πŸ”—
Base64 Data URI Generator

A Data URI bundles a file's MIME type and Base64 content into a single string. Our tool auto-generates the correct prefix (data:<mime>;base64,) so you can paste it directly into code.

πŸ”
API Authentication & JWT

HTTP Basic Auth sends credentials as Base64(username:password). JSON Web Tokens use Base64URL-encoded header and payload sections. Quickly inspect or build these values with our Base64 encoder decoder.

πŸ“§
Email Attachments (MIME)

The SMTP protocol is text-only. MIME encoding wraps binary attachments in Base64 so they survive transit through email servers reliably, without data corruption.

πŸ—„οΈ
Storing Binary in JSON / XML

JSON and XML are text formats and cannot contain raw binary. Converting files to Base64 is the standard way to embed binary payloads such as images, certificates, or audio clips in these formats.

Base64 Encoding in Popular Languages & Tools

Below are copy-ready snippets for the most commonly searched languages and platforms.

JavaScript β€” btoa() / Base64 Encode String

The browser's built-in btoa() function (JavaScript Base64 encode / btoa string) encodes a string to Base64. For Unicode strings, encode to UTF-8 bytes first:

// Standard ASCII string
const encoded = btoa("Hello, World!");
// β†’ "SGVsbG8sIFdvcmxkIQ=="

// Unicode-safe version (convert string to Base64)
function toBase64(str) {
  return btoa(unescape(encodeURIComponent(str)));
}
console.log(toBase64("HΓ©llo WΓΆrld"));
// β†’ "SMOpbGxvIFfDtnJsZA=="

// Decode
const decoded = atob("SGVsbG8sIFdvcmxkIQ==");
// β†’ "Hello, World!"

Python β€” base64.b64encode()

Python Base64 encode is handled by the built-in base64 module:

import base64

# Encode a string
text = "Hello, World!"
encoded = base64.b64encode(text.encode("utf-8")).decode("utf-8")
print(encoded)  # SGVsbG8sIFdvcmxkIQ==

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

# URL-safe variant (base64url encode)
url_safe = base64.urlsafe_b64encode(text.encode()).decode()
print(url_safe)  # SGVsbG8sIFdvcmxkIQ==

Java β€” java.util.Base64 (Java Base64 Encoder Class)

Since Java 8, the Java Base64 encoder class (java.util.Base64) is the recommended approach:

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

String original = "Hello, World!";

// Encode
String encoded = Base64.getEncoder()
    .encodeToString(original.getBytes(StandardCharsets.UTF_8));
System.out.println(encoded); // SGVsbG8sIFdvcmxkIQ==

// URL-safe encoder (no padding)
String urlSafe = Base64.getUrlEncoder()
    .withoutPadding()
    .encodeToString(original.getBytes(StandardCharsets.UTF_8));
System.out.println(urlSafe); // SGVsbG8sIFdvcmxkIQ

// Decode
byte[] decodedBytes = Base64.getDecoder().decode(encoded);
System.out.println(new String(decodedBytes)); // Hello, World!

Linux β€” base64 Command Line

The Linux Base64 encode command is available on all major distributions via GNU coreutils:

# Encode a string (echo -n avoids adding a newline)
echo -n "Hello, World!" | base64
# β†’ SGVsbG8sIFdvcmxkIQ==

# Decode
echo "SGVsbG8sIFdvcmxkIQ==" | base64 --decode
# β†’ Hello, World!

# Encode a file
base64 image.png > image_base64.txt

# Decode back to a file
base64 --decode image_base64.txt > image_restored.png

PowerShell β€” Base64 Encode String

PowerShell Base64 encode string uses the .NET Convert class:

# Encode (UTF-16 LE β€” the default PowerShell string encoding)
$text = "Hello, World!"
$bytes = [System.Text.Encoding]::Unicode.GetBytes($text)
$encoded = [Convert]::ToBase64String($bytes)
Write-Output $encoded

# Encode as UTF-8 (more compatible with other tools)
$bytes = [System.Text.Encoding]::UTF8.GetBytes($text)
$encoded = [Convert]::ToBase64String($bytes)
Write-Output $encoded   # SGVsbG8sIFdvcmxkIQ==

# Decode
$decoded = [System.Text.Encoding]::UTF8.GetString(
    [Convert]::FromBase64String($encoded))
Write-Output $decoded   # Hello, World!

CyberChef Base64

CyberChef (by GCHQ) is a popular browser-based tool often used by security analysts for chained data operations. Its "To Base64" and "From Base64" recipes work similarly to EzyToolbox but allow you to chain multiple operations (e.g., compress β†’ Base64 β†’ URL encode). EzyToolbox is the faster choice for quick standalone encode/decode tasks; CyberChef suits complex multi-step transformations.

Image & File Base64 Encoding β€” Deep Dive

Convert PNG to Base64 String

To convert PNG to Base64 string for use in HTML, the output format is:

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

Paste this entire string as the src attribute of an <img> tag, or as the value of a CSS background-image: url(…). Our Base64 image encoder generates this complete data URI automatically when you drop an image into the tool.

PDF to Base64 Online β€” API Submission

When submitting a PDF to REST APIs, the typical JSON payload looks like:

{
  "fileName": "contract.pdf",
  "fileContent": "JVBERi0xLjQKJeLjz9MKMSAwIG9iag..."
}

Use our file to Base64 encoder to get the fileContent value in one click β€” no server upload required.

Base64 Data URI Generator

A Base64 data URI generator produces URIs in the format data:[<mediatype>][;base64],<data>. Common MIME types include:

  • data:image/png;base64,…
  • data:image/jpeg;base64,…
  • data:image/svg+xml;base64,…
  • data:application/pdf;base64,…
  • data:font/woff2;base64,…
  • data:text/plain;charset=utf-8;base64,…

URL Encoder vs Base64 Encoder β€” What's the Difference?

A URL encoder and Base64 tool serve different purposes and are often confused:

Feature URL Encoding (%xx) Base64 Encoding
Purpose Safe characters in URLs Represent binary as text
Input Text / URL components Any binary or text data
Output format Hello%20World%21 SGVsbG8gV29ybGQh
Size overhead Varies (3Γ— for non-ASCII) Always ~33 % larger
Common use Query strings, form data Images, JWTs, MIME, APIs

In some situations both are applied together β€” for instance, a Base64URL-encoded JWT may be embedded in a URL query parameter that is further percent-encoded. Our tool handles the Base64 side; use a dedicated URL encoder for the percent-encoding step.

⚠️ Base64 Is NOT Encryption β€” Security Warning

A very common misconception is that Base64-encoded data is "protected" or "hidden." It is not. Base64 is a purely reversible encoding β€” anyone with the encoded string can decode it instantly. Never use Base64 to secure passwords, API secrets, or sensitive personal data.

If you need to protect data, use proper encryption such as AES-256, or hashing algorithms like bcrypt for passwords. Base64 is only for format conversion, not for security.

Frequently Asked Questions

What is the difference between Base64 encode and Base64 decode?

Encoding converts raw binary or text into a safe ASCII Base64 string. Decoding reverses the process, reconstructing the original data from the Base64 string. Our Base64 decode and encode tool handles both directions with a single click.

How much does Base64 encoding increase file size?

Base64 increases the size of binary data by approximately 33–36 %. Three input bytes become four Base64 characters, and newline characters added for MIME compliance can push it slightly higher. For production web assets, consider whether inline Base64 images actually save bandwidth compared to a single HTTP request.

Is this tool safe for confidential data?

Yes. All encoding and decoding is performed entirely in your browser using JavaScript. No data is ever uploaded to a server, making EzyToolbox a genuine secure offline Base64 encoder. You can verify this by disconnecting from the internet and refreshing β€” the tool continues to function normally.

What is Base64URL and when should I use it?

Base64URL (Base64url encode) replaces the + and / characters with - and _ respectively, making the output safe to include in URLs and filenames without percent-encoding. Use it for JWTs, OAuth tokens, and any value that appears in a URL query parameter or path segment.

Why does my Base64 output end with == or =?

Base64 encodes data in groups of 3 bytes. If the input length is not a multiple of 3, the encoder pads the output with one or two = signs to make the total character count a multiple of four. This is perfectly normal and expected. Some protocols require a Base64 encoder no padding variant; our tool provides a toggle to strip padding for those cases.

Can I convert any file type to Base64?

Yes β€” Base64 works on any binary data. Our file to Base64 encoder accepts images (PNG, JPEG, GIF, WebP, SVG), PDFs, fonts (WOFF, WOFF2), audio files, and more. The maximum file size supported is limited by your browser's available memory, not by any server restriction.

Related Developer Tools on EzyToolbox

Summary β€” Why Use EzyToolbox Base64 Encoder?

  • Instant results β€” encode or decode any text, image, or file in milliseconds.
  • Privacy-first β€” all processing runs locally; zero server uploads.
  • Multiple modes β€” standard Base64, URL-safe Base64URL, no-padding, UTF-8 input.
  • File support β€” image to Base64, PDF to Base64, any file type.
  • Data URI output β€” ready-to-paste data URIs with correct MIME type prefix.
  • No account required β€” free forever, no sign-up, no rate limits.
  • Cross-platform β€” works in any modern browser on desktop or mobile.