Skip to content
SpoofKiller
Fundamentals

What Is SPF? Sender Policy Framework Explained

How SPF lets a domain list its mail servers, how receivers check it, and where it falls short on its own.

Reading time
6 min read
Last updated
Updated
Two hands patching cables into a switchboard whose lamps glow green, amber, and red.
SPF authorizes the line a call comes in on. It has no opinion about who is speaking.
In this guideShow 7 sections

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.

MechanismMatches whenCosts a DNS lookup?
ip4: / ip6:The IP is in the given address or rangeNo
include:The IP passes the named domain’s SPF recordYes, plus whatever that record contains
aThe IP matches the domain’s A or AAAA recordYes
mxThe IP belongs to one of the domain’s mail exchangersYes
exists:A lookup of the given name returns any A recordYes
allAlways; it is the catch-all at the endNo

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 -all is 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 (-all matched).
  • softfail: probably not authorized (~all matched).
  • 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:

  1. One record per domain name, starting with v=spf1.
  2. List only services that actually send with your domain in the envelope sender. Remove the ones you stopped using.
  3. Stay under ten lookups, with room to spare for providers that grow.
  4. End with -all or ~all. Never +all.
  5. 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.

FAQ

Questions about What Is SPF

Short answers to what readers ask next. If yours is missing, write to us and a person will reply.

Ask a question

Free, no obligation

Want a second pair of eyes on your records?

Send us your domain. We will look at its DMARC, SPF, and DKIM setup and write back, in plain English, with what we found and what to fix first.

  • A person reads your records, not a script
  • Specific fixes, in order of importance
  • No sales sequence afterward

We use your details to reply. Nothing else.

Reading about it is the slow way.

Run the free check and see your own domain's DMARC, SPF, and DKIM in the time it took to read this paragraph. No account, no card.