DEV Community

Cover image for How to Encode and Decode Base64 Strings (With a Free Browser Tool)
Biplob Barman
Biplob Barman

Posted on

How to Encode and Decode Base64 Strings (With a Free Browser Tool)

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())
Enter fullscreen mode Exit fullscreen mode

Python:

import base64
encoded = base64.b64encode(b"Hello World")
print(encoded.decode())
Enter fullscreen mode Exit fullscreen mode

Decoding a String

JavaScript:

const decoded = atob("SGVsbG8gV29ybGQ=");
console.log(decoded); // Hello World
Enter fullscreen mode Exit fullscreen mode

Python:

decoded = base64.b64decode("SGVsbG8gV29ybGQ=")
print(decoded.decode())
Enter fullscreen mode Exit fullscreen mode

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)