Class D amplifiers function by taking the analog input signal and they replicate a pulse with modulation, it basically looks like a row of pulses, which then correlate with frequency and amplitude of the aforementioned input signal. In its original state you use a comparator circuit so you could match the input signal with the pwm signal. After that the pwm signal gets powered up by an output stage which is in switch mode, which pretty much means that you can find it in two different states, either on or off, and it is always at an extremely high speed, matching those PWM pulses.
Now when compared to a linear amplifier, which always has a constant waveform, but in order to not get distorted its output stages are on more than half the waveform or all of it, which in the end heats the amplifier up and reduces efficiency.
Now when it comes to how a class D amplifier is constructed you could say it’s similar to a continuously changing buck converter, which is a kind of switched-mode power supply that isn’t isolated, although it can also work backwards. While buck converters work as voltage regulators that give you a stable DC voltage into a variable load and is only able to source current, a class D amplifier on the other hand gives you an always changing voltage into a stable load, another specific feature of it is that voltage and current can separately change sign. It is important to note that there is big difference between a switching amplifier and a linear amplifier that use the aforementioned power supply for their DC power.
When it comes to a switching amplifier the defining feature is that it can pretty much use any power supply but when you dig a bit deeper and look into the amplification process you find out that it is operated by switching. In contrast to a switched-mode power supply, the amplifier itself has a much more important role in all this, it has to keep unwanted artifacts at bay. Another thing you get with all class D amplifiers is that they all use feedback, they are used for noise reduction and to decrease distortion, just like standard analog amplifiers.
Now we’ve mentioned heat and reduction of efficiency, in theory D class amplifiers can be 100% power efficient, which means that all the power gets where it needs to be, there’s no excess power that gets converted into heat. Now in a perfect world when a switch is “on” all the current that passes through should not have voltage at all, thus you wouldn’t get any heat. But when it’s in the “off” switch you would get all the voltage you would want but there would be no leakage of it, and of course, no increase in heat.