Base64 Encoder Encoders
Girdi
Çıktı
Settings
What is Base64 Encoding?
Base64 is a binary-to-text encoding scheme that represents binary data in an ASCII string format. It's designed to carry data stored in binary formats across channels that only reliably support text content. Base64 encoding schemes are commonly used when there is a need to encode binary data that needs to be stored and transferred over media designed to deal with ASCII text.
How Does Base64 Encoding Work?
Base64 encoding works by converting every three bytes of binary data into four ASCII characters. The encoding process uses a set of 64 characters: A-Z, a-z, 0-9, +, and /. The equals sign (=) is used for padding when the input data doesn't divide evenly by three.
Data Integrity
Ensures binary data remains intact without modification during transport through text-based systems.
Cross-Platform
Works seamlessly across different operating systems and programming languages.
Fast Processing
Instant encoding and decoding with support for large text and file inputs.
URL-Safe Option
Generate URL-safe Base64 strings by replacing + and / with - and _ characters.
Common Use Cases for Base64 Encoding
- Email Attachments: MIME (Multipurpose Internet Mail Extensions) uses Base64 to encode binary attachments in emails.
- Data URLs: Embed images, fonts, and other resources directly in HTML/CSS using data URIs.
- API Authentication: Many APIs use Base64 encoding for basic authentication headers.
- JSON Data Transfer: Store binary data like images or files within JSON payloads.
- XML Documents: Include binary data in XML documents that only support text content.
- Web Storage: Store binary data in localStorage or sessionStorage in web browsers.
- Configuration Files: Encode sensitive data in configuration files for basic obfuscation.
Base64 Encoding Examples
Text Encoding Example:
Input: Hello World!Output: SGVsbG8gV29ybGQh
URL-Safe Encoding Example:
Standard: +/==URL-Safe: -_
Frequently Asked Questions
Is Base64 encoding secure?
No, Base64 is not an encryption method. It's an encoding scheme that can be easily reversed. Never use Base64 for security purposes or to hide sensitive information.
Why does Base64 increase file size?
Base64 encoding increases the data size by approximately 33% because it represents every 3 bytes of data as 4 ASCII characters.
What's the difference between Base64 and Base64URL?
Base64URL is a variant that replaces + with - and / with _ to make the encoded string safe for use in URLs and filenames. It may also omit padding (=) characters.
Can Base64 encode any type of file?
Yes, Base64 can encode any binary data including images, PDFs, videos, executables, and any other file type.
Technical Specifications
| Specification | Details |
|---|---|
| Character Set | A-Z, a-z, 0-9, +, / (64 characters total) |
| Padding Character | = (equals sign) |
| Size Increase | ~33% larger than original |
| Block Size | 3 bytes input = 4 characters output |
| RFC Standard | RFC 4648 |
Developer Guide
JavaScript
// Encoding
const encoded = btoa('Hello World!');
console.log(encoded); // SGVsbG8gV29ybGQh
// Decoding
const decoded = atob('SGVsbG8gV29ybGQh');
console.log(decoded); // Hello World!
// For Unicode support
const unicodeEncode = btoa(unescape(encodeURIComponent('Hello 世界')));
const unicodeDecode = decodeURIComponent(escape(atob(unicodeEncode)));
Python
import base64
# Encoding
text = "Hello World!"
encoded = base64.b64encode(text.encode()).decode()
print(encoded) # SGVsbG8gV29ybGQh
# Decoding
decoded = base64.b64decode(encoded).decode()
print(decoded) # Hello World!
# URL-safe encoding
url_safe = base64.urlsafe_b64encode(text.encode()).decode()
PHP
// Encoding
$text = "Hello World!";
$encoded = base64_encode($text);
echo $encoded; // SGVsbG8gV29ybGQh
// Decoding
$decoded = base64_decode($encoded);
echo $decoded; // Hello World!
// URL-safe encoding
$urlSafe = strtr($encoded, '+/', '-_');
// Remove padding
$urlSafe = rtrim($urlSafe, '=');
Quick Reference
Common Use Cases
- Embedding images in HTML/CSS (Data URIs)
- Storing binary data in JSON
- Email attachments (MIME)
- Authentication tokens
Characteristics
- ~33% size increase
- Uses A-Z, a-z, 0-9, +, /
- Padding with = characters
- Case-sensitive