Base64 Encoder / Decoder

Instantly encode any text to Base64 or decode Base64 strings back to readable text. Supports standard and URL-safe variants. All processing happens in your browser — nothing is sent to a server.

How It Works

  1. 1

    Paste your text into the input panel — the tool auto-detects whether it looks like Base64 and switches to the right mode

  2. 2

    Toggle between Encode and Decode modes, or switch to URL-Safe Base64 for use in URLs and filenames

  3. 3

    Copy the output or use it directly — the stats row shows exactly how many characters were processed

When To Use This Tool

  • When you need to encode credentials or tokens for HTTP Basic Auth headers

  • When you want to embed small images or files as data URIs in CSS or HTML

  • When you're debugging a JWT and need to decode its Base64url-encoded sections

  • When an API returns a Base64-encoded response and you need to read the raw content

  • When you need URL-safe Base64 encoding for query parameters or filenames

Frequently Asked Questions

Complete Guide to Base64 Encoding and Decoding

What is Base64 and why does it exist?

Base64 is a binary-to-text encoding scheme invented to solve a fundamental problem: many systems built to handle text — email servers, HTTP headers, XML documents — cannot safely transmit arbitrary binary bytes. Control characters, null bytes, and bytes with the high bit set could corrupt data or be stripped entirely. Base64 sidesteps this by representing any binary sequence using only 64 safe ASCII characters: A–Z, a–z, 0–9, +, and /. The name comes from the 64-character alphabet it uses. The trade-off is size: Base64 output is always about 33% larger than the input, because every 3 bytes of binary data become 4 characters of text.

How Base64 encoding works step by step

Base64 encodes data in chunks of 3 bytes (24 bits) at a time. Each 24-bit group is split into four 6-bit values, and each 6-bit value maps to one character in the Base64 alphabet (0=A, 1=B, ..., 63=/). If the input length is not a multiple of 3, padding characters (=) are appended to make the output length a multiple of 4. One trailing = means the last group had 2 input bytes; two == means it had only 1. To encode 'Man': M=77, a=97, n=110. Binary: 01001101 01100001 01101110. Split into 6-bit groups: 010011 010110 000101 101110 = 19, 22, 5, 46 = T, W, F, u. Result: 'TWFu'.

Standard Base64 vs URL-safe Base64

Standard Base64 uses + and / as its 62nd and 63rd characters. These cause problems in URLs: + is interpreted as a space in query strings, and / is a path separator. URL-safe Base64 (Base64url, defined in RFC 4648) replaces + with - and / with _ so the encoded string can appear in URLs, query parameters, and filenames without percent-encoding. Padding (=) is also typically omitted in URL-safe contexts. JWT tokens use Base64url for their header and payload sections. When choosing between variants, use standard Base64 for data transmission (MIME, HTTP headers) and Base64url for web-facing identifiers.

Handling Unicode, emoji, and non-ASCII text

JavaScript's built-in btoa() function only accepts ASCII strings — calling it on text with characters outside the Latin-1 range (like emoji or Chinese characters) throws a 'String contains an invalid character' error. The correct approach is to first encode the string to UTF-8 bytes using encodeURIComponent(), then convert the percent-encoded sequences to raw bytes before passing to btoa(). The canonical pattern is: btoa(unescape(encodeURIComponent(input))). For decoding, the reverse: decodeURIComponent(escape(atob(input))). This tool uses this approach internally, so you can safely encode any text including emoji, Arabic, Chinese, and accented characters.

Common uses of Base64 in web development

HTTP Basic Authentication encodes credentials as Base64: Authorization: Basic base64(username:password). Note that this is not encryption — anyone who intercepts the header can decode it instantly. Data URIs embed files directly in HTML or CSS: <img src='data:image/png;base64,...'/> — useful for small icons to eliminate HTTP requests, but impractical for large images due to the 33% size overhead. Email attachments use MIME Base64 encoding to safely transmit binary files through text-based protocols. JWT tokens encode their header and payload as Base64url. API responses from services like Google Cloud Vision return image analysis results as Base64-encoded binary data.

How to detect and validate Base64 strings

A valid standard Base64 string has four properties: it contains only characters from [A-Za-z0-9+/=], its total length is a multiple of 4, it has at most 2 trailing = padding characters, and = characters only appear at the end. A regex that captures most cases: /^[A-Za-z0-9+/]*={0,2}$/. Note that this is a necessary but not sufficient check — a string of all A's passes the regex but may not decode to meaningful data. For URL-safe Base64, replace + with [-] and / with [_] in the pattern and omit the padding requirement. This tool's auto-detection uses this heuristic to switch to decode mode when you paste something that looks like Base64.

Base64 in the command line

On macOS and Linux, the base64 command is built in. To encode a file: base64 input.txt > output.txt. To decode: base64 -d encoded.txt > decoded.txt. On macOS the flag is -D instead of -d. To encode a string directly: echo -n 'Hello World' | base64. The -n flag prevents echo from adding a newline, which would be included in the encoding otherwise. On Windows, PowerShell can encode: [Convert]::ToBase64String([Text.Encoding]::UTF8.GetBytes('Hello World')). To decode in PowerShell: [Text.Encoding]::UTF8.GetString([Convert]::FromBase64String('SGVsbG8gV29ybGQ=')).

Was this tool helpful?

Related Tools

This free Base64 encoder decoder tool lets you convert text to Base64 and decode Base64 strings instantly in your browser. Supports both standard Base64 and URL-safe Base64 (Base64url) variants used in JWT tokens, OAuth, and API authentication. Works with Unicode, emoji, and any UTF-8 text.

This tool runs entirely in your browser. Your data never leaves your device.