Encoding and Decoding Online

The fastest way to encode or decode Base64 is with an online tool. ToolMasta's Base64 encoder and decoder runs entirely in your browser — your data never leaves your device. It supports text input, URL-safe (Base64URL) mode, and file encoding.

Steps to encode:

  1. Open the Base64 Encoder/Decoder
  2. Select "Encode" mode
  3. Type or paste the text you want to encode
  4. The encoded output appears instantly
  5. Click "Copy" to copy the result

Steps to decode:

  1. Select "Decode" mode
  2. Paste the Base64 string
  3. The decoded output appears instantly

All processing is client-side. This is important if you are working with API credentials, JWT payloads, or any sensitive strings — nothing is sent to a server.

Using the Browser Console

Every modern browser includes two built-in JavaScript functions for Base64:

Encode: btoa()

// Open your browser console (F12 → Console) and type:
btoa("Hello, World!")
// Returns: "SGVsbG8sIFdvcmxkIQ=="

Decode: atob()

atob("SGVsbG8sIFdvcmxkIQ==")
// Returns: "Hello, World!"
Unicode caveat: btoa() and atob() work on byte values and do not handle multi-byte Unicode characters natively. For strings containing non-ASCII characters (e.g., emojis, Chinese, Arabic), use btoa(unescape(encodeURIComponent(str))) to encode and decodeURIComponent(escape(atob(b64))) to decode. Modern projects should use the TextEncoder API for more robust handling.

Terminal Commands

Linux and macOS

# Encode text to Base64
echo -n "Hello, World!" | base64
# Output: SGVsbG8sIFdvcmxkIQ==

# Decode Base64 back to text
echo "SGVsbG8sIFdvcmxkIQ==" | base64 --decode
# Output: Hello, World!

Note the -n flag on echo — without it, a trailing newline is included in the encoded output, which changes the result.

Windows PowerShell

# Encode to Base64
[Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes("Hello, World!"))
# Output: SGVsbG8sIFdvcmxkIQ==

# Decode from Base64
[System.Text.Encoding]::UTF8.GetString([Convert]::FromBase64String("SGVsbG8sIFdvcmxkIQ=="))
# Output: Hello, World!

Programming Language Examples

Python

import base64

# Encode
encoded = base64.b64encode(b"Hello, World!")
print(encoded.decode())  # SGVsbG8sIFdvcmxkIQ==

# Decode
decoded = base64.b64decode("SGVsbG8sIFdvcmxkIQ==")
print(decoded.decode())  # Hello, World!

Node.js

// Encode
const encoded = Buffer.from("Hello, World!").toString("base64");
console.log(encoded);  // SGVsbG8sIFdvcmxkIQ==

// Decode
const decoded = Buffer.from("SGVsbG8sIFdvcmxkIQ==", "base64").toString("utf-8");
console.log(decoded);  // Hello, World!

PHP

// Encode
echo base64_encode("Hello, World!");
// SGVsbG8sIFdvcmxkIQ==

// Decode
echo base64_decode("SGVsbG8sIFdvcmxkIQ==");
// Hello, World!

Encoding Text to Base64

The most common use case is encoding plain text. This is used for HTTP Basic Auth headers, embedding text in binary protocols, and creating portable data formats.

For HTTP Basic Authentication, credentials are formatted as username:password and then Base64-encoded:

btoa("myuser:mypassword")
// Result: "bXl1c2VyOm15cGFzc3dvcmQ="

The resulting header is: Authorization: Basic bXl1c2VyOm15cGFzc3dvcmQ=

Remember: this provides no security on its own. The credentials are trivially recoverable by anyone with the encoded string. Always use HTTPS.

Decoding Base64 to Text

Decoding is the reverse operation. A common scenario is inspecting JWT token payloads (the middle segment of a JWT) to read the claims without needing a full JWT library:

// Extract the payload from a JWT (second segment between dots)
const jwt = "eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJ1c2VyMTIzIn0.HMAC";
const payload = jwt.split('.')[1];
atob(payload)
// Returns: {"sub":"user123"}

Encoding Files and Images

ToolMasta's Base64 encoder supports file input — you can drop any file and get the Base64 output for embedding or transmission.

On the command line (Linux/macOS), encode a file:

base64 image.png > image_base64.txt

To embed a PNG image as a data URI in HTML:

<img src="data:image/png;base64,$(base64 -w 0 image.png)">

The -w 0 flag disables line wrapping in the base64 output, which is necessary for data URIs.

Common Use Cases

  • Reading JWT payloads: Decode the middle segment to inspect claims
  • HTTP Basic Auth: Encode user:pass for Authorization headers
  • Data URIs: Embed small images, fonts, or audio in HTML/CSS
  • API keys in config: Some systems Base64-encode API keys for transport (still not encryption)
  • Binary in JSON: Encode binary data to include in a JSON payload
  • Email debugging: Decode MIME-encoded email attachments

Troubleshooting Common Issues

InvalidCharacterError

If btoa() throws an error, your string contains characters outside the Latin-1 range (code points above 255). You need to encode the string as UTF-8 bytes first before passing to btoa.

Incorrect Padding

If a Base64 string is missing its trailing = padding (common with Base64URL), add padding before decoding: the string length must be a multiple of 4. Add = characters until str.length % 4 === 0.

Line Breaks in Output

Some Base64 encoders insert line breaks every 76 characters (as required by MIME). Remove all whitespace before decoding if you receive an error about invalid characters.

Try It Free — No Signup Required

Encode text, URLs, and files to Base64 instantly — or decode any Base64 string back to its original content. All processing in your browser.

Open Base64 Tool