How MIDI Works?

Share
If you have ever seen a a file with the .mid file extension, you may have been surprised: the tiny file only 30 kilobytes in size can store an entire 4 minute long song! How is this possible? How does it achieve a compression rate much higher than MP3's?

The MIDI format achieves its efficiency not by compression like other audio formats, but by storing only the data of what musical notes of which musical instruments are played. This means that a MIDI file doesn't actually contain any data that can be decompressed into a sound wave. Instead, the operating system or music player must have the actual audio data of the instruments stored somewhere else.

For example, let's you have several MIDI files containing piano music. These files just contain which notes of the piano are played. The sounds of these notes are installed somewhere else. When the music player plays a piano MIDI file, the audio played is the piano audio that is shared by ALL piano MIDI's. This means that two MIDI's that have the same notes being played will produce the exact same sound, as they are all using the same digital piano to play those notes.

For the record, the way the music notes are stored in a MIDI file isn't simply "do re mi fa sol la si." We have 12 notes, C, C#, D, D#, E, F, F#, G, G#, A, A#, B, and several octaves that are stored in 7 bits (128 permutations), so less than one byte per note. The full mapping of values being:

Octave #Note Numbers
 CC#DD#EFF#GG#AA#B
-101234567891011
0121314151617181920212223
1242526272829303132333435
2363738394041424344454647
3484950515253545556575859
4606162636465666768697071
5727374757677787980818283
6848586878889909192939495
796979899100101102103104105106107
8108109110111112113114115116117118119
9120121122123124125126127    
Ordinal values of MIDI notes. Table source: https://www.music.mcgill.ca/~ich/classes/mumt306/StandardMIDIfileformat.html (accessed 2025-04-09)

MIDI doesn't feature only piano. There are actually dozens of different instruments, including flutes, guitars, violins, and even drums. 128 instruments in total, to be exact. Another 7 bits.

Presumably, the reason why MIDI isn't well-supported anymore is simply because the software can't guarantee that the audio for the notes exists somewhere on the computer. In order to play MIDI, a synthesizer to generate the audio for the notes is necessary, and this can be a hardware-based synthesizer (your sound card, which nowadays is integrated with the motherboard), or a software-based synthesizer. If your sound card doesn't have MIDI support, your operating system doesn't provide a common synthesizer, and the music player doesn't have its own synthesizer, then there would be no synthesizer for synthesizing the audio. This seems unlikely, however, as even on Windows 11 MIDI can still be played through Windows Media Player Classic.

A format similar to MIDI exists that is called chiptune. More specifically, chiptunes is an umbrella term for music files for retro hardware synthesizers from the first generations gaming consoles such as Nintendo, Super Nintendo, Sega Genesis, Dreamcast, etc. These hardware have different music formats but they're all called "chiptunes" collectively and they can be played back with software synthesizers today that emulate the hardware ones of the past.

Written by Noel Santos.

About the Author

I'm a self-taught Brazilian programmer graduated in IT from a FATEC. In a world of increasingly complex and essential computers, I decided to use my technical expertise in hardware, desktop applications, and web technologies to create an informative resource to make PC's easier to understand.

View Comments