Base64 Encoding & Decoding

Introduction to Base64

Base64 is an encoding scheme used to represent binary data in an ASCII string format by translating it into a radix-64 representation. It is commonly used to encode data for safe transmission over text-based protocols (like email or HTTP) where binary data might otherwise be corrupted or misinterpreted.

Base64 encoding takes 3 bytes of binary data (24 bits) and splits them into four 6-bit groups. Each 6-bit group is mapped to a character in the Base64 alphabet. If the data doesn't divide evenly into 3-byte chunks, padding (=) is added to make it a multiple of 4 characters.

Base64 Encoding Table

ValueCharacterValueCharacterValueCharacterValueCharacter
0A1B2C3D
4E5F6G7H
8I9J10K11L
12M13N14O15P
16Q17R18S19T
20U21V22W23X
24Y25Z26a27b
28c29d30e31f
32g33h34i35j
36k37l38m39n
40o41p42q43r
44s45t46u47v
48w49x50y51z
520531542553
564575586597
60861962+63/

Padding

Example