Inharmonicity

In music, inharmonicity is the degree to which the frequencies of overtones (also known as partials or partial tones) depart from whole multiples of the fundamental frequency (harmonic series).
Acoustically, a note perceived to have a single distinct pitch in fact contains a variety of additional overtones. Many percussion instruments, such as cymbals, tam-tams, and chimes, create complex and inharmonic sounds.
Music harmony and intonation depends strongly on the harmonicity of tones. An ideal, homogeneous, infinitesimally thin or infinitely flexible string or column of air has exactly harmonic modes of vibration. In any real musical instrument, the resonant body that produces the music tone—typically a string, wire, or column of air—deviates from this ideal and has some small or large amount of inharmonicity. For instance, a very thick string behaves less as an ideal string and more like a cylinder (a tube of mass), which has natural resonances that are not whole number multiples of the fundamental frequency.
However, in stringed instruments such as the piano, violin, and guitar, or in some Indian drums such as tabla, the overtones are close to—or in some cases, quite exactly—whole number multiples of the fundamental frequency. Any departure from this ideal harmonic series is known as inharmonicity. The less elastic the strings are (that is, the shorter, thicker, smaller tension or stiffer they are), the more inharmonicity they exhibit.
When a string is bowed or tone in a wind instrument initiated by vibrating reed or lips, a phenomenon called mode-locking counteracts the natural inharmonicity of the string or air column and causes the overtones to lock precisely onto integer multiples of the fundamental pitch, even though these are slightly different from the natural resonance points of the instrument. For this reason, a single tone played by a bowed string instrument, brass instrument, or reed instrument does not necessarily exhibit inharmonicity.
However, when a string is struck or plucked, as with a piano string that is struck by a hammer, a violin string played pizzicato, or a guitar string that is plucked by a finger or plectrum, the string will exhibit inharmonicity. The inharmonicity of a string depends on its physical characteristics, such as tension, stiffness, and length. For instance, a stiff string under low tension (such as those found in the bass notes of small upright pianos) exhibits a high degree of inharmonicity, while a thinner string under higher tension (such as a treble string in a piano) or a more flexible string (such as a gut or nylon string used on a guitar or harp) will exhibit less inharmonicity. A wound string generally exhibits less inharmonicity than the equivalent solid string, and for that reason wound strings are often preferred.
Pianos.
Sound quality of inharmonicity.
In 1943, Schuck and Young were the first scientists to measure the spectral inharmonicity in piano tones. They found that the spectral partials in piano tones are progressively stretched—that is to say, the lowest partials are stretched the least and higher partials are progressively stretched further.
Inharmonicity is not necessarily unpleasant. In 1962, research by Harvey Fletcher and his collaborators indicated that the spectral inharmonicity is important for tones to sound piano-like. They proposed that inharmonicity is responsible for the "warmth" property common to real piano tones. According to their research synthesized piano tones sounded more natural when some inharmonicity was introduced. In general, electronic instruments that duplicate acoustic instruments must duplicate both the inharmonicity and the resulting stretched tuning of the original instruments.
Inharmonicity leads to stretched tuning.
When pianos are tuned by piano tuners, the technician sometimes listens for the sound of "beating" when two notes are played together, and tunes to the point that minimizes roughness between tones. Piano tuners must deal with the inharmonicity of piano strings, which is present in different amounts in all of the ranges of the instrument, but especially in the bass and high treble registers. The result is that octaves are tuned slightly wider than the harmonic 2:1 ratio. The exact amount octaves are stretched in a piano tuning varies from piano to piano and even from register to register within a single piano—depending on the exact inharmonicity of the strings involved.
Because of the problem of inharmonicity, electronic piano tuning devices used by piano technicians are not designed to tune according to a simple harmonic series. Rather, the devices use various means to duplicate the stretched octaves and other adjustments a technician makes by ear. The most sophisticated devices allow a technician to make custom inharmonicity measurements—simultaneously considering all partials for pitch and volume to determine the most appropriate stretch to employ for a given instrument. Some include an option to simply record a tuning that a technician has completed by ear; the technician can then duplicate that tuning on the same piano (or others of similar make and model) more easily and quickly.
The issues surrounding setting the stretch by ear vs machine have not been settled; machines are better at deriving the absolute placement of semitones within a given chromatic scale, whereas non-machine tuners prefer to adjust these locations preferentially due to their temptation to make intervals more sonorous. The result is that pianos tuned by ear and immediately checked with a machine tend to vary from one degree to another from the purely theoretical semitone (mathematically the 12th root of two) due to human error and perception. (If pleasing the ear is the goal of an aural tuning, then pleasing the math is the goal of a machine tuning.) This is thought to be because strings can vary somewhat from note to note and even from neighbors within a unison. This non-linearity is different from true falseness where a string creates false harmonics and is more akin to minor variations in string thickness, string sounding length or minor bridge inconsistencies.
Piano tuning is a compromise—both in terms of choosing a temperament to minimize out-of-tuneness in the intervals and chords that will be played, and in terms of dealing with inharmonicity. For more information, "see Piano acoustics" and "Piano tuning".
Another factor that can cause problems is the presence of rust on the strings or dirt in the windings. These factors can slightly raise the frequency of the higher modes, resulting in more inharmonicity.
Guitar.
While piano tuning is normally done by trained technicians, guitars such as acoustic guitars, electric guitars, and electric bass guitars are usually tuned by the guitarist themselves. When a guitarist tunes a guitar by ear, they have to take both temperament and string inharmonicity into account. The inharmonicity in guitar strings can "cause stopped notes to stop sharp, meaning they will sound sharper both in terms of pitch and beating, than they "should". This is distinct from any temperament issue." Even if a guitar is built so that there are no "fret or neck angle errors, inharmonicity can make the simple approach of tuning open strings to notes stopped on the fifth or fourth frets" unreliable. Inharmonicity also demands that 
some of the "octaves may need to be compromised minutely." 
When strobe tuners became available in the 1970s, and then inexpensive electronic tuners in the 1980s reached the mass market, it did not spell the end of tuning problems for guitarists. Even if an electronic tuner indicates that the guitar is "perfectly" in tune, some chords may not sound in tune when they are strummed, either due to string inharmonicity from worn or dirty strings, a misplaced fret, a mis-adjusted bridge, or other problems. Due to the range of factors in play, getting a guitar to sound in tune is an exercise in compromise. "Worn or dirty strings are also inharmonic and harder to tune", a problem that can be partially resolved by cleaning strings.
Some performers choose to focus the tuning towards the key of the piece, so that the tonic and dominant chords will have a clear, resonant sound. However, since this compromise may lead to muddy-sounding chords in sections of a piece that stray from the main key (e.g., a bridge section that modulates a semitone down), some performers choose to make a broader compromise, and "split the difference" so that all chords will sound acceptable.
Mode-locking.
Other stringed instruments such as the violin, viola, cello, and double bass also exhibit inharmonicity when notes are plucked using the pizzicato technique. However, this inharmonicity disappears when the strings are bowed, because the bow's stick-slip action is periodic, driving all of the resonances of the string at exactly harmonic ratios even if it has to drive them slightly off their natural frequency. As a result, the operating mode of a bowed string playing a steady note is a compromise among the tunings of all of the (slightly inharmonic) string resonances, which is due to the strong non-linearity of the stick-slip action. Mode locking also occurs in the human voice and in reed instruments such as the clarinet.