SPF is a guest list. The domain owner writes down which mail servers are invited to send on its behalf, pins the list to the door, and the bouncer at the receiving end checks each arrival against it. It is a simple idea, it has been standard practice for the better part of two decades, and it has one flaw of real comic value: the bouncer checks the name on the delivery van, not the name on the letter.
That flaw is why SPF alone has never stopped anyone from forging a From address, and why it still matters anyway. To see both, it helps to look at exactly what is being checked.
What SPF is
SPF, the Sender Policy Framework, is defined in RFC 7208. It lets a domain publish, in a single DNS TXT record, the set of IP addresses permitted to send mail using that domain. A receiving server looks up the record, compares it with the IP address of the machine that just connected, and arrives at a result.
example.com. TXT "v=spf1 include:_spf.google.com ip4:203.0.113.25 -all"In English: mail for this domain may come from whatever Google lists in its own SPF record, or from the single address 203.0.113.25, and from nowhere else. You can run any domain through the SPF checker to see its record expanded this way.
What it checks, and the address it ignores
An email has two sender addresses. The envelope sender, also called the Return-Path or MAIL FROM, is given during the SMTP conversation and is used for bounces. The From header is the one displayed to the reader. SPF evaluates the domain in the envelope sender. It does not look at the From header at all.
So a forger who wants to send mail as you@yourcompany.com sets the From header to your address and the envelope sender to a domain he owns, complete with a flawless SPF record. SPF passes. The reader sees your name. Nothing in SPF objects, because nothing in SPF was asked.
SPF answers a question nobody reading the email thought to ask: is the bounce address legitimate?
The repair came later, with DMARC, which requires that the domain SPF validated match the domain in the From header. That requirement is called alignment, and it is what turns SPF from a courtesy into a control. The comparison in SPF vs DKIM vs DMARC shows how the three divide the work.
How to read an SPF record
A record starts with v=spf1 and is followed by mechanisms, evaluated left to right. The first one that matches the connecting IP decides the result.
| Mechanism | Matches when | Costs a DNS lookup? |
|---|---|---|
ip4: / ip6: | The IP is in the given address or range | No |
include: | The IP passes the named domain’s SPF record | Yes, plus whatever that record contains |
a | The IP matches the domain’s A or AAAA record | Yes |
mx | The IP belongs to one of the domain’s mail exchangers | Yes |
exists: | A lookup of the given name returns any A record | Yes |
all | Always; it is the catch-all at the end | No |
Each mechanism can carry a qualifier that sets the result when it matches. + means pass and is the default, so nobody writes it. - means fail. ~ means softfail: probably not authorized, but do not be hasty. ? means neutral, which is to say no opinion. The qualifier that matters most is the one on the final all:
-all: anything not listed is unauthorized.~all: anything not listed is probably unauthorized. Under a DMARC policy the practical difference from-allis small, since DMARC treats both as not passing.?all: no statement. Rarely useful.+all: every server on the internet is authorized. This is a guest list reading “everyone,” and it appears in real records more often than one would hope.
There is also a redirect= modifier, which hands the whole evaluation to another domain’s record, and a ptr mechanism, which the standard itself says not to use.
The limit of ten
To keep a single email from triggering an avalanche of DNS queries, the standard caps the number of lookups an SPF evaluation may cause at ten. The mechanisms include, a, mx, exists, ptr, and the redirect modifier each count. Crucially, lookups inside an included record count too. An include: for a large provider can quietly cost three or four by itself.
Go over ten and the result is permerror, a permanent error, and receivers treat the record as broken. Mail that depended on SPF stops passing, often months after the record last changed, because a provider you include added a lookup to its record without telling you. There is a second, lesser-known cap: more than two lookups that return nothing, called void lookups, also produce permerror. A stale include: for a service that no longer exists is how that happens.
The count is tedious to do by hand, which is why the SPF checker does it the way a receiver would, and why SPF monitoring repeats the check on a schedule and warns you when the number moves. The remedies are in common SPF errors and how to fix them.
The seven possible results
An SPF evaluation ends in exactly one of these:
- pass: the IP is authorized.
- fail: the IP is explicitly not authorized (
-allmatched). - softfail: probably not authorized (
~allmatched). - neutral: the domain declines to say.
- none: there is no SPF record.
- temperror: a DNS timeout; try again later.
- permerror: the record is broken. Too many lookups, a syntax error, or two SPF records on the same name.
That last cause deserves emphasis. A domain may have only one TXT record beginning with v=spf1. Adding a second one for a new provider, instead of merging it into the first, invalidates both. The SPF record generator builds one combined record for all your senders.
Where SPF falls short
Forwarding breaks it
When a recipient forwards mail automatically to another address, the forwarding server becomes the connecting IP at the next hop. It is not on your list. SPF fails, though nothing dishonest occurred. This is unfixable from the sender’s side, and it is the main reason not to rely on SPF alone: DKIM signatures travel with the message and usually survive the trip.
Third-party senders rarely align
Most email services send with their own domain in the envelope sender, so SPF passes for their domain, not yours. For DMARC purposes that pass does not count unless the provider lets you set a custom Return-Path under your own domain. Adding the provider’s include: to your record in that situation spends a lookup and buys nothing. Alignment is explained here.
It authorizes machines, not messages
An include: for a shared email platform authorizes every customer of that platform to pass SPF as your domain, not only your account. SPF vouches for the building, not the tenant.
Getting it right
A sound SPF record follows a few rules, none of them difficult:
- One record per domain name, starting with
v=spf1. - List only services that actually send with your domain in the envelope sender. Remove the ones you stopped using.
- Stay under ten lookups, with room to spare for providers that grow.
- End with
-allor~all. Never+all. - Give domains that send no mail a record of
v=spf1 -all.
Then stop treating SPF as the whole answer. Turn on DKIM for every sender, publish a DMARC record so that the From address is finally part of the conversation, and read the reports; the DMARC configuration guide picks up where this one ends. A free domain health check will show all three at once, including the lookup count. The guest list is worth keeping. It just should not be the only thing on the door.

