# Base64 codec

> Encode and decode Base64 for text or a file, including the URL-safe alphabet.

Free Base64 encode and Base64 decode tool for text and files. Turn on URL-safe output, wrap a file as a data URI, or decode a data URI back to text or a download. The file never leaves the browser.

- Page: https://benchline.fabwaseem.com/t/base64-codec
- Runs: in the browser. Input stays on the device.
- Price: free, no account
- Input: Text or a file, encode or decode, and toggles for URL-safe Base64 and a data URI.
- Output: Base64 text, a data URI, decoded UTF-8 when the bytes are text, and a file download.
- Keywords: base64 decode, base64 encode, base64 to file, url safe base64
- Updated: 2026-10-18
- Built by: Waseem Anjum (https://fabwaseem.com)

## How to use it

1. **Choose text or a file.** Text encodes a string as UTF-8. A file is read in the browser and encoded as raw bytes.
2. **Encode or decode.** URL-safe output drops the padding. A data URI uses the standard alphabet and the file type you set, or text/plain for a string.
3. **Copy or download.** Copy the Base64, or decode it and download the file under the sniffed type.

## Use it from an AI agent

MCP tool name: `base64_codec`
MCP endpoint: https://benchline.fabwaseem.com/mcp (Streamable HTTP, no key)
HTTP: POST https://benchline.fabwaseem.com/api/v1/tools/base64-codec with the input as the JSON body
This call does not fetch anything. It runs on the arguments you send.

Encode UTF-8 text as Base64, or decode Base64 and data URIs. URL-safe output uses - and _ and omits padding. Decode reports the sniffed media type and whether the bytes are UTF-8 text.

### Input schema

```json
{
  "type": "object",
  "properties": {
    "action": {
      "default": "encode",
      "type": "string",
      "enum": [
        "encode",
        "decode"
      ]
    },
    "text": {
      "type": "string",
      "description": "Text to encode, or Base64 or a data URI to decode."
    },
    "urlSafe": {
      "default": false,
      "description": "Encode with the URL-safe alphabet and no padding. Data URIs stay on the standard alphabet.",
      "type": "boolean"
    },
    "dataUri": {
      "default": false,
      "type": "boolean"
    },
    "mime": {
      "default": "text/plain;charset=utf-8",
      "type": "string"
    }
  },
  "required": [
    "action",
    "text",
    "urlSafe",
    "dataUri",
    "mime"
  ],
  "additionalProperties": false
}
```

### Example tools/call

```json
{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "tools/call",
  "params": {
    "name": "base64_codec",
    "arguments": {
      "action": "encode",
      "text": "example",
      "urlSafe": false,
      "dataUri": false,
      "mime": "text/plain;charset=utf-8"
    }
  }
}
```

Setup for Claude, Cursor, and VS Code: https://benchline.fabwaseem.com/mcp/guide

## Questions

### What is URL-safe Base64?

The URL-safe alphabet uses - and _ instead of + and /, and this tool omits the padding. Decoding accepts both alphabets, with or without padding, and ignores whitespace.

### Does a data URI stay URL-safe?

No. A data URI uses the standard alphabet, because that is what browsers read. The URL-safe toggle applies to raw Base64 only.

### Can I decode a file?

Yes. Paste the Base64 or a data URI and download the bytes. The type is taken from the data URI when it has one, otherwise from the file header: PNG, JPEG, GIF, WebP, PDF, ZIP, SVG, JSON, or plain text.

### Why is decoded text empty for some files?

The bytes are not valid UTF-8. The download still has the original bytes. Text mode only shows a string when the decoded bytes are UTF-8.

## Related tools

- [JSON formatter](https://benchline.fabwaseem.com/t/json-formatter): Pretty-print, minify, and validate JSON, with the exact line and column when it fails.
- [JWT decoder](https://benchline.fabwaseem.com/t/jwt-decoder): Paste a JSON Web Token, read the claims, and verify the signature in the browser.
- [JSON YAML converter](https://benchline.fabwaseem.com/t/json-yaml-convert): Convert JSON, YAML, TOML, and XML in the browser, and keep the line number when a document fails.
- [CSV JSON converter](https://benchline.fabwaseem.com/t/csv-json-convert): Convert CSV to JSON and JSON back to CSV, with a delimiter and a header row you choose.
