How spam filters work
Follow two messages that both claim to be from the same shop through the checks a mail provider runs: reputation, SPF, DKIM, DMARC, content scoring and your own reports.
In 30 seconds
A spam filter asks three questions about every incoming message: who sent it, is it really them, and is it wanted?
Reputation is the sender’s track record. SPF, DKIM and DMARC are checks against records the real domain publishes, and they expose forged senders.
A content classifier then scores the message itself. Your “Report spam” and “Not spam” clicks correct its mistakes, including real mail wrongly caught, which is called a false positive.
How spam filters work, step by step
Simplified: real filters weigh hundreds of signals together rather than in a fixed order, and keep the details secret. The addresses, rates and scores are invented examples.
- Step 1: Two messages, one From line. Two messages reach your mail provider, and both claim to come from shop.example. One was sent by the shop’s own server, the other by a forger. Email lets anyone type any address in the From line, so before delivering anything the receiving server runs a series of checks.
- Step 2: Sender reputation. First, the track record. Mail providers keep a history for every sending IP address and domain: how much it sends, how often recipients report it as spam, how many addresses bounce, whether it sits on a blocklist. A sender with a poor record is slowed down, sent to spam or refused before its content is even read.
- Step 3: SPF: is this server allowed?. SPF (Sender Policy Framework) lets a domain publish, in DNS, the list of servers allowed to send its mail. The receiver looks up that list and compares it with the IP address that actually connected. The shop’s server is inside the listed range; the forger’s is not. SPF checks the hidden return address, not the From line.
- Step 4: DKIM: signed and unchanged?. DKIM (DomainKeys Identified Mail) adds a digital signature. The shop’s server signs each message with a private key only it holds; the matching public key sits in DNS for anyone to fetch. If the signature verifies, the message was signed by that domain and has not been altered on the way. The forger has no key to sign with.
- Step 5: DMARC: match the From line. DMARC ties the two checks to the address people actually see. It passes only if SPF or DKIM passes for the same domain as the From line. The domain owner also publishes what to do with failures: nothing, quarantine (spam folder) or reject. The shop says reject, so the forged message is refused.
- Step 6: Content classifier. Proving who sent a message does not prove it is wanted: spammers can set up SPF, DKIM and DMARC for their own domains. So a classifier, a model trained on huge numbers of messages already labelled spam or not, scores the content: wording, links, layout, attachments. A high score sends the message to the spam folder.
- Step 7: Reports, and mistakes. No filter is perfect. Spam that reaches the inbox is a false negative; real mail caught as spam is a false positive, usually the costlier mistake, so filters are tuned to keep it rare. Your clicks on “Report spam” and “Not spam” are feedback: they adjust the sender’s reputation and become training examples for the classifier.
Try it yourself
Learn this first
Spotted a mistake on this page?