What Is Base64 Encoding

Base64 is an encoding technique, which converts binary data, such as images and video, into ASCII format (an encoding scheme for representing text data in a computer systems.). Since binary data consists of strings of 0s and 1s, Base64 encoding works by converting these characters into a definite set of ASCII. The result can be easily decoded by mapping the ASCII characters into the binary value. Below you can find a list of standard ASCII characters used in Base64 encoding.

Number characters: 0-9.Uppercase alphabet characters: A-Z.Lowercase alphabet characters: a-z.Two special characters: “/.” and “+”.

Why Is Base64 Encoding Used

When performing a file transfer online, binary data from the file is chopped into chunks which are called packets. These are then sent to the receiver using different protocols. Here is where the problem arises. If the receiver is unable to decode the binary file format from the sender, it can lead to data loss or corruption. Therefore, it’s considered good practice to first covert the file using Base64 encoding before sending it to the user. Base64 will encode the characters into ASCII format, which the majority of machines can read. And given the wide adoption of Base64 encoding, you can basically employ Base64 encoding on any machine.

What Is Base64 Encoding Used For

Base64 is widely used to encode text, images, musics, videos etc that you want to transmit across the web. One of the established use cases for Base64 is email attachments. Files attached to an email are encoded using Base64 behind the scenes before they are sent off along with the email to their destination. With Base64, encoded images can directly be added to HTML documents or in CSS files. This technique can help reduce the number of requests from clients and make your website more performant. You’ll need make sure to compress the image before encoding, though. Otherwise it will result into very big file sizes and slow down the website (alternatively, you can use webp file format to compress the image). If you are transferring a big BLOB (Binary Large Object File) across the internet, it’s actually mandatory to encode the data using Base64. Otherwise if some network packets happen to get lost during the transfer, the data inside the file may become corrupted and your file will be no longer usable. Another very popular but rather niche use for Base64 encoding is setting a custom iPhone charging sound. The new charging sound can be Base 64-encoded to ASCII using the Shortcuts app on Apple’s mobile devices.

How to Encode Data with Base64 in Javascript

To encode and decode data with Base64, you can take advantage of the two helper functions atob() and btoa() in Javascript. The name of these functions represents their utility. atob() function translates into ASCII to binary and btoa() means binary to ASCII.

How to Encode Data with Base64 in Python

In Python, you can use the built-in Base64 Python standard package.

How to Encode & Decode with Base64 in Linux

Every Linux distribution comes with a Base64 encoding and decoding utility. If you are on Windows, you can use the Windows subsystem for Linux (WSL) to run the the terminal commands examined below.

With Command Line

Using Online Base64 Converters

There are many online Base64 converters out there, but rapidtable’s Base64 converter stands out. This online tool provides a handy way to encode and decode Base64 texts and images. To encode a text string, simply paste your string in the text area and hit the the encode button. This tool can also support text files as an input. In the character encoding section, you also have additional options such as ASCII, UTF8, UTF16 etc. Other online easy-to-use Base64 converters include:

Base64DecodeEncodeCodeBeautifyEmn178

Image credit: Markus Spiske via Unsplash All screenshots by Hrishikesh Pathak