HelpContactFor teachers and institutes
>_StemPy Lab
Mock TestsClasses

>_StemPy Lab

Learn. Solve. Code the solutions. Test yourself.

Live examsFree mock exams, timed and rankedEveryone starts together, and your score and rank come the moment it ends.See the exams →

Learn

  • Physics
  • Chemistry
  • Mathematics
  • Biology
  • Python Programming
  • Statistics & Data Science
  • Computer Science
  • Classes
  • Groups

Practice

  • Problems
  • Quizzes
  • Mock Tests
  • Prepare for an Exam
  • Question Sets
  • Exams
  • Certificates
  • Python Labs
  • AI Practice Generator
  • Student-Created Tests

Community

  • Discussions
  • Resources
  • Notes
  • Glossary
  • Blog

Account

  • Log in
© 2026 senLearn. All rights reserved.HelpFor SchoolsAboutContactPrivacy PolicyTerms of UseRefund Policy
Storage Units and Compression
  1. 1Units of data storage
  2. 2Calculating file sizes
  3. 3Compression: lossy, lossless and run-length encoding
  1. Computer Science
  2. /Storage Units and Compression
  3. /Calculating file sizes

Course 1.3·Lesson 2 of 3

Calculating file sizes

In the previous course you found the size of an image or a sound in bits. Now you give that size in the unit the question asks for: bytes, kibibytes or mebibytes. You follow one clear chain of steps, always using 1024.

about 25 min1 simulation1 practice question
Lesson 2 of 3Show all lessonsHide
Storage Units and Compression
  1. 1Units of data storage
  2. 2Calculating file sizes
  3. 3Compression: lossy, lossless and run-length encoding

Try the code and the simulations beside the lesson.

The chain of steps

A file-size question gives you the facts and names the unit it wants. Answers must be in that unit. Every question follows the same chain.

A chain of four boxes from left to right: bits, bytes, KiB, MiB. The arrow from bits to bytes is labelled divide by 8, and the arrows from bytes to KiB and from KiB to MiB are each labelled divide by 1024. Under the bits box are the two rules: image = width times height times colour depth, and sound = sample rate times resolution times seconds.
  1. Bits. Use the rule for the kind of file.
  2. Bytes. Divide by 8.
  3. KiB. Divide by 1024.
  4. MiB. Divide by 1024 again, and so on up the ladder.

Stop as soon as you reach the unit the question asks for.

The rules for the bits come from the previous course.

  • Image: bits === width ×\times× height ×\times× colour depth.
  • Sound: bits === sample rate ×\times× sample resolution ×\times× length in seconds.

An image in MiB

A photo is 1024 pixels wide and 768 pixels high, with a colour depth of 24 bits. What is its size in MiB?

  1. Bits. 1024×768×24=188743681024 \times 768 \times 24 = 188743681024×768×24=18874368 bits.
  2. Bytes. 18874368÷8=235929618874368 \div 8 = 235929618874368÷8=2359296 bytes.
  3. KiB. 2359296÷1024=23042359296 \div 1024 = 23042359296÷1024=2304 KiB.
  4. MiB. 2304÷1024=2.252304 \div 1024 = 2.252304÷1024=2.25 MiB.

A short cut: 24 bits is 3 bytes, so each pixel takes 3 bytes. 1024×768×3=23592961024 \times 768 \times 3 = 23592961024×768×3=2359296 bytes, the same as before.

A sound in KiB and MiB

A recording is sampled 8192 times a second, with a sample resolution of 16 bits, for one minute. Give its size in KiB and in MiB.

  1. Seconds. One minute is 60 seconds. Always change the time to seconds first.
  2. Bits. 8192×16×60=78643208192 \times 16 \times 60 = 78643208192×16×60=7864320 bits.
  3. Bytes. 7864320÷8=9830407864320 \div 8 = 9830407864320÷8=983040 bytes.
  4. KiB. 983040÷1024=960983040 \div 1024 = 960983040÷1024=960 KiB.
  5. MiB. 960÷1024=0.9375960 \div 1024 = 0.9375960÷1024=0.9375 MiB.

How many will fit?

Another kind of question asks how many files fit on a device. Put both sizes in the same unit, divide, and round down, because part of a file is no use.

A memory stick holds 1 GiB. Each song is 4 MiB. 1 GiB is 1024 MiB, and 1024÷4=2561024 \div 4 = 2561024÷4=256. So 256 songs fit.

Practise with new numbers

Try it in Python

The program has one function for the bits of an image and one for a sound, and a third that changes bits into any unit. It prints the two worked examples of this lesson.

Read it first. Then run it. Do the answers match the worked examples?

1. Change the sound to two minutes. Predict the size in MiB before you run it.

2. Ask for the photo in "GiB". Is the number bigger or smaller than in MiB?

Common mistakes

  • Stopping too soon. If the question asks for MiB, a size in bytes is not the answer.
  • Using 1000 instead of 1024.
  • Forgetting to change minutes to seconds in a sound question.
  • Rounding up the number of files. Only whole files fit, so round down.

Remember these

  • Bits, then divide by 8 for bytes, then by 1024 for each step up.
  • Image bits === width ×\times× height ×\times× colour depth. Sound bits === rate ×\times× resolution ×\times× seconds.
  • Give the answer in the unit the question asks for.
  • To count files that fit, use one unit for both sizes and round down.

Check yourself

Try each one on your own first. If you are stuck, open a hint. Then check with Show the answer.

  1. An image is 256 by 128 pixels with a colour depth of 8 bits. What is its size in KiB?
  1. A sound file is 3 MiB. How many bytes is that?
  1. A recording is sampled 4096 times a second at 8 bits for 20 seconds. What is its size in KiB?
  1. A card holds 2 GiB. Each video is 300 MiB. How many videos fit?
  1. Why must you round down when you count files that fit?

Enroll free in Storage Units and Compression

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.
No payment. You can leave at any time.

Problems (4)

A game background is 512 pixels wide and 256 pixels high, with a colour depth of 8 bits…Easy · High School (9–10) · by StemPy Lab
A music app records 2 minutes of sound at 8192 samples a second, with a sample resolution of 16…Medium · High School (9–10) · by StemPy Lab
A camera takes photos of 2048 by 1536 pixels with a colour depth of 24 bits…Medium · High School (9–10) · by StemPy Lab
Next: lesson 3Compression: lossy, lossless and run-length encoding
← Storage Units and Compression
← Units of data storageCompression: lossy, lossless and run-length encoding →

Discussion (0)

Log in to join the discussion.

Loading…

1 Python program
5 questions to check yourself

This lesson is free to read. Enroll free to keep your place and take the tests.

An image is 800 pixels wide and 600 pixels high…Hard · High School (9–10) · by StemPy Lab

Python Labs (1)

A file-size calculatorPython Lab · by StemPy Lab