A compression test is a good way to get a baseline of the mechanical health of your engine. What you're checking is the ability of the engine to bring in air, compress it, and expel the spent gas. To perform a compression test, you'll need a compression tester.
You can purchase this tool rather inexpensively, or you might be able to borrow one from your local auto parts store. To perform the test, first remove all the spark plugs from your engine. Then find a way to disable the fuel system. You can pull the fuel pump fuse or unplug the main relay. In the video below I show putting the gas pedal to the floor when cranking the engine. This should put the fuel system into clear flood mode, which means it turns off the injectors while you crank. This might not always be the case, so to be safe you might also pull the fuel pump fuse as suggested. You might even go so far as to unplug the fuel pump if you have access to its connector.
Next, install the compression tester into one of the cylinders. It really doesn't matter which one, but it's a good idea to keep track of everything so you can identify the location of your problem cylinder. You might want to pick cylinder number one as your first cylinder when doing your testing to make keeping track easier.
Now that the tester is installed and you've disabled the fuel system, hold the throttle plate open. I often just hold my foot to the gas when I crank the engine to do this. Crank the engine over. I usually listen for about five revolutions and quit. You really don't need to crank more than that. Then take your reading. What you should see will vary by engine, make, and model, but you hope to see readings that are within 20% of one another. Ten to 15% would be even better. The key here is to look for balance. Remember an engine needs to be balanced to run smoothly; if it’s not balanced, it will run rough and shake. So if you see a cylinder that's down significantly compared to the one next to it, look to that cylinder for the problem.
If you see two cylinders next to each other with low compression, this could indicate a head gasket failure. Keep in mind that a compression test is just a general test. It can only tell you the problem cylinder(s). It can't tell you what's wrong with that cylinder necessarily other than that it's low on compression.
Another test that can give you a little more information is a wet test. A wet test is when you insert a small amount of oil into the cylinder before you do the compression test. After the oil is in the cylinder, do the test again and take a reading. You should see a jump in readings by doing this because the oil will help seal the rings on the piston. If you see a significant increase, this could indicate that your rings aren't sealing well and it might be time for a replacement or rebuild of the engine.
That's about the limit of what a compression test can tell you. If you want more information you can do a leak down test, which I'll get into next. In the meantime, here's a video on how to perform a compression test.