🎨 Pixel Compression Lab

Can describing repeated pixels take less space than listing every pixel? Draw, encode, decode and test your prediction.

Predict first: which will compress better: a solid square, broad horizontal bands or a checkerboard? These are tiny learning pictures, not real phone-file size estimates.

1. Draw your picture

Navy = 1; white = 0. Tap a pixel, or Tab to it and press Space or Enter.

Compression mission

There is more than one solution. Try making your own instead of using a preset.

2. Compare the payload

Raw pixels64 bits
Runs—
Toy encoded payload—
Difference from raw—

Read the runs

A run is an unbroken stretch of the same bit. Scan each row left to right, then continue with the next row. Runs can cross row boundaries.

Inspect the actual encoded bits

Spaces separate records for reading; they are not stored bits.

3. Why seven bits per run?

This lab invents a simple run-length encoding format. Each record contains one bit for the pixel value and six bits for the run length minus one. Six bits can store 0 through 63, so adding one gives lengths 1 through 64.

For example, 1 | 000000 means one navy pixel; 0 | 111111 means 64 white pixels. Every run costs 7 bits, so encoded payload = number of runs × 7. The decoder repeats each value the specified number of times and checks that there are exactly 64 pixels.

Lossless here means decoding restores every pixel exactly. It does not mean the result must be smaller! Frequent colour changes create many short runs and a lot of records.

Fair comparison: both sizes count pixel payload only. Both sides already know the image is 8 × 8, the scan order and the encoding format. File headers, a format label, byte padding and other metadata are excluded. Our toy format is not PNG, JPEG or a claim about how your phone saves pictures.

Try Invert: the colours change, but do the run boundaries and encoded size change? Explain why. Then compare horizontal bands with vertical stripes you draw yourself.

4. Check your reasoning

All 64 pixels are navy. In this lab's format, how many bits does the encoded pixel payload need?

Keep exploring

Explore binary bytes and hexadecimal postcards · Plan phone storage · Investigate download times

No account, saved scores or input uploads. Your drawing stays in this page; reloading resets it. This lab does not use cookies or browser storage.