I have been wondering why so many amps comes with a gain button/switch?
It seems to boost the mids, but can someone please explain what's the purpose, reasoning and history behind the gain feature on amps?
The gain pot does itself (more or less) exactly the same thing as a volume pot, with one important difference: it's located at the very front-end of the circuitry. So it does not only control the output level, but more so the level the signal will have in the circuit. This may not seem necessary as most amplifier circuits are (more or less) designed to work linearly, that is, it should not matter whether the signal is weak inside the circuit and just boosted at the end of it or strong all the way through – but that's not quite true in reality.
One problem with the former: every active piece of electronics introduces some amount of noise. If we greatly boost the signal at the end of the circuit, we will also greatly boost this noise.
An even more drastic effect to the sound occurs when the level is too high to be accurately processed by the circuitry, that is, when the signal voltage exceeds the operating voltage. In this case, various types of clipping will come up. This is in most applications generally not desired as it heavily affects the sound characteristics, but sometimes it's an integral part of the desired sound: it's what makes up a screaming distorted electric guitar as well as a warm and gentle tube-overdrive on a vocal track. To control the amount of clipping and thereby the sound, we need the gain pot.