{"base":{"id":"cs10-07","subject":"Data representation","title":"File size and compression","scene":"bin10","steps":[{"mode":"units","eyebrow":"Storage units","title":"From bits to tebibytes","body":"8 bits make a byte. After that, each unit is 1024 times bigger: kibibyte (KiB), mebibyte (MiB), gibibyte (GiB), tebibyte (TiB). Slide up the ladder and see what each holds.","controls":[{"id":"p","label":"Unit","min":0,"max":6,"step":1,"value":3,"hideValue":true}]},{"mode":"imgsize","eyebrow":"Image file size","title":"Width × height × colour depth","body":"An uncompressed image needs one colour code per pixel. Multiply the pixels by the bits per pixel, divide by 8 for bytes, then by 1024 twice for MiB. Change the settings.","controls":[{"id":"res","label":"Resolution (640×480 up to 4000×3000)","min":0,"max":3,"step":1,"value":2,"hideValue":true},{"id":"depth","label":"Colour depth (1, 8, 16 or 24 bits)","min":0,"max":3,"step":1,"value":3,"hideValue":true}]},{"mode":"rle","eyebrow":"Lossless compression","title":"Run-length encoding","body":"Lossless compression makes a file smaller and gives back the exact original. Run-length encoding replaces runs of the same value with a count. Try three kinds of data. One gets bigger!","actions":[{"id":"r0","label":"Pixel row"},{"id":"r1","label":"Letters"},{"id":"r2","label":"No repeats"}]},{"mode":"lossy","eyebrow":"Lossy compression","title":"Throw away what you won't notice","body":"Lossy compression removes detail that people hardly see or hear, so files shrink a lot. The detail can never be recovered. Lower the quality and find the point where it looks bad.","controls":[{"id":"q","label":"Quality","min":5,"max":100,"step":5,"value":60,"unit":"%"}]},{"mode":"quiz","look":"units","eyebrow":"Check yourself","title":"Work out a file size","body":"An image is 100 pixels wide and 50 pixels high, with a colour depth of 8 bits.","question":"How big is it, uncompressed?","options":["5000 bytes","40 000 bytes","625 bytes"],"answer":0,"right":"Correct. 100 × 50 = 5000 pixels × 8 bits = 40 000 bits ÷ 8 = 5000 bytes.","wrong":"Not quite. Multiply pixels by bits per pixel, then divide by 8 to get bytes."}],"more":[{"type":"cards","id":"worked","eyebrow":"Worked examples","title":"Step by step","intro":"Write the formula first, then the numbers, then the units at each stage.","items":[{"tag":"Image","title":"1920 × 1080, 24-bit colour, in MiB","body":"pixels: 1920 × 1080 = 2 073 600\nbits: × 24 = 49 766 400\nbytes: ÷ 8 = 6 220 800\nKiB: ÷ 1024 = 6075\nMiB: ÷ 1024 ≈ 5.93 MiB","code":true},{"tag":"Sound","title":"3 minutes of stereo, 44 100 Hz, 16-bit","body":"size = rate × resolution × seconds × channels\n= 44 100 × 16 × 180 × 2\n= 254 016 000 bits\n÷ 8 = 31 752 000 bytes\n≈ 30.3 MiB","code":true},{"tag":"Units","title":"How many 6 MiB photos fit on 64 GiB?","body":"64 GiB = 64 × 1024 MiB = 65 536 MiB\n65 536 ÷ 6 = 10 922.6…\nabout 10 922 photos","code":true},{"tag":"RLE","title":"Compress 'BBBBBWWWWWWWWWBB'","body":"runs: 5 B, 9 W, 2 B\nencoded: 5B 9W 2B\n16 characters → 6 characters\ndecode by repeating: exact original back","code":true}]},{"type":"cards","id":"mistakes","eyebrow":"Common mistakes","title":"Watch out for these","items":[{"tag":"Mistake","title":"Forgetting to divide by 8","body":"Pixels × colour depth gives BITS. Divide by 8 for bytes before converting to KiB or MiB."},{"tag":"Mistake","title":"Using 1000 and 1024 in the same answer","body":"KiB/MiB/GiB use 1024. kB/MB/GB (as used by hard-drive makers) use 1000. Stick to one system."},{"tag":"Mistake","title":"\"Lossy is always bad\"","body":"Lossy files can look and sound almost the same as the original at a fraction of the size. That's why streaming works."},{"tag":"Mistake","title":"Using lossy compression on text or programs","body":"Losing even one character changes a document's meaning or breaks a program. Text and code need lossless compression."}]},{"type":"cards","id":"method","eyebrow":"Set out your answer","title":"Choosing a compression type","items":[{"tag":"Lossless","title":"When every bit matters","body":"Text documents, program files, spreadsheets, medical scans. The original must be restored exactly. Examples: ZIP, PNG, FLAC."},{"tag":"Lossy","title":"When smaller matters more","body":"Photos, music, video to stream or send. People can't notice the removed detail. Examples: JPEG, MP3, MP4."},{"tag":"Why compress?","title":"Give real reasons","body":"Less storage space, faster upload and download, less bandwidth used, and pages that load faster."}]},{"type":"calc","id":"calc","eyebrow":"Calculator","title":"Photo storage","intro":"A phone photo is about 3 MiB. How many photos fit on each size of storage?","input":{"label":"Storage","min":16,"max":512,"step":16,"value":128,"unit":"GiB"},"rows":[{"label":"Photos at 3 MiB (× 1024 ÷ 3)","mul":341.33,"decimals":0,"color":"#2f6fdb"},{"label":"Raw photos at 24 MiB (× 1024 ÷ 24)","mul":42.67,"decimals":0,"color":"#e0463e"}],"bars":true,"note":"Compression lets you keep about eight times more photos."},{"type":"cards","id":"deeper","eyebrow":"Go deeper","title":"More than the lesson","items":[{"tag":"How it works","title":"How JPEG decides what to throw away","body":"Our eyes notice changes in brightness more than changes in colour, and notice big smooth areas more than fine detail. JPEG stores brightness carefully but colour roughly, and smooths tiny details in 8 × 8 blocks. At low quality those blocks become visible."},{"tag":"How it works","title":"How MP3 shrinks music","body":"MP3 removes sounds people can't hear: very high frequencies, and quiet sounds hidden by louder ones at the same moment. A song shrinks to about one tenth of its CD size."},{"tag":"Real world","title":"Why streaming quality changes","body":"Video apps switch between versions compressed at different levels depending on your connection. Slow Wi-Fi means more compression and a blurrier picture, rather than stopping to buffer."},{"tag":"Coming next","title":"Where this leads","body":"Next term you'll see how files are split into packets and sent across networks, where smaller files mean faster transfers."}]},{"type":"cards","id":"challenge","eyebrow":"Challenge yourself","title":"Stretch your brain","intro":"Try each one before opening the card.","items":[{"tag":"Challenge","title":"A 1-minute video is 1280 × 720 pixels, 24-bit colour, 30 frames per second, uncompressed. How big?","body":"one frame: 1280 × 720 × 24 = 22 118 400 bits = 2 764 800 bytes ≈ 2.64 MiB\nframes: 30 × 60 = 1800\ntotal ≈ 2.64 × 1800 ≈ 4746 MiB ≈ 4.6 GiB\nThat's why video is ALWAYS compressed."},{"tag":"Challenge","title":"Decode this RLE image row: 3W 2B 1R 4W","body":"WWW BB R WWWW → WWWBBRWWWW (10 pixels)."}]},{"type":"activities","id":"try","eyebrow":"Try it at home","title":"Squash it","items":[{"title":"Zip test","time":"15 minutes","need":["A computer"],"steps":["Make a text file containing one sentence copied 200 times. Note its size.","Make another with 200 different random-looking lines (or copy part of a story).","Compress both into ZIP files.","Which one shrank more? Why?"],"why":"Lossless compression looks for repeated patterns. Highly repetitive text compresses enormously; varied text much less.","safety":"Ask before installing anything; most computers can zip files built in."},{"title":"Quality detective","time":"15 minutes","need":["A computer with a free image editor","One photo"],"steps":["Save the same photo as JPEG at high, medium and very low quality.","Note each file size.","Zoom in on edges and sky. Where do you first see damage?","Choose the lowest quality you'd happily share."],"why":"Lower JPEG quality throws away more detail. The damage shows first as blocks in smooth areas and halos round sharp edges.","safety":"No safety risks."}]},{"type":"quiz","id":"quiz","eyebrow":"Quiz","title":"Eight more questions","questions":[{"question":"How many bytes are in 1 KiB?","options":["1024","1000","8"],"answer":0,"right":"Correct. 1 KiB = 2¹⁰ = 1024 bytes.","wrong":"Not quite. Binary units go up in powers of 2."},{"question":"Which is the biggest?","options":["900 MiB","2 GiB","1 000 000 KiB"],"answer":1,"right":"Correct. 2 GiB = 2048 MiB; 1 000 000 KiB ≈ 977 MiB.","wrong":"Not quite. Convert them all to MiB."},{"question":"A 200 × 100 image uses 16-bit colour. How many bytes?","options":["20 000","320 000","40 000"],"answer":2,"right":"Correct. 20 000 pixels × 16 bits = 320 000 bits ÷ 8 = 40 000 bytes.","wrong":"Not quite. Remember to divide the bits by 8."},{"question":"Which file should NOT use lossy compression?","options":["A program","A holiday photo","A song for streaming"],"answer":0,"right":"Correct. Losing data would break the program.","wrong":"Not quite. Which file must be restored exactly?"},{"question":"What does RLE turn 'AAAABB' into?","options":["A4B2","4A2B","AB42"],"answer":1,"right":"Correct. A count, then the value, for each run.","wrong":"Not quite. Count each run: four A's, then two B's."},{"question":"Which describes lossless compression?","options":["Removes details people won't notice","Always halves the file","The original can be restored exactly"],"answer":2,"right":"Correct. Nothing is lost for good.","wrong":"Not quite. Lossless means nothing is lost."},{"question":"Why does RLE make 'ABCDEF' bigger?","options":["There are no repeated runs","It is lossy","Letters can't be compressed"],"answer":0,"right":"Correct. Each single letter becomes '1A', doubling the size.","wrong":"Not quite. What does RLE need in the data to save space?"},{"question":"Doubling both the width and height of an image makes its file…","options":["2 times bigger","4 times bigger","the same size"],"answer":1,"right":"Correct. 2 × 2 = 4 times as many pixels.","wrong":"Not quite. Count the pixels in a 2 × 2 grid and a 4 × 4 grid."}]},{"type":"checklist","id":"check","eyebrow":"Self-check","title":"I can…","items":["list storage units from bit to TiB","convert between units using 8 and 1024","calculate the size of an uncompressed image","calculate the size of an uncompressed sound file","explain why files are compressed","explain lossless compression and run-length encoding","explain lossy compression and where it is used","choose lossy or lossless for a given file and justify it"]},{"type":"keywords","id":"words","eyebrow":"Key words","title":"Words to know","items":[{"word":"kibibyte (KiB)","meaning":"1024 bytes."},{"word":"mebibyte (MiB)","meaning":"1024 KiB."},{"word":"gibibyte (GiB)","meaning":"1024 MiB."},{"word":"tebibyte (TiB)","meaning":"1024 GiB."},{"word":"file size","meaning":"How much storage a file needs."},{"word":"compression","meaning":"Making a file smaller."},{"word":"lossless compression","meaning":"Compression where the original can be rebuilt exactly."},{"word":"lossy compression","meaning":"Compression that permanently removes some data."},{"word":"run-length encoding (RLE)","meaning":"Replacing runs of repeated values with a count and the value."},{"word":"bandwidth","meaning":"How much data a connection can carry each second."}]},{"type":"sources","id":"sources","title":"Sources","items":["BBC Bitesize, GCSE Computer Science: Compression","International Electrotechnical Commission (IEC): binary prefixes kibi, mebi, gibi","Joint Photographic Experts Group: JPEG overview","Isaac Computer Science: Data compression"]}]},"overlay":null}