Base64 Encoder/Decoder

A free online Base64 encoder/decoder for quick encoding and decoding, with convenient features like UTF-8 support, secure copy, and clear.

Encode (Text → Base64)

Decode (Base64 → Text)

How to Use

Base64 encodes binary data into ASCII for safe transmission and storage. Size increases by approximately 33%.
Encode: Convert plain text into Base64 for secure transmission.
Decode: Restore the original text from a Base64 string.

Features

  • UTF-8 Safe: Properly handles non-ASCII characters (wrapped with encodeURIComponent/unescape).
  • URL-safe Support: One-click toggle between + / → - _, optional removal of padding =.
  • Pre-process Before Decoding: Ignore whitespace, auto-convert URL-safe, and auto-pad =.
  • Real-time Interaction: Input is processed instantly, with length and growth rate statistics displayed.
  • Usability: Quick copy, bidirectional fill between inputs, keyboard-accessible, mobile-friendly.
  • Consistent Theme: No Tailwind dark: classes — fully styled with DaisyUI themes.

Quick Examples

Original Text:
Hello, World!
Base64:
SGVsbG8sIFdvcmxkIQ==

What is Base64?

Base64 is a method of encoding binary data into ASCII text, commonly used to transmit images or file contents over text-based protocols such as JSON, XML, and HTTP.

It maps every 3 bytes into 4 printable characters, typically resulting in approximately a 33% increase in size.

Standard Base64 uses A–Z, a–z, 0–9, +, /, and the padding character =; the URL-safe variant replaces + and / with - and _ to avoid escaping issues in URLs.

Common Use Cases

  • Embed images or small files as Data URIs.
  • Transfer binary data between client and server (e.g., encrypted ciphertexts, compressed streams).
  • Convert text into printable format to avoid encoding inconsistencies or invisible characters.

FAQs & Important Notes

  • Character set: In web environments, first encode text as UTF-8 (this tool includes this step automatically).
  • URL-safe: For URL parameters or paths, prefer the URL-safe variant and consider removing padding characters.
  • Padding: Some implementations allow omitting =; during decoding, automatically pad to a multiple of 4 characters.
  • Line breaks: MIME Base64 may include line breaks; select "Ignore whitespace" during decoding to handle them.

How to Encode/Decode Base64 in Programming Languages

JavaScript
Text → Base64 (UTF-8 Safe)
const encoded = btoa(unescape(encodeURIComponent(text)));
// URL-safe
const urlSafe = encoded.replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/g, '');
Decode (Base64 → Text)
// Preprocess: Replace -_ with +/
let b64 = input.replace(/-/g, '+').replace(/_/g, '/');
if (b64.length % 4 !== 0) b64 = b64.padEnd(b64.length + (4 - (b64.length % 4)), '=');
const text = decodeURIComponent(escape(atob(b64)));
PHP
Encode (Text → Base64)
$encoded = base64_encode($text);
// URL-safe
$urlSafe = rtrim(strtr($encoded, '+/', '-_'), '=');
Decode (Base64 → Text)
$b64 = strtr($input, '-_', '+/');
// Auto-pad with '='
if (strlen($b64) % 4 !== 0) $b64 .= str_repeat('=', 4 - (strlen($b64) % 4));
$text = base64_decode($b64);
Python
Encode (Text → Base64)
import base64

encoded = base64.b64encode(text.encode('utf-8')).decode('ascii')
# URL-safe Encode (Remove Padding)
url_safe = encoded.replace('+','-').replace('/','_').rstrip('=')
Decode (Base64 → Text)
import base64

def b64_decode(s: str) -> str:
    s = s.replace('-','+').replace('_','/')
    s += '=' * (-len(s) % 4)  # Auto-pad with '='
    return base64.b64decode(s).decode('utf-8')
Go
Encode (Text → Base64)
import (
    "encoding/base64"
)

enc := base64.StdEncoding.EncodeToString([]byte(text))
// URL-safe Encode (No Padding)
urlEnc := base64.RawURLEncoding.EncodeToString([]byte(text))
Decode (Base64 → Text)
import (
    "encoding/base64"
)

decBytes, err := base64.StdEncoding.DecodeString(enc)
// URL-safe Decode (No Padding)
decURL, err2 := base64.RawURLEncoding.DecodeString(urlEnc)
Rust
Encode (Text → Base64)
use base64::{engine::general_purpose, Engine as _};

let enc = general_purpose::STANDARD.encode(text.as_bytes());
// URL-safe Encode (No Padding)
let url_enc = general_purpose::URL_SAFE_NO_PAD.encode(text.as_bytes());
Decode (Base64 → Text)
use base64::{engine::general_purpose, Engine as _};

let dec_bytes = general_purpose::STANDARD.decode(&enc).unwrap();
let dec = String::from_utf8(dec_bytes).unwrap();

let url_dec = String::from_utf8(
    general_purpose::URL_SAFE_NO_PAD.decode(&url_enc).unwrap()
).unwrap();
Cargo dependency: base64 = "0.22"
Java
Encode (Text → Base64)
import java.nio.charset.StandardCharsets;
import java.util.Base64;

String enc = Base64.getEncoder().encodeToString(text.getBytes(StandardCharsets.UTF_8));
// URL-safe Encode (No Padding)
String urlEnc = Base64.getUrlEncoder().withoutPadding().encodeToString(text.getBytes(StandardCharsets.UTF_8));
Decode (Base64 → Text)
import java.nio.charset.StandardCharsets;
import java.util.Base64;

String dec = new String(Base64.getDecoder().decode(enc), StandardCharsets.UTF_8);
String urlDec = new String(Base64.getUrlDecoder().decode(urlEnc), StandardCharsets.UTF_8);

Data URI Examples

Embed images or small files as Data URIs:

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

Note: Avoid using Data URIs for large files, as they significantly increase HTML/JSON size and degrade performance.