How the internet worksExhibit 21

Why do emails go to spam?

A spam filter asks who sent the message, scores what it says, and listens to what people report. We built a tiny word-counting filter from 4,136 real text messages. On 1,035 messages it had never seen it got 98% right, and then one friendly sentence fooled it.

Try it: write a message, watch the score

This is the small filter from our video. It learned from 4,136 real text messages and only counts words. Type anything: each word pushes the score towards spam or away from it. Nothing you type leaves your browser.

Or try one of ours
Spam score
–
Verdict
–

A word-counting filter is easy to fool, as the examples show. Real mail filters also check who sent the message, the sender's reputation and reports from people. The training messages are texts, not emails.

The video for this exhibit comes out on YouTube on Friday 29 January. Subscribe so you don’t miss it

Who sent it

Before a filter reads a single word, it checks the sender. A domain can publish a list of the servers allowed to send its mail; that record is called SPF. It can also sign each message with a key, so the receiver can tell if it was faked or changed; that is DKIM. A third record, DMARC, tells receivers what to do when those checks fail. Since February 2024, Gmail requires all three from anyone sending about 5,000 or more messages a day to personal Gmail accounts.

What it says

The classic method is counting words. In the 4,136 real messages our filter learned from, the word "free" appeared in 23.6% of the spam and 1.2% of the rest; "claim" in 14% of the spam and almost never otherwise; "later" went the other way. Every word nudges the score up or down, and the filter adds up the nudges. The idea became widely known through Paul Graham's 2002 essay A Plan for Spam.

What we measured

We wrote the filter from scratch and trained it on the SMS Spam Collection, a public set of real text messages labelled spam or not (they are texts, not emails). The set contains word-for-word copies, so we kept each message once: 5,171 messages. Shown 1,035 messages it had never seen, it caught 120 of the 131 spam messages and wrongly flagged 6 of the 904 real ones: 1,018 right, or 98%. Always answering "not spam" would already score 87% on this data, so the two counts say more than the percentage.

How we fooled it

A prize message we wrote scored 100% spam. With letters swapped for digits it was still spam. With the words misspelled it passed, at 11%. With one friendly sentence added at the end it dropped to under 7%. That is why real filters do not stop at words: they also weigh the sender's reputation and how many people report the mail as spam.

Why real mail gets lost

Often one of three things: the sender never set up the identity checks; too many people marked their earlier mail as spam (Gmail's limit for senders is a reported spam rate of 0.3%, three in a thousand); or the message simply reads like spam. If a real email lands in your spam folder, mark it as not spam; Google says that trains the filter.

Frequently asked questions

Why do real emails go to spam?

Often for one of three reasons: the sender has not set up the identity checks (SPF, DKIM, DMARC), too many recipients marked the sender's earlier mail as spam, or the wording looks like spam to the filter.

How does a spam filter decide?

It combines several things: whether the sender passes identity checks, the sender's reputation, the words and links in the message, and reports from people. Our demo shows only the word-counting part.

How accurate was the filter in the video?

Trained on 4,136 real text messages and tested on 1,035 it had never seen, it caught 120 of 131 spam messages and wrongly flagged 6 of 904 real ones, which is 98% right overall.

Can spammers fool a filter that counts words?

Yes. In our test, misspelling the words or adding one friendly sentence made a prize message pass. That is why real filters also look at who is sending and how people react to the mail.

Sources

Last updated

Keep exploring