Base64 IconBase64 Converter

Text Encoding and Decoding

Image Encoding and Decoding

Introduction

Base64 encoding is a commonly used method to convert binary data into text. It takes every set of 3 bytes (24 bits in total) and converts them into 4 sets of 6 bits (also 24 bits in total). Then, it adds two zeros in front of each of these 4 sets of 6 bits, forming 4 complete 8-bit bytes. When the input data's byte count is not a multiple of 3, Base64 uses padding with zeros and may add one or two '=' characters at the end of the encoded result as padding indicators. To ensure that the encoded text is human-readable, Base64 defines an encoding table containing 64 characters, which is also the origin of the name 'Base64'.

Base64 Encoding Table

ValueCharacterValueCharacterValueCharacterValueCharacter
0A16Q32g48w
1B17R33h49x
2C18S34i50y
3D19T35j51z
4E20U36k520
5F21V37l531
6G22W38m542
7H23X39n553
8I24Y40o564
9J25Z41p575
10K26a42q586
11L27b43r597
12M28c44s608
13N29d45t619
14O30e46u62+
15P31f47v63/

Benefits of Using Base64

  • Textual Representation of Binary Data:Base64 encoding converts binary data into plain text format, allowing data to be transmitted in systems that do not support binary transfer, such as email.
  • Data Simplification:Through Base64 encoding, data can be simplified to include only ASCII characters, ensuring that it can be correctly parsed across various systems and protocols.
  • Secure Transmission:Base64 encoding can serve as a simple data obfuscation technique. While it doesn't provide true encryption security, it can prevent data from being easily readable.
  • Data Embedding:Base64 encoding is commonly used to embed small binary data, such as images, into text files or HTML, avoiding the need for additional HTTP requests.

Use of Base64 in HTML and CSS

Usage in HTML

In HTML, Base64 encoding is commonly used to embed image data, thereby avoiding additional HTTP requests. This is achieved using "data URL."

<img src="data:image/png;base64,iVBORw0...(base64 encoded data)" alt="Description">

Usage in CSS

In CSS, Base64 encoding can be used to embed image data into style sheets, reducing external resource requests and improving page load speed.

.background-icon { background-image: url(data:image/png;base64,iVBORw0...(base64 encoded data)); }

Note: While Base64 encoding can reduce HTTP requests, it increases the size of HTML or CSS files. Therefore, it is best used only for small images or resources.

Privacy Statement: This web tool interaction will not collect any of your private data.