A little room to wonder

File Formats & Compression

Separate a file’s agreed representation from its compression method, and test whether a compact description can reconstruct the original.

Can a compression method make some data larger instead of smaller?

Blue curling waves tower over three boats, with Mount Fuji small in the distance.
The approved raster reproduction of an artwork gives an image-file context. Its actual JPEG encoding is not the article’s tiny monochrome run-length code.Katsushika Hokusai · Source · Public domain

A format tells a reader how to interpret bytes

A file format is an agreed structure for information, including how to interpret its contents and relevant metadata. Renaming a file’s extension does not rewrite its bytes into a different format. A decoder needs the actual structure, not just an appealing filename.

Compression is a way of representing information more compactly under particular rules. Lossless compression allows exact reconstruction of the encoded original data. Lossy compression deliberately discards some information; looking similar is a different promise from being identical.

A run is a consecutive repetition

Run-length encoding replaces a repeated sequence with a count and a symbol under a defined code. It can work well on long runs but needs extra information to describe those runs. That overhead matters when repetition is short or absent.

For this original paper code, every run uses a 3-bit count from 1 to 7 and a 1-bit colour value: 4 bits per run. The count 000 is unused. This is a teaching format, not the exact encoding used by PNG, JPEG or the reference page’s example.

Worked example: compare two 24-symbol records

Take 24 monochrome pixels arranged as six white, six black, six white and six black. An uncompressed one-bit-per-pixel payload uses 24 bits. Four runs in the stated code use 4 × 4 = 16 bits, saving 8 bits before headers or other overhead. Decoding the four count/colour pairs reconstructs all 24 pixels.

Now alternate white and black at every position. The same 24 pixels require 24 runs, so the code uses 24 × 4 = 96 bits, larger than the uncompressed payload. A run longer than 7 would also need splitting in this particular count scheme. The result depends on both the data and the chosen representation.

Preservation is a practical criterion

A saved diagram with small text may need exact edge and colour preservation more than a quick photographic preview does. Some formats support more than one compression mode, so a format name alone does not always settle what was discarded.

Compare the actual task, reconstruction requirement and complete file size. A short toy calculation leaves out headers and many real compression techniques, but it still reveals a central idea: there is no rule that every compressor must make every possible input smaller.

Only if you feel like trying

Encode and decode two paper sequences

  1. Write the two 24-pixel sequences and list their count/colour pairs under the stated 4-bit run rule.
  2. Check that decoding gives the original sequence exactly.
  3. Compare 16, 24 and 96 bits and explain why a scheme suited to long runs performs poorly on alternating symbols.

Optional. Use paper or talk through the supplied fictional example. No purchase, personal information, account, public sharing or practical experiment is needed.