The smallest program ever


Brian Raiter wrote an article many years ago in which he documented his quest to make the smallest possible Linux ELF executable, a stripped-down program that returns the answer to life, the universe, and everything.

While the standard gcc-compiled version of the application nets out at 3998 bytes, Brian discovered that the smallest possible size for an ELF executable that will still run correctly is 45 bytes:

This forty-five-byte file is less than one-eighth the size of the smallest ELF executable we could create using the standard tools, and is less than one-fiftieth the size of the smallest file we could create using pure C code. We have stripped everything out of the file that we could, and put to dual purpose most of what we couldn’t.

Of course, half of the values in this file violate some part of the ELF standard, and it’s a wonder than Linux will even consent to sneeze on it, much less give it a process ID. This is not the sort of program to which one would normally be willing to confess authorship.

It’s not an easy process creating the smallest possible program. To get there, you need to dissect the inner workings of the operating system and the ELF file format, which is really what the article is about. If you’ve ever wondered about the mysterious events that happen before main() and after return(), here’s your chance to take the red pill.

A Whirlwind Tutorial on Creating Really Teensy ELF Executables for Linux

4 thoughts on “The smallest program ever

  1. Nox says:

    That was a really interesting article, took me back to my university days… would love to see some metrics for the running times of the first and last iterations of the code.

    I dread to see what the file size and running time of the equivalent Java class file would be!!

  2. PDXNET96 says:

    Its only 3 bytes bigger than the answer…

Comments are closed.

Discuss this article with the rest of the community on our Discord server!
Maker Faire Bay Area 2023 - Mare Island, CA

Escape to an island of imagination + innovation as Maker Faire Bay Area returns for its 15th iteration!

Buy Tickets today! SAVE 15% and lock-in your preferred date(s).