A digital image is a grid of tiny dots called pixels, and each pixel's colour is stored in binary. You learn what the resolution and the colour depth of an image are, how they change its quality and size, and how to work out the size of an image.
about 25 min1 simulation1 practice question
Lesson 3 of 3Show all lessonsHide
Try the code and the simulations beside the lesson.
A grid of pixels
Look very closely at a phone screen and you can see that the picture is made of tiny squares of colour. Each square is a pixel, which is short for picture element. An image stored this way is a series of pixels. The colour of each pixel is a binary number, so the whole image is converted to binary, which the computer processes.
On the left, an 8 by 8 grid of pixels showing a simple fir tree in black on white. On the right, the eight rows of the image as 8-bit binary numbers, one for each row, with 1 for black and 0 for white: 00010000, 00111000, 01111100, 11111110, 00111000, 01111100, 11111110 and 00010000.
The picture shows a small image of 8 by 8 pixels with only two colours. Each pixel needs just 1 bit: 1 for black and 0 for white. Each row of the image is one byte. The image needs 8×8=64 bits.
Resolution
The resolution of an image is the number of pixels in it. We usually give it as width by height, such as 800 by 600, which is 800×600=480000 pixels.
A higher resolution has more pixels, so it can show finer detail. The image looks sharper, especially when it is made bigger.
But every pixel must be stored, so the file is larger.
Colour depth
The colour depth is the number of bits used to represent the colour of each pixel.
With d bits each pixel can have 2d different colours.
1 bit gives 2 colours, 2 bits give 4, 8 bits give 256, and 24 bits give 224=16777216 colours.
A higher colour depth shows more shades, so colours look more natural and smooth.
But each pixel needs more bits, so the file is larger.
Both settings work the same way: as the resolution and the colour depth increase, the quality and the file size of the image both increase.
The size of an image file
Every pixel needs (colour depth) bits.
bits=width in pixels×height in pixels×colour depth
An image of 100 by 50 pixels with a colour depth of 8 bits needs 100×50×8=40000 bits, which is 40000÷8=5000 bytes.
What if you double both the width and the height? There are four times as many pixels, so the file is four times as large.
Practise with new numbers
Try it in Python
The program stores a tiny two-colour image as rows of bits and prints it with blocks. Then it works out the size for several colour depths.
Common mistakes
Adding the width and the height. The number of pixels is width times height.
Colours and bits. 8 bits give 28=256 colours, not 8 or 16 colours.
Forgetting to divide by 8 when the question asks for bytes.
Thinking resolution means the size on screen. Here it means the number of pixels.
Remember these
An image is a grid of pixels. Each pixel's colour is stored in binary.
Resolution: the number of pixels in the image.
Colour depth: the number of bits per pixel. d bits give 2d colours.
Higher resolution or colour depth: better quality and a larger file.
Bits = width × height × colour depth.
Check yourself
Try each one on your own first. If you are stuck, open a hint. Then check with Show the answer.
What is meant by the colour depth of an image?
How many colours can a pixel have with a colour depth of 4 bits?
An image is 60 pixels wide and 40 pixels high, with a colour depth of 2 bits. How many bits does it need?
The colour depth of an image goes up from 8 bits to 16 bits. The resolution stays the same. What happens to the file size?
Why might a website use a lower resolution for its pictures?
Enroll free in Text, Sound and Images in Binary
Every lesson is open to read. Enrolling also lets you:
Mark lessons done and carry on where you stopped.
Take the tests of this lesson and its course.
Count the course towards the certificate for its chapter.