How Base64 encoding works
Base64 represents any data, including binary data like images or encryption keys, using only 64 safe, printable characters: A–Z, a–z, 0–9, + and /. That lets binary data travel through systems that were designed for text, such as email, JSON, HTML attributes, URLs and HTTP headers. You see it in email attachments, data URIs for small images, JSON Web Tokens and HTTP Basic authentication.
How it works
The encoder takes the input three bytes (24 bits) at a time and splits them into four groups of 6 bits. Each 6-bit group is a number from 0 to 63, which maps to one character of the alphabet. When the input length is not a multiple of three, the output is padded with one or two = signs so its length is a multiple of four.
For example, the text Hi! is the bytes 72, 105, 33. In binary that is 010010 000110 100100 100001, which maps to SGkh.
It makes data about a third bigger
Every 3 bytes become 4 characters, so Base64 output is roughly 33% larger than the input. That is the price of being text-safe. It is fine for small items but a poor way to ship large files.
Base64 is not encryption
Anyone can decode Base64; it hides nothing. Never use it to protect passwords, tokens or personal data. Use real encryption for that, and treat Base64 only as a way to package bytes as text.
Text, Unicode and UTF-8
Base64 encodes bytes, not characters, so text first has to be turned into bytes. This tool uses UTF-8, the encoding used by almost every website and API, so accented letters, Chinese characters and emoji all round-trip correctly. (The browser's built-in btoa() function fails on any character outside Latin-1, which is a common source of bugs.) If decoded bytes are not valid UTF-8, the input was probably binary data such as an image rather than text.
URL-safe Base64
The standard + and / characters have special meanings in URLs and file names. The URL-safe variant (RFC 4648 section 5, sometimes called base64url) replaces them with - and _ and usually drops the = padding. JSON Web Tokens use it. When decoding, this tool accepts either alphabet, with or without padding, and ignores spaces and line breaks.