The Mathematics of the 88 Keys
A standard modern piano has 88 keys, spanning seven octaves plus a minor third. The tuning of these keys is based on the Equal Temperament system, where the octave is divided into twelve equal logarithmic steps (semitones). This allows a piano to play in any key while remaining 'acceptably' in tune, a breakthrough that enabled the complex harmonies of the last 300 years of Western music.
The A440 Standard
The benchmark for all piano tuning is A4 (the 49th key on the keyboard), which is tuned to exactly 440 Hz. Every other note is calculated relative to this frequency.
The Formula
The frequency of any key 'n' is calculated using an exponential function where each step represents a factor of the 12th root of 2.
Inharmonicity and 'Stretch Tuning'
In the real world, piano strings are not 'ideal' mathematical lines; they have physical stiffness. This causes the higher harmonics (overtones) to be slightly sharper than they 'should' be. To make the piano sound harmonious to our ears, tuners perform Stretch Tuning, where the high notes are tuned slightly sharp and the low notes slightly flat to match these imperfect overtones.