Base64 decoder/encoder

All You Need To Know About Base64 Encoding

Base64 is a set text encoding schemes of the same value in binary form. The set is usually used to represent binary data through an ASCII format. This can be done by simply translating the binary data into a simple radix 64 representation. For effective representation, each base64 digit should have exactly 64 bits of representation.

Design And Format Base64

To fully understand what base64 encoding is all about, one has to look at salient factors like design. The specific set of 64 characters used to represent the 64 place varies from time to time. There is, however, a general rule that each implementation always takes into account. The strategy calls for choosing 64 characters that fall under a common subset. The characters should also be printable.

Base 64 Encode Process

The base 64 encode process is simple. There are characters which are represented by binary values. The values are then joined together into 24-bit strings that produce other binary values. It does not end there. There are also groups of 6 bits which must be converted into separate numbers from left to right. Finally, the individual members get converted into values that correspond with Base64 characters. In summary, base 64 encoding converts 3 octets into 4 encoded characters.

Advanced Base64 Encode Process

It happens sometimes that the number of bytes that should be encoded is not divisible by three. In other words, there are just one or two input bytes for the last and only remaining 24-bit block. When this happens, extra bytes with value zero will be added to come up with three bytes. Conversion to base64 will, therefore, be easier. It can also happen that there is just one input byte. In such a case, all bits must be captured in the first 2 base 64 digits.

Base64 encoding example from string to code

Decode Base 64 With Padding

It is possible for you to decode base64 with padding. This may sound unnecessary in theory but it is not. That is because it is possible to calculate the total number of missing bytes from the total number of Base64 digits. Even with this provision, however, some implementations still insist that the padding character should be mandatory. A good example where the padding character is mandatory is concatenating several base64 encoded files.

When decoding any base64 text with padding, four characters are usually converted back to 3 bytes. There is the exception, though, like where a padding character exists. Four characters can be decoded for instance to just two bytes or four characters can be decoded to just one byte.

Base64 decoding example from code to string

Decoding Base64 Without Padding

It can be hard to achieve base64 without padding in some cases. That is because after the usual decoding of 4 special characters to 3 bytes, again and again, less than 4 encoded characters usually remain. That means that only 2 or sometimes 3 characters will remain. Encoding a simple character on the other hand is not possible. That is because one base64 character is made up of 6 bits. You will also need 8 bits to create a byte. It all boils down to a minimum of 2 base 64 characters.