Base64 is an encoding method used to safely transmit data over text-based systems like APIs, JSON, or HTTP headers. It’s important to note that Base64 is encoding, not encryption — it does not secure your data, but it ensures it can be safely transported.
Encoding a String
JavaScript:
const encoded = btoa("Hello World");
console.log(encoded); // SGVsbG8gV29ybGQ=
import base64
encoded = base64.b64encode(b"Hello World")
print(encoded.decode())
Python:
import base64
encoded = base64.b64encode(b"Hello World")
print(encoded.decode())
Decoding a String
JavaScript:
const decoded = atob("SGVsbG8gV29ybGQ=");
console.log(decoded); // Hello World
Python:
decoded = base64.b64decode("SGVsbG8gV29ybGQ=")
print(decoded.decode())
When to Use Base64
Base64 is commonly used for:
- Encoding API keys or authentication tokens
- Embedding images in HTML or emails
- Sending small files in JSON or XML
- Debugging encoded content in development
Keep in mind that Base64 increases file size by ~33%, so it’s best for small data or text, not large files.
Quick Browser-Based Tool
If you want to encode or decode Base64 strings without writing code, you can use a free browser-based tool I often use:
Base64 Encoder & Decoder
It runs entirely in your browser, is fast, and does not store any data, making it safe for testing and learning.
Learning Base64 is a small but powerful skill for web development. Whether you’re testing APIs, debugging payloads, or embedding images, knowing how to encode and decode strings will save you time and simplify your workflow.
Top comments (0)