OK. To start with, an analogy. You know that bit in Star Wars episode 1 where Luke, Leia, Han, and Chewy are in the garbage chute and the walls start to close in on them? Same thing, roughly speaking.
Compression is a way to reduce the dynamic range of a wave. If, for instance, you are having some difficulty getting a vocal to sit in the mix properly because there are parts that are a bit too quiet and other parts that are a bit too loud, you would use compression to reduce the difference between the quietest and loudest parts of the signal. In the olden days of 16 bit recording when it was important to get a hot signal, compression was a useful tool to ensure that you could do so without clipping. This was also true in the stone age when we used magnetic tape (look that up, you will be astounded), and in fact the magnetic tape itself was used as a form of compression (some really archaic studios even use this these days). Anyhoo, I digress. The idea of compression is largely that it pushes the transient peaks down towards the RMS (average, although this is a bit misleading. RMS is a way of calculating the mean of a waveform over time, loosely speaking), thereby reducing the difference between peak level and RNS level. A compressor generally includes a make-up gain control so that you can push the peak level back up, bringing the average level (loudness) back up with it.
This is all very well, but far too often it's apparent that peeps don't understand or hear the effects of compression, and drive it too hard, resulting in overcompression, characterised by pumping in the audio.
HERE is a truly great example of overcompression. Note the constant pumping in the sound. Not good.
I suspect that what you're really asking is how you should apply it in real terms. This is a question that only you can answer, as it is in many ways an artistic decision. The only time it falls outside the artistic is in cases like the above, in which the producer obviously has no clue about its effects. That anyone could ever think that sounds acceptable is totally beyond me.
Now then! In some forms of music, that pumping can be acceptable in artistic terms, particularly in dance music, where the pumping can actually aid the piece in its energy. I, for one, have never found it pleasant, though, even in that context.
The key to any kind of dynamics processing, AFAIC, is to be subtle. There are members here who would, no doubt, disagree with me. What do I know, after all. I'm just a cheesy rocker. However, in my professional life, I deal with all kinds of music, mostly jazz, reggae and blues, where such things are apparent and unacceptable.
Compression can be used to great effect in taming dynamic range for any part that is proving to be recalcitrant during mixing, but you should be careful to exercise caution and not overdo it.
Some techie stuff.
1) Threshold: This is important, as it defines at what level compression should be applied. Any signal above the threshold will be squashed according to the ratio defined. Setting this too low will lead to pumping
2) Ratio: This defines how hard the compressor should work. This is a bit more difficult to explain in my drunken state, but it works like any other ratio. If your compression ratio is, for example, 2:1, any signal that is 2db over the given threshold will be reduced to 1db over the threshold, giving a gain reduction of 1db.
3) Knee: This is the rate at which the compressor works as it reaches and crosses the threshold. A soft knee will bring the compression in gradually, while a hard knee will bring it in more aggressively as you move up the amplitude range.
4) Attack: This determines how quickly the compressor activates. This is quite important, as this is the factor that most affects transients. Setting a fast attack means that the attack peaks of your audio events will be more affected. Transients are the peaks that make your music breathe, so you need to pay careful attention here. With a very fast attack, the attack phase of your events will be pushed down toward the average level, or RMS, meaning that, although the dynamics will be tamed, the events will be less lively, resulting in dulling of events and loss of transients. Did I already mention that those are the important bits? I think I did...
5) Release: this is fairly self-explanatory. This determines the time between the compressor meeting the last audio event that breaches the threshold and the compressor shutting off.
6) Make up gain: This calculation should be based on your threshold and ratio settings and, more importantly, your ears. For example, if you set your threshold at -10db with a ratio of 2:1 and your level before compression is - 6db, resulting in a 4db gain reduction, you should add 4db of make up gain to bring the peak level of the signal back up to the level it was before you applied compression.
7) train and then trust your ears. They are the most valuable piece of kit in your studio, and can't be vetoed by any piece of kit, or meter.
This is a guide only, and subject to dispute by such audio gods as are to be found in these parts. I would be happy to receive any corrections/clarification as these peeps can give me, but this should about cover it.
****! My post took so long to formulate and type, I was beaten to it! Ah, well. Them's the breaks!