Base64 Encoder/Decoder
Convert between plain text and Base64 encoded strings with this simple tool. Perfect for developers working with binary data in text-based environments.
Base64 Encoder/Decoder
Operation Mode
Text to encode to Base64
Base64 encoded result
Typical Use Cases
- Encoding binary data for inclusion in URLs or JSON
- Sending images or files through text-only protocols
- Storing binary data in databases that don't support binary types
- Obfuscating data for basic transport security
- Working with email attachments and MIME encoding
Formula
- Base64 Encoding: Converts binary data to a string of ASCII characters using 64 printable characters
- Character Set: A-Z, a-z, 0-9, +, / (with = used for padding)
- Conversion Ratio: Base64 encoding increases data size by approximately 33% (3 bytes become 4 characters)
How Base64 Works
Base64 encoding works by dividing the input into 3-byte groups, then converting each group into 4 characters:
1. Input bytes are read in groups of 3 (24 bits)
2. These 24 bits are divided into 4 groups of 6 bits
3. Each 6-bit value (0-63) maps to a character in the Base64 alphabet
If the input length is not divisible by 3, padding '=' characters are added to ensure the output length is always a multiple of 4 characters.
Code Examples
JavaScript
// Encoding
const encoded = btoa('Hello World');
console.log(encoded); // SGVsbG8gV29ybGQ=
// Decoding
const decoded = atob('SGVsbG8gV29ybGQ=');
console.log(decoded); // Hello World
Python
import base64
# Encoding
encoded = base64.b64encode(b'Hello World')
print(encoded) # b'SGVsbG8gV29ybGQ='
# Decoding
decoded = base64.b64decode('SGVsbG8gV29ybGQ=')
print(decoded) # b'Hello World'
Important Notes
- Not for Security: Base64 is an encoding scheme, not an encryption method. It provides no real security and can be easily decoded.
- URL-Safe Variant: Regular Base64 uses '/' and '+' characters which are problematic in URLs. URL-safe Base64 replaces these with '-' and '_' characters.
- Binary Data Handling: When encoding binary data (like images), it's important to use array buffers or typed arrays rather than strings to avoid character encoding issues.
- Size Increase: Base64 encoding increases data size by approximately 33%, which can impact performance for large files or bandwidth-constrained situations.