Comprehensive Developer Reference & Guide
The Complete Guide to Base64 Encode and Decode
Learn everything about Base64 encoding, the RFC 4648 standard, binary conversions, Data URIs, image encoding, command-line usage, and code implementations in Python, JavaScript, PHP, Golang, and Linux.
1. What is Base64 Encoding and How Does the RFC 4648 Standard Work?
Base64 encode is a group of binary-to-text encoding schemes that translate binary data (bytes) into an ASCII string format. The primary purpose of base64 encoding is to allow binary assets—such as images, compressed zip files, audio clips, encryption keys, and compiled byte arrays—to be safely transmitted over network channels and communication protocols designed strictly for plain ASCII text (such as HTTP headers, email MIME protocols via SMTP, XML payloads, and JSON REST APIs) without data corruption.
Under the formal RFC 4648 base64 encoding standard, the Base64 alphabet consists of exactly 64 printable ASCII characters:
- Uppercase Letters (26):
A-Z(Index values 0 to 25) - Lowercase Letters (26):
a-z(Index values 26 to 51) - Numeric Digits (10):
0-9(Index values 52 to 61) - Special Symbols (2):
+(plus) and/(slash) (Index values 62 and 63) - Padding Character:
=(equals sign) used to align byte boundaries when the input length is not divisible by 3.
Because 2^6 = 64, each character in a base64 encoded string represents exactly 6 bits of raw binary data. During the encoding process, the computer takes groups of three 8-bit bytes (24 bits in total) and partitions them into four 6-bit integers. Each 6-bit integer maps directly to a character in the 64-character alphabet table. As a mathematical consequence, any data converted using a base64 encoder incurs an exact +33.3% size overhead (4 output characters for every 3 input bytes).
2. Base64 Encode and Decode Online: Converting Text, Strings & Characters
When you use an online base64 encode tool or base64 decoder, the conversion handles various character encodings and formatting variations:
Encoding Plain Text to Base64
To base64 encode text, the raw characters (e.g. UTF-8 strings containing Latin characters, Asian ideographs, Arabic text, or emojis) are first serialized into a binary byte sequence via TextEncoder, and then translated into standard Base64 characters. You can also enable line-by-line mode to encode multiple credentials or log entries independently.
Decoding Base64 to Text & Bytes
When you decode base64 online, the base64 converter parses the 6-bit character indexes back into an 8-bit Uint8Array byte buffer. Our smart engine automatically inspects the payload, repairs missing trailing = padding, and decodes binary byte arrays into readable UTF-8 strings.
Our tool acts as a unified base64 decode and encode studio: simply paste your text or Base64 string into the input area. The Auto-Detect engine immediately identifies whether your input is plain text, Base64, a Data URI, or JSON, and executes the optimal transformation with zero manual toggling required.
3. Image to Base64, Base64 to Image, PDF & File Conversions (Data URIs)
Modern web development frequently relies on inline binary embedding using Data URIs. By using our base64 image encoder, you can convert image to base64 and embed visual assets directly inside your HTML markup or CSS stylesheets, reducing additional HTTP round-trip requests for small UI icons, favicons, badges, and splash illustrations.
Supported Image & Media Formats:
- PNG:
data:image/png;base64,... - JPEG / JPG:
data:image/jpeg;base64,... - SVG Vector:
data:image/svg+xml;base64,... - WebP:
data:image/webp;base64,... - GIF:
data:image/gif;base64,... - PDF Document:
data:application/pdf;base64,...
How to base64 encode a file: With our interactive base64 file encoder, you can drag and drop any file (such as images, PDF documents, JSON config files, MP3 audio, or binary blobs) directly onto the inspector surface. The tool converts the binary data into an RFC 4648 Base64 string instantly in your browser, displays a real-time visual preview, and provides 1-click buttons to copy the raw string, HTML <img> tag, CSS url() property, or download the decoded file.
4. Base64 Encode & Decode in Programming Languages and Command Line (CLI)
Developers frequently need to implement Base64 encoding in backend APIs, build scripts, automation pipelines, and server configurations. Below is a quick cheat sheet for major programming languages and command-line environments:
Python (base64 encode python & python base64 decode)Python 3.x Standard Library
import base64
# Base64 Encode String Python
raw_data = "Hello, World!".encode("utf-8")
encoded_b64 = base64.b64encode(raw_data).decode("utf-8")
print("Encoded:", encoded_b64) # Output: SGVsbG8sIFdvcmxkIQ==
# Base64 Decode Python
decoded_bytes = base64.b64decode(encoded_b64)
decoded_str = decoded_bytes.decode("utf-8")
print("Decoded:", decoded_str) # Output: Hello, World!JavaScript & Node.js (base64 encode in js & nodejs)Browser & Node Runtime
// Browser JavaScript
const encoded = btoa(unescape(encodeURIComponent("Hello, World!")));
const decoded = decodeURIComponent(escape(atob(encoded)));
// Node.js Buffer
const b64Encoded = Buffer.from("Hello, World!", "utf-8").toString("base64");
const b64Decoded = Buffer.from(b64Encoded, "base64").toString("utf-8");PHP (php base64 encode & php decode base64)PHP 7.x / 8.x Native
<?php
// PHP Base64 Encode
$encoded = base64_encode("Hello, World!");
// PHP Base64 Decode
$decoded = base64_decode($encoded);
echo $decoded;
?>Golang (golang base64 decode & base64 encode golang)Go standard encoding/base64
package main
import (
"encoding/base64"
"fmt"
)
func main() {
data := []byte("Hello, World!")
encoded := base64.StdEncoding.EncodeToString(data)
decoded, _ := base64.StdEncoding.DecodeString(encoded)
fmt.Printf("Encoded: %s\nDecoded: %s\n", encoded, string(decoded))
}Linux Terminal, Bash & Windows PowerShell (base64 command line)CLI & Shell Scripts
# Linux Command Base64 Encode String
echo -n "Hello, World!" | base64
# Linux Base64 Decode Command Line
echo -n "SGVsbG8sIFdvcmxkIQ==" | base64 -d
# Base64 Encode File Linux
base64 -w 0 input.png > image.b64
# Windows PowerShell Base64 Encode
[Convert]::ToBase64String([Text.Encoding]::UTF8.GetBytes("Hello, World!"))
# Windows PowerShell Base64 Decode
[Text.Encoding]::UTF8.GetString([Convert]::FromBase64String("SGVsbG8sIFdvcmxkIQ=="))5. Base64 for HTTP Basic Authentication, Passwords & JSON Web Tokens (JWT)
In HTTP API security, the HTTP Basic Authentication scheme (RFC 7617) requires clients to send credentials in an Authorization request header. The client combines the username and password separated by a colon (username:password) and converts it with a base64 encode username and password routine:
Authorization: Basic YWRtaW46c2VjcmV0cGFzc3dvcmQxMjM=Similarly, JSON Web Tokens (JWT) rely on Base64URL encoding to pack the JOSE header, JSON payload claims, and cryptographic signature into three period-delimited URL-safe parts (header.payload.signature). Because standard Base64 characters + and / carry special meaning in web URLs and query strings, Base64URL substitutes them with - and _ while omitting padding = characters.
6. Why B64EncodeDecode is the Safest & Fastest Online Base64 Tool
Many legacy online converters (such as base64encode.org) transmit your sensitive inputs, passwords, proprietary code, and confidential images across the internet to remote servers for processing.
B64EncodeDecode (encoderbase64.com) is fundamentally different:
- 100% In-Browser Execution: All string transformations, byte array conversions, and file readings happen entirely inside your local browser memory using JavaScript Web Workers and the HTML5 FileReader API.
- Zero Server Uploads: No files, strings, passwords, or telemetry data are ever transmitted to any external backend server or database.
- Instant Zero-Latency Performance: Real-time processing with sub-millisecond conversion times even for large megabyte-sized assets.
- Live Visual Previews: Instant rendering for PNG, JPEG, SVG, WebP, GIF, PDF documents, MP3/WAV audio streams, and JSON trees directly on-page.
- Smart Error Auto-Repair: Automatically pinpoints malformed characters, corrects invalid byte padding, and normalizes line endings with a single click.