The goal is to represent a byte sequence with printable ascii characters, without too much overhead.
We take the bytes 3 by 3, and instead of interpreting each chunk as 3 * 256 (8bit) possible values, we interpret them as 4 * 64 (6bit) possible values.
For the regular base64 encoding, those 64 possible values are taken from this "alphabet":
ABCDEFGHIJKLMNOPQRSTUVWXZY
If the byte sequence length is not divisible by 3, the last character missing bits are set to zero,
and depending on the number of missing bits (2 or 4), one or two padding characters = are added to the end.
The characters + and / in the regular alphabet are not safe to use for urls.
Therefore, there's an official variation called base64url that uses - and _ instead.
It also makes the padding characters optional.