What is Base64 Encoding & Decoding? (2024)

What is Base 64 Encoding?

Introduction

Base64 encoding is a format designed to prevent communication “mishaps” during the transfer of binary information. It achieves this through the conversion of binary data and a “lookup table” — data is eventually made in a stream of ASCII characters, which can then be transmitted and decoded. On base 64 encoded data, the resultant string is always larger than the original (i.e. this is not a compression algorithm). Another important distinction is that base 64 does not encrypt any information — it uses a “standard” table of characters to encode and decode information. In other words, any base-64 string can be decoded, as long as the string was encoded using a standard set of characters (which the decoder can also understand).

Uses for Base64

On top of being used for safely encoding image/media data (you may have seen images on the web encoded in the following format: data:image/png;base64,(...)), it is used for SSL certificates, email transmissions, and virtually any transfer of information that requires special (control) characters to be escaped.

Encoding Base64

While many programming languages (e.g. Java, Python, JS) include built-in functions to facilitate the conversion of base64 encoded information and binary data, the algorithm used to perform the conversion is relatively simple. Starting with binary information, base 64 splits a binary string into 6-bit groups (note: each zero or one in a binary string is one bit) of three bytes. The result is an ASCII-readable string that can be safely transmitted and received.

For the sake of simplicity, we’ll use a short string to demonstrate the encoding process. Suppose we have “hi” as our string, the ASCII equivalent being: 104 (h), 105 (i).

We need to convert the ASCII string to its binary representation:

01101000 01101001 (0110100001101001 without spaces)

Now, divide the binary representation into 6-bit groups:

011010 000110 100100

What is Base64 Encoding & Decoding? (1)

With the binary representation of our string, we can then make use of an ASCII lookup table above. We get the following ASCII characters for our string’s binary representation:

  • 011010 => “a”
  • 000110 => “G”
  • 100100 => “k”

Before we can finish off the conversion process, it is important to notice the missing padding: base 64 strings must be groups of 3 characters (6 byte binary representations). As such, our string “hi” only has 2 characters; this means that we need to insert a “=” at the end of the string to make this a valid base 64 string.

The result is finally: “aGk=” (hi).

Decoding Base64

Decoding base64 strings follows a similar process, just in reverse. Using the result from the previous section (“aGk=”), we will use the same Base 64 lookup table:

  • “a” => 011010
  • “G” => 000110
  • “k” => 100100
  • “=” => padding

This leaves us with three 6-bit binary groups:

011010 000110 100100

Converting this back to 8-bit groups, we get (the last two zeroes can be ignored):

01101000 01101001

… which results in “hi” in ASCII.

Conclusion

Whether you’re sending an email, or trying to encode binary streams (images, videos, etc.), base 64 can be seen in many applications. While the resulting strings are larger, using base 64 encoding is a reliable way to ensure that a transmission of binary information is never “misinterpreted.”

What is Base64 Encoding & Decoding? (2024)

FAQs

What is Base64 encoding and decoding? ›

Base64 is an encoding scheme, not an encryption method. It is designed for data representation and transmission, not for data security. Base64 encoded data can be easily decoded, so it should not be used to protect sensitive information. For secure data transmission, proper encryption methods should be used.

What is the Base64 encoding term? ›

Details of the Base64 encoding

The general rule is to choose a set of 64 characters that is both 1) part of a subset common to most encodings, and 2) also printable. This combination leaves the data unlikely to be modified in transit through systems such as email, which were traditionally not 8-bit clean.

How safe is Base64 encoding? ›

Base64 encoding can disguise malicious code as noise that is imperceptible to humans. While Base64 encoding has legitimate uses for data transfers, it's important to be cautious with images containing Base64-encoded strings, particularly if they arrive from unknown sources.

Is Base64 encoding good? ›

Base64 allowed us to camouflage any data as text in order to pass validation when transmitted between email servers. It also ensured that this pseudo-text contained only safe characters, that is 1) only printable ones and 2) only those that have no special meaning in SMTP and (hopefully) in most other systems.

What is an example of Base64 encoding? ›

Base64 uses 6-bit characters grouped into 24-bit sequences. For example, consider the sentence Hi\n, where the \n represents a newline. The first step in the encoding process is to obtain the binary representation of each ASCII character.

What is the meaning of encode and decode? ›

Encoding is essentially a writing process, whereas decoding is a reading process. Encoding breaks a spoken word down into parts that are written or spelled out, while decoding breaks a written word into parts that are verbally spoken.

How to tell if something is Base64-encoded? ›

Encoded data will always have the following characteristic:
  1. The length of a Base64-encoded string is always a multiple of 4.
  2. Only these characters are used by the encryption: “A” to “Z”, “a” to “z”, “0” to “9”, “+” and “/”

Why encode file to Base64? ›

Base64 is also widely used for sending e-mail attachments, because SMTP – in its original form – was designed to transport 7-bit ASCII characters only. Encoding an attachment as Base64 before sending, and then decoding when received, assures older SMTP servers will not interfere with the attachment.

What is the function of Base64 encode? ›

BASE64ENCODE is a function that manipulates all string data types (BIT, BLOB, and CHARACTER). BASE64ENCODE returns a CHARACTER string that contains the base64-encoded version of the source string.

Why do hackers use Base64? ›

Why Might Attackers Use Base64? Base64 is often used to hide the plaintext elements of an attack that can't be concealed under the veil of encryption. Look for Base64 use in early stages of attacks, when the breach is narrow.

What does Base64 look like? ›

Base-64 maps 3 bytes (8 x 3 = 24 bits) in 4 characters that span 6-bits (6 x 4 = 24 bits). The result looks something like "TWFuIGlzIGRpc3Rpb...". Therefore the bloating is only a mere 4/3 = 1.3333333 times the original.

What are the cons of Base64? ›

Base64 files are bigger than the original file - you are wasting user transfer (the user can use mobile device, some countries still have internet limits in a cable) You have to reverse the process on the server which costs you more money as usually you pay for the CPU utilization.

What is the point of encoding? ›

Encoding plays a vital role in data compression by representing information in a more efficient manner. This reduces the amount of storage or bandwidth required. Popular techniques, like Huffman coding, use encoding to assign shorter codes to frequently occurring data patterns, optimizing space utilization.

What are the benefits of Base64 encoding images? ›

Data Transmission: Base64 ensures the safe transmission of data by converting binary data into a format that can survive transport through layers designed to deal with text. This ensures that the data remains unaltered during transport.

Is Base64 encoding same as UTF-8? ›

No, Base64 and UTF-8 serve different purposes in data encoding. Base64: It is a binary-to-text encoding scheme that represents binary data in an ASCII string format by converting it into a radix-64 representation.

Is Base64 encoding the same as encryption? ›

Base64 is such an encoding algorithm. It merely encodes arbitrary data using only ASCII characters, which is useful in many situations in which non-ASCII characters may not be handled correctly. You can encode and decode Base64 back and forth all day long; there's no secret, no protection, no encryption.

Top Articles
The average wedding costs $30,000–here's how to save enough for your big day
How can I tell if my wallet is RFID protected?
Netr Aerial Viewer
Worcester Weather Underground
Swimgs Yuzzle Wuzzle Yups Wits Sadie Plant Tune 3 Tabs Winnie The Pooh Halloween Bob The Builder Christmas Autumns Cow Dog Pig Tim Cook’s Birthday Buff Work It Out Wombats Pineview Playtime Chronicles Day Of The Dead The Alpha Baa Baa Twinkle
Combat level
Online Reading Resources for Students & Teachers | Raz-Kids
Toyota Campers For Sale Craigslist
Autobell Car Wash Hickory Reviews
A Fashion Lover's Guide To Copenhagen
FIX: Spacebar, Enter, or Backspace Not Working
Oriellys St James Mn
Erin Kate Dolan Twitter
Oxford House Peoria Il
Immediate Action Pathfinder
Best Fare Finder Avanti
Wisconsin Women's Volleyball Team Leaked Pictures
Google Feud Unblocked 6969
Download Center | Habasit
"Une héroïne" : les funérailles de Rebecca Cheptegei, athlète olympique immolée par son compagnon | TF1 INFO
Free Online Games on CrazyGames | Play Now!
Christina Steele And Nathaniel Hadley Novel
Jeff Now Phone Number
1973 Coupe Comparo: HQ GTS 350 + XA Falcon GT + VH Charger E55 + Leyland Force 7V
Bellin Patient Portal
Troy Gamefarm Prices
Spiritual Meaning Of Snake Tattoo: Healing And Rebirth!
4 Times Rihanna Showed Solidarity for Social Movements Around the World
Tuw Academic Calendar
Snohomish Hairmasters
Grave Digger Wynncraft
Delete Verizon Cloud
Infinite Campus Asd20
Orange Park Dog Racing Results
1475 Akron Way Forney Tx 75126
Gina's Pizza Port Charlotte Fl
Lil Durk's Brother DThang Killed in Harvey, Illinois, ME Confirms
Santa Cruz California Craigslist
Gold Nugget at the Golden Nugget
Babylon 2022 Showtimes Near Cinemark Downey And Xd
Studio 22 Nashville Review
Eastern New Mexico News Obituaries
Booknet.com Contract Marriage 2
Royals Yankees Score
Race Deepwoken
Theater X Orange Heights Florida
Meee Ruh
Is Chanel West Coast Pregnant Due Date
Grand Park Baseball Tournaments
BYU Football: Instant Observations From Blowout Win At Wyoming
O'reilly's Eastman Georgia
La Fitness Oxford Valley Class Schedule
Latest Posts
Article information

Author: Melvina Ondricka

Last Updated:

Views: 5889

Rating: 4.8 / 5 (48 voted)

Reviews: 87% of readers found this page helpful

Author information

Name: Melvina Ondricka

Birthday: 2000-12-23

Address: Suite 382 139 Shaniqua Locks, Paulaborough, UT 90498

Phone: +636383657021

Job: Dynamic Government Specialist

Hobby: Kite flying, Watching movies, Knitting, Model building, Reading, Wood carving, Paintball

Introduction: My name is Melvina Ondricka, I am a helpful, fancy, friendly, innocent, outstanding, courageous, thoughtful person who loves writing and wants to share my knowledge and understanding with you.