What is an SPF record?
SPF (Sender Policy Framework, RFC 7208) is a TXT record that lists the servers allowed to send email for a domain. When a message arrives, the receiving server looks up the SPF record of the domain in the envelope sender (the Return-Path) and checks whether the connecting IP address is on the list.
A typical record for a company that uses Microsoft 365 and a newsletter service looks like this:
v=spf1 include:spf.protection.outlook.com include:servers.mcsv.net -all
SPF on its own only checks the hidden envelope sender, not the From address people see. To stop spoofing of the visible From address you also need DMARC, which ties SPF and DKIM to the From domain.
How to read the results
- SPF record found: the domain publishes exactly one TXT record starting with
v=spf1. Two or more SPF records is an error: receivers treat the result as PermError, which usually means SPF fails. - DNS lookups used: every
include,a,mx,exists,ptrandredirectcosts one DNS lookup, including the ones inside included records. The limit is 10. Over 10, SPF returns PermError for every message, so ZoneProbe warns from 8 onwards. - The "all" ending:
-all(fail) and~all(soft fail) both protect the domain once DMARC is enforcing.?allgives no protection, and+alllets any server in the world send as the domain. - Include tree: each include is expanded, so you can see which service uses up the lookups.
- Terms: every mechanism in the record, with what it matches.
Common SPF problems and how to fix them
Too many DNS lookups (more than 10)
This is the most common SPF failure, and it builds up quietly as services are added. To fix it:
- Remove includes for services you no longer use.
- Replace
aandmxwith theip4:orip6:ranges they point to, if those addresses rarely change.ip4andip6cost no lookups. - Send bulk or marketing mail from a subdomain, such as
news.example.com, with its own SPF record.
"Flattening" (replacing includes with the IP addresses they currently resolve to) also works, but the record breaks silently when the provider changes its addresses, so it needs to be kept up to date automatically.
Multiple SPF records
Adding a second v=spf1 record for a new service is a frequent mistake. Merge them into one record, keeping every include and a single all at the end.
Include loops and broken includes
An include that points to a domain with no SPF record, or that doesn't exist, makes the whole evaluation fail. A loop, where a record includes one of the records that included it, fails too. ZoneProbe shows the chain so you can see where it goes wrong. Including the same domain twice from different places isn't a loop, but each copy still counts toward the limit.
Mail from a service isn't covered
If a sending service (a CRM, helpdesk or invoicing tool) isn't in the record, its mail can fail SPF. Add the include the provider documents, or have it send with its own envelope domain and sign with DKIM for your domain.
SPF mechanisms at a glance
| Term | Lookups | Matches when |
|---|---|---|
ip4:203.0.113.0/24 | 0 | the sender's IPv4 address is in the range |
ip6:2001:db8::/32 | 0 | the sender's IPv6 address is in the range |
a, a:host | 1 | the sender is one of the host's A or AAAA addresses |
mx | 1 (plus up to 10 address lookups for the MX hosts) | the sender is one of the domain's mail servers |
include:domain | 1, plus its own | the other domain's SPF record passes |
redirect=domain | 1 | uses the other domain's record instead (only if no all) |
-all / ~all | 0 | everything else: fail or soft fail |
Frequently asked questions
Should I use -all or ~all?
With DMARC set to quarantine or reject, both work, because DMARC decides what happens to failing mail. ~all is the safer choice while you're still finding all the services that send for you; -all is stricter and fine once the record is complete.
Do subdomains inherit the SPF record?
No. SPF is checked against the exact domain in the envelope sender. A subdomain that sends mail needs its own record, and one that never sends mail can publish v=spf1 -all.
How long does an SPF change take to work?
As long as the old record's TTL, typically a few minutes to an hour. You can watch the change reach resolvers with the DNS propagation checker.
What is a void lookup?
A lookup that returns no answer or a domain that doesn't exist. RFC 7208 recommends that receivers allow at most two per evaluation and return PermError beyond that. Void lookups usually come from includes for services you've stopped using.
Does a domain that never sends email need SPF?
Yes. Publish v=spf1 -all together with a DMARC policy of p=reject, so nobody can send convincing mail using the domain.