Compressors reduce dynamic range - the difference in amplitude of the softest note to the loudest note.
Most do this by automatically turning down the volume of the louder notes at a set threshold and ratio, but there are also compressor/expanders that will also increase the volume of quiter passages at a set threshold and ratio. Different units have different compression technologies, and most have adjustable thresholds, ratios, attack and release times.
How a compressor is set up depends on the application and the program material. Inexpensive compressors (based on LED detectors) have a tendency to compress unevenly accross the frequency range, sometimes leaving the higher frequencies uncompressed while clamping down hard on the lower, more dominant frequencies. The resulting sound is not pleaseing to the ear and is what I would consider to be downright nasty. An EQ in the side chain (control signal path, not audio path) is required to smooth out the response of some compressors.
The best compressors (IMO) are tube compressors. If you have a tube amp and you play with two channels you can easily see the difference between a compressed and uncompressed signal by checking out the difference in dynamic range between a high gain sound and a clean sound. There is little difference in the volume between a lightly picked note and a more dymanic strum with too much gain. High gain tube amp users will often get complaints from soundmen that heir clean sound is way louder than their dirty sound, as the clean sound is not compressed.
Compressors are meant to be used sparringly, that is they are meant to react to the part of the signal that needs to be attenuated, not the entire program material. They should be transparent and lay in waiting until they are needed. They allow you more 'net' volume or more usable headroom through whatever you are using it on (if used correctly) at the expense of reduced dynamic range. I use them extensively in live sound to keep signals and the entire program material within the confines of the PA systems capabilities.
With all of that being said, I have seen compressors used in a more artistic way to create sound envelopes (attack is uncompressed but a hudge gain reduction following the attack giving a staccado effect or the opposite - no attack and ramping volume).
In my opinion, compressors are probably one of the hardest audio devices to get a handle on - I've seen some instances where the user cannot see any difference at all between a heavily compressed and lightly compressed signal (use the high gain two channel tube amp as a perfect example).