Encode Base64

What is a Base64?

Base64 is an encoding scheme that converts binary data into a text format using 64 characters (A-Z, a-z, 0-9, +, and /). It's commonly used to transfer data over text-based protocols like email or JSON, ensuring that binary data remains intact by representing it as readable text.

How does encoding work?

The input is UTF-8 encoded and divided into 6-bit segments, with each segment mapped to a corresponding Base64 character from the encoding table below and then combined into a single output. If the data length isn't a multiple of 3, padding characters (=) are added to maintain a consistent output length.

Example Encoding: "Cat"

  1. Convert to Binary: Convert each character to binary using the ASCII Table: C = 01000011, a = 01100001, t = 01110100. Combined, "Cat" becomes: 01000011 01100001 01110100.

  2. Split into 6-Bit Chunks: Divide the 24-bit binary string into four 6-bit segments:
    010000 110110 000101 110100.

  3. Map to Base64 Characters: Match each 6-bit segment to its Base64 character, according to the table below: 010000 = Q, 110110 = 2, 000101 = F, 110100 = 0

  4. Result: The Base64 encoding of "Cat" is Q2F0.

    If padding were needed (when the input isn't divisible by 3 bytes), = characters would be added to ensure the encoded length is a multiple of 4.

Base64 Encoding Table (RFC 4648)

The Base64 alphabet contains 64 characters that map 6-bit binary blocks to ASCII characters. There are several Base64 variants, with the most widely used being RFC 4648, which is also the standard used on this site. Each binary block is shown as a decimal number for easier reference. To convert decimal numbers to binary, you can use a Binary Converter.

0 = A8 = I16 = Q24 = Y32 = g40 = o48 = w56 = 4
1 = B9 = J17 = R25 = Z33 = h41 = p49 = x57 = 5
2 = C10 = K18 = S26 = a34 = i42 = q50 = y58 = 6
3 = D11 = L19 = T27 = b35 = j43 = r51 = z59 = 7
4 = E12 = M20 = U28 = c36 = k44 = s52 = 060 = 8
5 = F13 = N21 = V29 = d37 = l45 = t53 = 161 = 9
6 = G14 = O22 = W30 = e38 = m46 = u54 = 262 = +
7 = H15 = P23 = X31 = f39 = n47 = v55 = 363 = /
Padding = =