There are several ways to do it, but none are 100% effective. I'm using one of the better ones on my own blog which stops about 150-200 spams a day, but I still have to manually delete 2-6 per day.