Brad has made a post on Google blog explaining "how Gmail's spam filters works".
...you can use Gmail for things you enjoy without even realizing that the spam filter is there most of the time. It's not too different from driving a convertible down the freeway with the top down, with the wind blowing through your hair and no traffic jams to destroy the mood. Now, I'm not saying we're perfect, but the really good news is that it seems like spammers are finally starting to get discouraged. Attempts to spam Gmail users have been leveling off over the last year and more recently, even declining slightly. We need your help clicking on the "Report Spam" button, but through continuous improvement we are approaching the world we all want to live in.
Gmail's filters are constantly improving and an important ingredient of their effectiveness is the use of community signals. Every time you click on the "Mark as spam" button, Gmail uses that information to block similar future messages not only for you, but for all Gmail users.
"Many Google teams provide pieces of the spam-protection puzzle, from distributed computing to language detection. For example, we use optical character recognition (OCR) developed by the Google Book Search team to protect Gmail users from image spam. And machine-learning algorithms developed to merge and rank large sets of Google search results allow us to combine hundreds of factors to classify spam," explains Google. "Gmail supports multiple authentication systems, including SPF (Sender Policy Framework), DomainKeys, and DKIM (DomainKeys Identified Mail), so we can be more certain that your mail is from who it says it's from. Also, unlike many other providers that automatically let through all mail from certain senders, making it possible for their messages to bypass spam filters, Gmail puts all senders through the same rigorous checks."
Here's a video explaining how spam filters work:
Gmail, Webmail, Spam, Spam Filters, Video, YouTube