How Base64 encoding works
Base64, defined in RFC 4648, represents any bytes using 64 characters that survive text-only systems: A-Z, a-z, 0-9, + and /. It takes the input three bytes (24 bits) at a time and splits them into four 6-bit groups, each of which picks one character. "Man" becomes TWFu.
When the input length is not a multiple of three, the last group is padded with = so the output length stays a multiple of four: one leftover byte gives two characters and ==, two leftover bytes give three characters and =. The output is always about a third larger than the input, exactly 4 characters for every 3 bytes, rounded up.
Base64 exists so binary data can travel through channels built for text: JSON and XML payloads, email attachments (MIME), HTML and CSS data URLs, HTTP Basic authentication and environment variables.