ArticleslgStudy

science

Base64

Base64 is a science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Base64 rather than just read about it. In short: Base64 is a binary-to-text encoding that uses 64 printable characters to represent each 6-bit segment of a sequence of byte values. As for all binary-to-text encodings, Base64 encoding enables transmitting binary data on a communication channel that only supports text.

Base64 — main illustration
Base64 — illustration

Key takeaways

  • Base64 belongs to science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Base64 to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Base64 from memory before moving on to harder problems.

Reference excerpt

Base64 is a binary-to-text encoding that uses 64 printable characters to represent each 6-bit segment of a sequence of byte values. As for all binary-to-text encodings, Base64 encoding enables transmitting binary data on a communication channel that only supports text. When comparing the original data to the resulting encoded data, Base64 encoding increases the size by 33% plus about 3% additional if inserting line breaks for typical line length. The earliest uses of this encoding were for dial-up communication between systems running the same operating system – for example, uuencode for UNIX and BinHex for the TRS-80 (later adapted for the Macintosh) – and could therefore make more assumptions about what characters were safe to use. For instance, uuencode uses uppercase letters, digits, and many punctuation characters, but no lowercase.

Applications

Notable applications of Base64:

Web pages Base64 encoding is prevalent on the World Wide Web where it is often used to embed binary data such as a digital image in text such as HTML and CSS. E-mail attachments Base64 is 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 correctly transmit messages with attached binary information. Embed binary data in a text file For example, to include the data of an image in a script to avoid depending on external files. Embed binary data in XML To embed binary data in an XML file, using a syntax similar to <data encoding="base64">...</data> e.g. favicons in Firefox's exported bookmarks.html. PDF files To embed a PDF file in an HTML page. Embedded elements Although not part of the official specification for the SVG format, some viewers can interpret Base64 when used for embedded elements, such as raster images inside SVG files. Preventing delimiter collisions To transmit and store text that might otherwise cause delimiter collision. LDAP Data Interchange Format To encode character strings in LDAP Data Interchange Format files. Data URI schemes The data URI scheme can use Base64 to represent file contents. For instance, background images and fonts can be specified in a CSS stylesheet file as data: URIs, instead of being supplied in separate files. Leverage clipboard To store/transmit relatively small amounts of binary data via a computer's text clipboard functionality, especially in cases where the information doesn't warrant being permanently saved or when information must be quickly sent between a wide variety of different, potentially incompatible programs. An example is the representation of the public keys of cryptocurrency recipients as Base64 encoded text strings, which can be easily copied and pasted into users' wallet software. Support human verification Binary data that must be quickly verified by humans as a safety mechanism, such as file checksums or key fingerprints, is often represented in Base64 for easy checking, sometimes with additional formatting, such as separating each group of four characters in the representation of a PGP key fingerprint with a space. QR code encoding A QR code, which contains binary data, is sometimes stored as Base64 since it is more likely that a QR code reader accurately decodes text than binary data. Also, some devices more readily save text from a QR code than potentially malicious binary data.

Alphabet The set of characters used to represent the values for each base-64 digit (value from 0 to 63) differs slightly between the variations of Base64. The general strategy is to use printable characters that are common to most character encodings. This tends to result in data remaining unchanged as it moves through information systems, such as email, that were traditionally not 8-bit clean. Typically, an encoding uses A–Z, a–z, and 0–9 for the first 62 values. Many variants use + and / for the last two. Per RFC 4648 §4, the following table lists the characters used for each numeric value. To indicate padding, = is used.

Base64URL encoding replaces + with - and / with _ to make the encoded string HTTP-safe and avoid the need for escaping.

Examples To simplify explanation, the example below uses plain text for input. While this is done in practice, a much more common use is encoding images and other data that are normally not representable with plain text, and the result then represents the data in a printable text format. For the input data:

Many hands make light work.

The typical Base64 representation is:

TWFueSBoYW5kcyBtYWtlIGxpZ2h0IHdvcmsu

Encoding when no padding needed Each input sequence of 6 bits (which can encode 26 = 64 values) is mapped to a Base64 alphabet letter. Therefore, Base64 encoding results in four characters for each three input bytes. Assuming the input is ASCII or similar, the byte-data for the first three characters 'M', 'a', 'n' are values 77, 97, and 110 which in 8-bit binary representation are 01001101, 01100001, and 01101110. Joining these representations and splitting into 6-bit groups gives:

010011 010110 000101 101110

Which encodes the string TWFu (per ASCII or similar). The following table shows how input is encoded. For example, the letter 'M' has the value 77 (per ASCII and similar). The first 6 bits of the value is 010011 or 19 decimal which maps to Base64 letter 'T' which has a value 84 (per ASCII and similar).

Encoding with one padding character If the input consists of a number of bytes that is 2 more than a multiple of 3 (e.g. 'M', 'a'), then the last 2 bytes (16 bits) are encoded in 3 Base64 digits (18 bits). The two least significant bits of the last content-bearing 6-bit block are treated as zero for encoding and discarded for decoding (along with the trailing = padding character).

Encoding with two padding characters If the input consists of a number of bytes that is 1 more than a multiple of 3 (e.g. 'M'), then the last 8 bits are represented in 2 Base64 digits (12 bits). The four least significant bits of the last content-bearing 6-bit block are treated as zero for encoding and discarded for decoding (along with the trailing two = padding characters):

Decoding with padding When decoding, each sequence of four encoded characters is converted to three output bytes, but with a single padding character the final 4 characters decode to only two bytes, or with two padding characters, the final 4 characters decode to a single byte. For example:

… excerpt ends here. Continue reading the full article.

Worked examples

Example 1 — a first encounter with Base64

Start with the simplest possible case. Write down what Base64 claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Base64 before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Base64 ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Base64

In research
Base64 appears in science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Base64 in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Base64 is common in secondary-school and first-year university syllabi. It links to neighbouring topics Binary-to-text encoding formats, Data serialization formats, Email, so understanding it makes those chapters shorter.
In everyday life
Look for Base64 outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Base64” →

How to study Base64 in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Base64 means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Base64 out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Base64 in simple terms?

Base64 is a binary-to-text encoding that uses 64 printable characters to represent each 6-bit segment of a sequence of byte values. As for all binary-to-text encodings, Base64 encoding enables transmitting binary data on a communication channel that only supports text.

Why does Base64 matter?

Because it connects several science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Base64?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Base64.

Tags

  • Binary-to-text encoding formats
  • Data serialization formats
  • Email
  • Internet Standards
  • Power-of-two numeral systems
  • Usenet

Keep exploring