In this lesson, students will begin to explore the way digital images are encoded in binary. The class begins by asking students to invent their own image encoding protocol in order to familiarize themselves with some of the subtle complications of encoding images, namely the need for other data, called metadata, that describes properties of the image necessary for rendering it. Students will learn about pixels, raster images, and what an image file format is.



Students will be able to:


The main purpose of this lesson is for students to exhibit some creativity while getting some hands-on experience manipulating binary data that represents something other than plain numbers or text. Connections to abstraction in data can be made here. Connections can be made back to file sizes and file formats here as well - e.g. how many bytes does it take to store an image vs. text? If you want to broach the subject, the concept of data compression can come in here too - it is interesting to think about how a black and white image might be compressed. You should be aware that this lesson largely acts as a stepping stone to the next lesson which addresses how RGB colors are represented in binary.

Image file types have some similarities to data packets we saw in the Internet unit -- because images must include metadata, or data about the data. The data of a black-and-white image is the list of bits that represent whether each pixel is on or off. To create the image, however, we must also know how wide and tall the image is in order to recreate it accurately. This necessitates the creation of a file format which clearly defines how this metadata will be encoded, since it is crucial for interpreting the subsequent data of the image. It is similar to how an internet packet doesn't only contain the data you need to send, but must also include metadata like the to and from addresses and packet number.

Digital images can be stored in many formats, but one of the most common formats is "raster." Raster images store the image as an array of individual pixels, each of which has a particular color. Higher-quality images can be obtained by decreasing the size of the pixels (resolution). While full color will be addressed in the next lesson, an important idea here is that images on computer screens are created with light by illuminating pixels on the screen. This is why it is typical in a black and white image for the value 1 to represent white - it means turn the light on - and 0 represents black - light off. If you were drawing on paper you might do the inverse.

Getting Started

Back in the Internet Unit you encoded a line-drawing image as a list of numbers that made up the coordinates of the points in the image. That works for line drawings, but how might you encode a different kind of image? Today we’re going to consider how you might use bits to encode a photographic image.

Invent an Encoding Scheme

Have students work in pairs for this activity.

Teacher Tip: Alternative Tools

For students who may have difficulty using graphing paper to create an image, we suggest using a lego board and several round "1x1" lego plates to represent the graph paper and the pixels for this lesson. Each peg on the lego board will represent one pixel and the lego pieces will be added to the board to signify an illuminated pixel in the B&W image.

Prompt: Using a piece of graph paper, draw out a simple image such as the letter x, a plus sign, or a checkerboard design. Have each square on the graph paper represent a "pixel." Discuss with your partner how you could encode the "pixels" that create your image in binary.

Record your ideas for your encoding on a piece of paper. As you Develop your encoding consider:


What we've discovered is that the data for our image file must contain more than just a 0 or 1 for every pixel. It must contain other data that describes the pixel data. This is called metadata. In this case the metadata encodes the width and height of the image. We've seen forms of metadata before. For example: an internet packet. The packet contains the data that needs to be sent, but also other data like the to and from address and packet number.

Pro Tip: The purpose of this little concept invention activity is to be creative and to get the mind moving. There is no exact right answer that we're going for here. There are many clever and interesting ways this could be done. Most students will likely end up saying that each pixel should be represented with either a 0 or a 1. But what we really want to draw out is the idea of metadata. Simply encoding the pixel data is not enough. We also need to encode the width and height of the image, or the image could not be recreated - other than through trial and error.


Allow students to create and encode their own image of anything they would like. The image can be any size, permitting that it will fit on the graphing paper. Try and have students depict something in their image such as their initials, their name written out or an icon of some sort. The image does not have to be a perfect square. Have students sketch out their image and then come up with the bits that create the image using an encoding scheme which includes the metadata (width and height) for the image. The encoding scheme we will be using for this activity is similar to the one shown below and should include 8 bits (1 byte) for the width (bits 0 - 7), 8 bits (1 byte) for the height (bits 8 - 15), and the remaining bits for the pixel data (the number of bits used for the pixel data will vary depending on the size of the image - in this activity we will use 1-bit for each pixel in the image). In this example the image is 3 pixels wide, 5 pixels high, and the pixel data will recreate an image of the letter "A."

Image of bits used to create an image using an encoding scheme with necessary metadataImage of bits used to create an image broken up into width, height, and pixel data

Give students some time to sketch out their images and come up with the correct bits to recreate their image before having them trade their bits with a classmate to see if they can recreate the image using the bits provided.

Note: It is much easier to encode the image if you space out the bits to match the rows and columns of pixels you are turning "ON/WHITE" (1) and the pixels you are turning "OFF/BLACK" (0).

Wrap Up

The image file protocol we used contains "metadata": the width and height. Metadata is "data about the data" that might be required to encode or decode the bits. For example, you couldn’t render the B&W image properly without somehow including the dimensions.


Standards Alignment