category-iconWEB TESTING

Base 64 in software testing (The Basics of Base64)

Mst. Afsana13 Dec 202405050
Blog Thumbnail

Base 64:

Base64 is a way of encoding binary data into a readable text format. It's commonly used in computing to ensure data can be safely transmitted or stored in systems that only work with text, like emails or JSON-based APIs.

How Base64 Works

Base64 is a simple and efficient way to encode binary data in text-friendly format. Here's how it operates:

1. Input Data

Base64 starts with raw binary data, which could be anything from text, images, audio files, or any other type of file.

2. Breaking Data into Groups

The binary data is split into groups of 3 bytes (24 bits).

Example: For the string Man, the ASCII values are:

M = 01001101

a = 01100001

n = 01101110

Combined as: 01001101 01100001 01101110 (24 bits).

3. Splitting into 6-bit Chunks

The 24-bit group is divided into four 6-bit chunks. Example: 01001101 01100001 01101110 becomes:

010011, 010110, 000101, 101110.

4. Mapping to Base64 Characters

Each 6-bit chunk is mapped to a character in the Base64 character set:

A-Z, a-z, 0-9, +, /

Example: 010011 maps to T, 010110 maps to W, 000101 maps to F, and 101110 maps to u.

5. Adding Padding (If Necessary)

If the original data doesn't divide evenly into 3 bytes, padding is added using the = symbol to make the Base64 output a multiple of 4 characters.

Example: Encoding the string Ma (2 bytes) produces TWE = with one = for padding.