Free Converter

Base64 Encoder / Decoder

Encode text or files to Base64 and decode Base64 strings instantly in your browser. Free, private, and no upload required.

About Base64 Encoding and Decoding

Base64 is an encoding scheme that represents binary data as ASCII text using 64 printable characters: A-Z, a-z, 0-9, plus (+), and slash (/), with equals (=) used for padding. The format was originally designed to make binary attachments survive 7-bit-clean email transports, but it has expanded to dozens of uses today: data URLs in HTML, JSON containing image data, JWT payloads, basic authentication headers, and any text-based protocol that needs to carry bytes.

Encoding takes 3 bytes of input and produces 4 ASCII characters of output. The output is therefore 33% longer than the input — which is the cost of fitting binary into a text-safe format. Decoding reverses the process exactly, recovering the original bytes from the encoded text.

This tool handles both directions. Encode mode takes text input (or a binary file via upload) and produces base64 text. Decode mode takes base64 text and produces the original text or downloadable binary. URL-safe variant (using - and _ in place of + and /) is supported for tokens and identifiers.

Why Use Base64

Base64 is the standard way to embed binary data in text-only contexts. Inline images in HTML use data URLs (data:image/png;base64,...) so a small icon can ship with the page without a separate request. JSON payloads carrying images, certificates, or signatures encode them as base64 strings. JWT tokens are three base64-encoded segments separated by dots.

Base64 also normalizes character handling for protocols that mishandle 8-bit binary. Authentication headers (Basic auth uses base64), email attachments, configuration files containing keys, and many APIs require base64 because binary cannot pass through their pipelines reliably.

How to Encode and Decode Base64

Paste data, choose direction.

  1. Choose encode or decode: Encode produces base64 text from binary or text input. Decode reverses the process.
  2. Add input: For encoding, paste text or upload a binary file. For decoding, paste base64 text. The tool detects URL-safe variant automatically.
  3. Convert: The browser uses btoa for encoding and atob for decoding (with UTF-8 handling for non-ASCII text). Output is exact and deterministic.
  4. Copy or download: Encoded text can be embedded in URLs, JSON, HTML data URLs, or any text-based protocol. Decoded binary downloads as a file with a guess at the appropriate extension based on detected file type.

Common Use Cases

Technical Details

Base64 maps every 6 bits of input to one of 64 output characters. Three input bytes (24 bits) produce four output characters. When the input length is not a multiple of 3, the encoder appends one or two equals signs to pad the output to a multiple of 4 characters.

URL-safe base64 (defined in RFC 4648 section 5) replaces + with - and / with _ to produce strings safe to use in URLs and filenames without further escaping. The padding equals signs are sometimes omitted in URL-safe contexts; decoders typically accept both forms.

JavaScript's btoa and atob handle ASCII directly but fail on non-ASCII strings. For UTF-8 text, the converter uses TextEncoder/TextDecoder to convert between text and binary, then base64-encodes the binary. This handles emoji, accented characters, and non-Latin scripts correctly.

Best Practices

Frequently Asked Questions

What's the size overhead of base64?
Roughly 33% larger than the original binary. Three input bytes become four output characters; an extra 0–2 padding characters are appended at the end if the input length is not a multiple of 3.
What's URL-safe base64?
A variant that uses - and _ instead of + and / so the encoded value can appear in URLs without further percent-escaping. The two variants are interchangeable; decoders typically accept both.
Can I encode binary files?
Yes. Upload the binary file; the tool reads its bytes and produces base64. Decoding base64 back to binary produces a downloadable file.
What if my text contains non-ASCII characters?
The encoder uses UTF-8 to convert text to binary first, then base64-encodes the binary. This produces correct results for emoji, accented characters, and non-Latin scripts.
Are JWT tokens base64?
Yes — JWT consists of three base64url-encoded segments separated by dots. The first is the header, the second is the payload, the third is the signature.
Is my data uploaded to a server?
No. Encoding and decoding happen in your browser using btoa, atob, TextEncoder, and TextDecoder.
What's the maximum size?
Up to 50 MB. Browser memory bounds the practical size for very large inputs.
Why does my decoded output look like garbage?
Most likely the source was binary, not text. Switch to file-download mode to get the binary, or check that the input is actually base64-encoded text rather than binary.