By the early 2000s, email was close to unusable. Unsolicited commercial messages made up a rapidly growing share of all mail, and by some measurements passed half of it in 2003 on the way to a peak of around 90 per cent later in the decade.

The defences of the time were rules written by hand. If the subject line contains "FREE!!!", add points. If the message mentions a particular drug, add points. Above a threshold, discard. Senders adapted in days. They wrote "F R E E" and "V1agra", and the rule-writers were always a step behind.

In August 2002 the programmer Paul Graham published an essay called "A Plan for Spam". Its proposal was to stop writing rules and let the filter work them out from examples.

Words as evidence

The method rests on a theorem published in 1763, two years after the death of its author, the English minister Thomas Bayes. Bayes's theorem describes how to revise a probability in the light of new evidence.

Applied to mail, it works as follows.

Take two piles of old messages, one of spam and one of legitimate mail. For each word, count how often it appears in each pile. Suppose "mortgage" turns up in 30 per cent of spam messages and 1 per cent of legitimate ones. Then a message containing "mortgage" is, on that evidence alone, much more likely to be spam. Suppose "meeting" appears in 0.5 per cent of spam and 15 per cent of legitimate mail. It is evidence the other way.

When a new message arrives, the filter looks up each of its words, takes the most telling ones in either direction, and combines their probabilities into a single figure: the probability that this message is spam.

The technique is called naive Bayes. It is naive because it treats each word as independent of the others, which is plainly false, since "credit" and "card" travel together. It works remarkably well in spite of that.

Why it beat the rules

Three properties made it effective.

It learns each user's mail. For a pharmacist, the names of drugs are evidence of legitimate mail. A filter trained on that person's own messages learns this. A general rule cannot.

It finds signals nobody would think of. Graham reported that in his own mail, the colour code for bright red in the formatting was one of the best indicators of spam. No one would have written a rule for that.

It uses evidence of innocence. Rules could only add suspicion. A statistical filter also counts the words that make a message look legitimate, such as the names of colleagues or the jargon of the user's trade. This sharply reduces the number of real messages lost.

That last point matters most. In filtering, the two kinds of error are not equally costly. A spam message that slips through costs a second of attention. A real message wrongly discarded, such as a job offer, an invoice or a note from a doctor, can cost a great deal. Graham reported catching 99.5 per cent of his spam with no false positives at all. Open-source filters built on the idea spread within months.

The senders respond

A spam filter differs from most uses of machine learning in one respect. The thing being classified is produced by someone who wants to be misclassified, and who can study the classifier.

Word salad. Spammers padded messages with passages from novels and news reports, to add innocent words. This is called Bayesian poisoning. It helped somewhat, though the sales pitch still had to be in there.

Obfuscation. Misspellings, inserted punctuation and look-alike characters from other alphabets. Filters learnt that these were themselves strong signals.

Image spam. Around 2006 the text moved into pictures, which word-counting filters could not read. Filters added optical character recognition and analysis of image properties. Senders added noise and distortion to defeat that. Image spam fell away after a year or two as filters caught up.

Less to analyse. Messages shrank to a line and a link, with the content on a web page. Filters began to follow and assess links.

The pattern has repeated ever since. A defence is deployed, the adversary adapts, and the defence is retrained.

Beyond the content

The large email providers long ago moved past looking at words alone. A modern filter weighs hundreds of signals.

Reputation. How much mail has this sending address, server or domain sent before, and how was it received? A server that began sending a million messages yesterday is suspect, whatever they say.

What users do. Every click on "report spam" or "not spam" is a labelled example. A provider with a billion users receives an immense stream of them, and can spot a new campaign within minutes of its first messages.

Volume and similarity. Messages nearly identical to thousands of others sent in the same hour.

Links and attachments. Where the links actually lead, how new the destination is, and what an attachment does when opened in an isolated test environment.

Authentication. Whether the message can be shown to come from where it claims.

The classifiers are now deep neural networks, in place of naive Bayes. One large provider has stated that its systems block more than 99.9 per cent of spam, phishing and malware.

Authentication

Email was designed in an era of trust, and the sender's address on a message can be set to anything. Three later standards allow a receiving server to check.

SPF lets the owner of a domain publish the list of servers allowed to send its mail.

DKIM has the sending server add a cryptographic signature, which the receiver verifies against a key the domain publishes.

DMARC ties the two to the address the reader actually sees, and lets the domain owner say what should happen to mail that fails: deliver it, quarantine it or reject it.

A domain with a strict DMARC policy is hard to impersonate exactly. Since 2024 the largest mailbox providers have required bulk senders to authenticate their mail, which has pushed adoption along.

Authentication has a limit worth understanding. It proves that a message came from the domain it claims. It says nothing about whether that domain is the one you think it is. A message properly signed by "paypa1-secure.example" passes every check.

Phishing

Bulk spam is largely a solved problem for most users. The harder problem is the message crafted to deceive a specific person.

A phishing message does not resemble spam statistically. It is sent in small numbers. It contains ordinary business language. It may carry no link and no attachment, only a request: I'm in a meeting, can you process this payment today? Fraud of that kind, in which a criminal poses as an executive or a supplier, has cost organisations billions, according to the FBI's annual figures.

Filters respond by looking for subtler things. Is the display name that of a senior person, while the address is external? Is this the first message ever received from this sender? Does the reply go to a different address? Is the language urgent and about money? Does the writing style differ from that person's earlier mail?

Language models have helped both sides. Attackers no longer need to write fluently in the target's language, so the spelling mistakes that people were taught to look for have gone. Defenders use the same technology to judge the intent of a message, beyond its vocabulary.

What remains for the reader

Since no filter is complete, the last check falls to the person reading. Technical clues such as bad spelling have become unreliable. What works is to look at what the message wants.

A message deserves a second look if it asks you to do any of the following:

  • pay money, or change the bank details for a payment
  • enter a password or approve a login
  • open an unexpected attachment
  • buy gift cards
  • act immediately, or keep the request to yourself

For any of those, verify by another route. Telephone the person on a number you already have. Go to the site by typing its address, not by following the link. A request that is real will survive a five-minute delay.

A password manager helps here too, since it will not fill in a password on a site whose address does not match.

What the story shows

The spam filter is the longest-running experiment in applying machine learning against an intelligent opponent, and a few conclusions from it apply much more widely.

Learning from data beat hand-written rules decisively. It did not remove the need for people: someone has to label examples, watch for drift and decide what the errors cost.

The two kinds of error have to be weighed separately. A filter judged only on how much spam it catches will discard real mail.

A model that faces an adversary is never finished. Its accuracy on last month's data says little about next month.

And the most valuable signals turned out to lie outside the content, in who was sending, how much, and whether the origin could be proved. Bayes's theorem got the field started, and identity and reputation now do most of the work.