The SPF lookup limit and how to stay under it

RFC 7208 caps the DNS lookups a receiver makes while evaluating SPF at 10. Go over and SPF returns permerror for every message, which DMARC counts as a failure. Most domains hit the limit by adding one sending service too many.

What counts as a lookup

Section 4.6.4 of RFC 7208 counts every term that makes the receiver query DNS: include, a, mx, ptr, exists and the redirect modifier. The lookups inside an included record count too, so include:_spf.google.com costs one for itself plus the includes Google's record contains.

ip4, ip6 and all cost nothing. An mx term also has its own limit: no more than 10 address lookups for the MX hosts it finds.

There is a second limit people miss: no more than two void lookups, meaning lookups that return no records or a name that does not exist. A stale include for a service you cancelled is the usual cause.

An example over the limit

This record looks short but needs 12 lookups once every include is followed:

SPF record with too many includes
example.com. TXT "v=spf1 mx include:spf.protection.outlook.com include:_spf.google.com include:sendgrid.net include:mailgun.org include:servers.mcsv.net include:_spf.salesforce.com -all"

Run it through the SPF checker and the tree shows which include is expensive. Large providers often nest three or four lookups behind one include.

Five ways back under 10

  1. Remove senders you no longer use. DMARC aggregate reports show which services have sent mail as you in the last month; an include with no traffic for 60 days is a candidate.
  2. Remove duplicates. Two includes that both pull in the same provider's record cost twice.
  3. Replace a and mx with the addresses they resolve to, when those addresses are yours and rarely change.
  4. Send marketing mail from a subdomain such as news.example.com with its own SPF record, so the main domain carries only the senders that use it.
  5. Flatten an include into ip4 and ip6 ranges only when you accept the upkeep. SPF flattening risks explains why that needs watching.

Check the result

After any change, check the published record again: count lookups, confirm there is exactly one v=spf1 record, and confirm every sender in your DMARC reports still passes. The SPF generator counts lookups against live DNS before you publish.