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:
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
- 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.
- Remove duplicates. Two includes that both pull in the same provider's record cost twice.
- Replace
aandmxwith the addresses they resolve to, when those addresses are yours and rarely change. - Send marketing mail from a subdomain such as
news.example.comwith its own SPF record, so the main domain carries only the senders that use it. - Flatten an include into
ip4andip6ranges 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.