Quite often, when I see a pedalboard of guitarists I admire, there is a compressor pedal in the chain. How exactly does this pedal affect the sound?
A compressor "compresses" the signal that your guitar produces by normalizing the dynamic range of the audio input signal based on a threshold value. This effect is used virtually everywhere in recording. Everything you hear in music that is produced today is compressed in some way--and it can sound anything from a subtle barely noticeable effect to a thick, dampened squish.
The benefit of a compressor lies in that every note played will be at nearly the same amplitude, and therefore nearly equal in volume. This will help normalize tones that are sometimes lost in the mix because of complex overtones, and it will result in a more articulate sound. Notice that if you don't pick all notes of an arpeggio at exactly the same pressure you will likely get a different sound for each note, especially if you are playing a tube amp. Tube amplifiers react dynamically to stronger and weaker signals--it's the allure of them--and thus the non-uniformity of picking at different strengths will be exaggerated. A compressor will fix this problem and normalize all notes of the arpeggio regardless of the player's technique and equipment, which is consequently why many soloists prefer them. Compressors also have the ability to increase the sustain of notes beyond sounds that are normally usable on the instrument; yet another reason the effect is a popular tool in the soloist's arsenal. The tiniest signal can be normalized to the same amplitude of a fierce pick attack, and a trailing note will resonate at the exact same volume until the string stops inducing a signal on the pickup.
Drawbacks of a compressor mirror their benefits. More expressive musical genres such as blues rely on the dynamics of the player. Picking technique and signal volume become part of the performance itself. In this case, a compressor will nullify exactly what you are trying to preserve. However, I have seen some blues guitarists use compressors so this is obviously not true universally.
Compressors also dampen the attack of plucking a string. This will make the note sound a bit squishy and with less snap. This is related to how fast the compressor reacts and normalizes the amplitude of the input signal. Slower reaction times result in a more natural uncompressed tone, while faster reaction times result in the trademark squishy sound. Some people consider the "squishyness" of a faster attack time a plus, while others don't like it. Nearly all compressors allow you to adjust this parameter, but it can never be completely transparent. You can get quite close with parallel compressor designs that blend the original signal into the affected signal, but the nature of the effect will still color the sound; that's what it's supposed to do.
I feel a bit silly writing a new answer when Jduv's is so good, and so well received, but I'm going to anyway partly because I want to use simpler terms, and partly because I have a point to make about attack.
Imagine you had a signal that was sometimes too loud, and sometimes too quiet. You'd deal with it by turning the volume down when it's too loud, and bringing the volume back up when it's quiet. A compressor does exactly this, except it adjusts the volume automatically, usually very quickly.
At its simplest then, it takes a signal that has a variable volume level, and fixes it up so that the volume is more constant.
Whether this is desirable musically depends on the player and the style of music; it is an artistic choice.
Compressors have a number of adjustable parameters. The following ones address the basics:
Compressors are incredibly versatile, having loads of different uses.
Maybe a little counter-intuitively, a compressor can be used to increase the attack; to make something sound more dynamic and staccato:
Imagine the waveform of a clean guitar note:
If we apply compression, and we set, say, 10ms of attack time, it does this:
So it accentuates the attack of plucking the string. Alternatively, with a really short attack parameter, you could dampen the pluck.
Affordable compression units have side effects on the timbre of the sound. Really high end studio equipment minimises this -- but it doesn't matter to the guitarist, because the side effects are rarely unmusical; indeed they are often pleasant. Some units are desirable precisely because of their side-effects.
My explanation is more for generic compressors, but I believe it is relevant for guitars as well.
A compressor is most often used to amplify quiet sounds more than loud sounds. You could think of it as someone turning up the volume on quiet parts, and down on loud parts. This is done by a compressor much faster than a human with a volume knob could :)
As a result, the output has a thinner volume range than the input of the compressor.
Here is an example of a compressor setting:
If there is no compression at all, the output is equal to the input. If you have -20 dB in, you'll have the same -20 dB out. It is represented by the black line in the graph.
With compression as in the example above (green curve):
In other words, the amplification gain varies with the loudness of the input.
Further, this gain is often restricted from changing too fast. This is what attack and release times are for. The attack time prevents the gain from going up to fast, while the release time prevents it from going down too fast.
Compression is really about reducing dynamic range and ends up consisting of either one, or both of
Limiting, is a specialized form of compression which has an "infinite" amount of reduction at a particular volume threshold. Basically, the signal will never go above this point.
Typically, compressors have
The amount of time between a signal being over the threshold before compression is applied. this is useful for keeping the "attack" of the initial transient before the application of compression
The amount of time to actually apply compression to the signal
The input level that when exceeded, triggers the "attack" of the compressor
The amount of signal reduction applied, usually a ratio, with the larger relating to "more". Lower amounts of compression are typically used to "glue" sounds together, large amounts can be used for various effects.
Compressors also may have
Typically called "makeup gain". This is the amount of gain applied to the signal before compression (typically before. Sometimes after, depends on the compressor. Always read the manual!)
The "knee" of a compressor relates to how quickly the full compression amount is applied to the signal. for guitar pedals, you wont usually get to change this, but for plugins you'll be able to control how much compression is applied to signals above the threshold using this.
So, using a combination of all of the above, we can shape the resulting signal. Typically for guitars (and bass), what you want to do is retain the pick "attack" but make the resulting "notes" more similar in volume. This will mean reducing very loud notes, and amplifying very quiet notes. This has the advantage of typically introducing more sustain as well as the tail off of the note will be amplified using the compressor pedal.
Guitar pedal compressors typically don't provide all of the above options, opting for simplicity. its quite common that you'll only get 2-3 parameters to play with. But understanding what the pedal is actually doing will help you shape the sound in a pleasing way. usually the manufacturer will tell you the release/attack/etc timings/values that are set inside the pedal so you can work with them.
The typical usage is where note volume consistency is important. such as when you're chugging away on the low E (or B), and quite often when you're doing fast solos. when you want to be more expressive with your picking velocity, you can turn it off ;)
Its usually recommended that you put a noise gate before your compressor (and some people put one after too) as this will help stop unwanted noise being amplified as "quiet notes" by your compressor pedal.