Menu

Base64 Encoder / Decoder

Purpose: Encode text to Base64 or decode Base64 back to text - Unicode safe, ideal for data URIs and tokens.

Base64 Encoder: How It Works

Base64 turns arbitrary bytes into 64 safe printable characters so binary data can travel through systems built for text. It is an encoding, not encryption — anyone can reverse it instantly, and treating it as protection is a genuine security mistake.

How it works

Base64 takes three bytes — 24 bits — and re-groups them into four 6-bit values, each mapped to a character from A–Z a–z 0–9 + /. Because 6 bits give 64 possibilities, every combination has a printable representation.

When the input is not a multiple of three bytes, the output is padded with = characters. This is why encoded strings so often end in one or two equals signs, and why the length is always a multiple of four.

InputBytesOutputPadding
Man3TWFunone
Ma2TWE=one
M1TQ==two

The 33% cost

Four output characters for every three input bytes means base64 is about 33% larger than the original, plus any line breaks. That overhead is the price of text safety, and it is why base64 is right for small payloads and wrong for large ones. Embedding a 2 MB image as a data URI produces 2.7 MB of markup that cannot be cached separately from the page.

Standard versus URL-safe

Standard base64 uses + and /, both of which have meaning in URLs — + is decoded as a space in query strings and / is a path separator. URL-safe base64 substitutes - and _ and usually drops the padding.

This variant is what JWTs use, which is why a JWT segment pasted into a standard decoder sometimes fails. If decoding produces garbage, converting - to + and _ to / and restoring padding almost always fixes it.

Where it is genuinely used

The mistake worth naming

Base64 provides no confidentiality whatsoever. Anyone can decode it in a browser console in one line. Encoded credentials in a configuration file, an API key in a request header, or a 'hidden' identifier in a URL are all fully readable. If something must be protected, encrypt it; if it must be verified, sign it. Base64 solves transport, not security.

Text and encoding

Base64 operates on bytes, not characters. Encoding text requires deciding on a character encoding first — nearly always UTF-8. A string containing non-ASCII characters encoded as UTF-8 and then base64 produces different output than the same string encoded as Latin-1. If a decoded result shows mangled accents or emoji, an encoding mismatch upstream is the usual cause.

Frequently Asked Questions

Is base64 a form of encryption?
No. It is a reversible encoding with no key. Anyone can decode it instantly. Use encryption for confidentiality and signing for integrity — base64 provides neither.
Why do encoded strings end in equals signs?
Padding. Base64 works on groups of three bytes; when the input length is not a multiple of three, one or two '=' characters pad the output to a multiple of four.
Why won't my JWT decode properly?
JWTs use URL-safe base64, which substitutes '-' for '+' and '_' for '/' and usually omits padding. Convert those characters back and restore the padding before using a standard decoder.
How much larger does base64 make data?
About 33%, plus any line breaks. Four characters are produced for every three input bytes. This is why it suits small payloads and is a poor choice for large files.
Should I embed images as base64 data URIs?
Only for very small assets such as icons. Larger images become 33% bigger, cannot be cached independently of the document, and block rendering of the file that contains them.
Is my data sent anywhere when I use this tool?
No. Encoding and decoding run entirely in your browser. Nothing you paste is transmitted or stored.

Related Developer Tools

Browse all Developer tools →