SPF 'too many DNS lookups': what breaks and how to fix it
Go over 10 DNS lookups in your SPF record and receivers are supposed to return permerror instead of pass or fail. I assumed that meant all your mail starts failing at once. It doesn’t, and the real behavior is stranger, so I built a realistic fixture, counted the lookups, and evaluated a handful of sender IPs with an independent SPF implementation.
What counts toward the limit
RFC 7208, section 4.6.4, caps the number of terms that trigger a DNS query, and it counts them across the whole evaluation, nested includes and all.
include, a, mx, ptr, exists and the redirect= modifier cost one each. ip4, ip6 and all are free. An mx term counts once, but the address lookups for the hosts it returns are capped separately: more than 10 of those and the mx term itself gives a permerror. On top of the 10, the RFC says implementations should also give up after more than 2 “void” lookups (queries that come back empty). pyspf enforces that one.
So your record can look short and still be over, because every include: carries whatever is inside it.
Count it recursively
The SPF and DMARC checker on this site only counts the terms in the text you paste, since it never makes a DNS query. For the real number you have to follow the includes. The script I used is in the evidence folder and works with DNS-over-HTTPS or a JSON fixture:
python3 spfcount.py company.test zone-before.json
This is the fixture’s output. company.test isn’t a real domain, and every name and IP in the fixture is made up:
include:_spf.bigsuite.test [lookup 1]
include:_n1.bigsuite.test [lookup 2]
include:_n2.bigsuite.test [lookup 3]
include:_n3.bigsuite.test [lookup 4]
include:spf.mailer-a.test [lookup 5]
include:spf.crm-b.test [lookup 6]
include:eu.crm-b.test [lookup 7]
include:us.crm-b.test [lookup 8]
include:spf.support-c.test [lookup 9]
a:relay.support-c.test [lookup 10]
include:spf.oldvendor-d.test [lookup 11]
a [lookup 12]
mx [lookup 13]
TOTAL: 13 DNS-lookup terms, 0 void lookups -> OVER THE LIMIT (permerror)
The top-level record has 7 lookup terms. The other 6 sit inside the vendors’ own records, where you can’t see them without following the includes.
What actually fails: order matters
Next I evaluated seven sender IPs against that record with pyspf, which is a separate implementation from my counter (pyspf_eval.py):
198.51.100.5 -> pass sender SPF authorized
203.0.113.70 -> pass sender SPF authorized
203.0.113.140 -> pass sender SPF authorized
192.0.2.150 -> pass sender SPF authorized
192.0.2.200 -> permerror SPF Permanent Error: Too many DNS lookups
192.0.2.10 -> permerror SPF Permanent Error: Too many DNS lookups
8.8.8.8 -> permerror SPF Permanent Error: Too many DNS lookups
SPF evaluation stops at the first term that matches. Senders covered by terms 1 to 10 passed without the limit ever coming into play. Senders that can only be reached after the 10th lookup got the permerror. Here that’s 192.0.2.200, which sits in the last vendor include, and 192.0.2.10, the company’s own server, matched by the trailing a.
Two things jumped out at me. The company’s own mail server broke, which is about the most basic thing SPF is meant to authorize. And a stranger’s IP (8.8.8.8) got permerror, not the fail that the closing -all promises, so the record wasn’t protecting anyone either.
So the limit doesn’t take everything down. Whatever sits late in the record breaks, and which senders those are depends on term order. That’s why it can look random in DMARC reports: one vendor is fine, another isn’t, and nothing you changed explains it. DKIM alignment can still carry some of that mail through DMARC, but I wouldn’t lean on it.
Fix 1: trim what you don’t use
Two cheap edits. Drop the decommissioned vendor (oldvendor-d), and swap a mx for the literal address of the one server that really sends mail:
v=spf1 include:_spf.bigsuite.test include:spf.mailer-a.test include:spf.crm-b.test include:spf.support-c.test ip4:192.0.2.10 -all
TOTAL: 10 DNS-lookup terms, 0 void lookups -> within limits
All five authorized IPs passed, and 8.8.8.8 now got a proper fail SPF fail - not authorized. But ten is the maximum, so there’s no headroom. Adding one more vendor puts you back over.
Fix 2: flatten the heaviest include
The costliest hidden item was bigsuite, at 4 lookups. I replaced its three nested netblocks with literal ip4: terms:
v=spf1 ip4:198.51.100.0/25 ip4:198.51.100.128/25 ip4:203.0.113.0/26 include:spf.mailer-a.test include:spf.crm-b.test include:spf.support-c.test ip4:192.0.2.10 -all
TOTAL: 6 DNS-lookup terms, 0 void lookups -> within limits
Every sender check still passed. The catch is that a flattened list is a copy. The day the vendor changes its ranges, your record is stale and legitimate mail starts failing, with nothing in your DNS to tell you why. Only flatten if something regenerates the record on a schedule, or if you’re willing to re-check it by hand every so often.
Fix 3: split by purpose
Put high-volume senders such as newsletters on a subdomain like news.company.test, with its own SPF record and its own budget of 10, and send that mail from the subdomain. I didn’t test this one. It works because each domain’s record is evaluated on its own, but that’s the RFC talking, not my output.
A live snapshot
I ran the same script against live DNS on 2026-12-02. github.com came out at exactly 10 of 10 lookups (one of them an exists: macro inside the Salesforce include), and atlassian.com at 6. Those numbers change whenever a domain or a vendor edits a record, so read them as a snapshot, not a verdict on either company. What I took from it: a large, well-run domain can sit right at the limit, so counting once and forgetting isn’t enough.
Checklist
Count recursively instead of reading the top-level record. Remove vendors you no longer send through, but look at your DMARC reports first to confirm a sender is really unused. Use ip4: or ip6: for servers you own when the address is stable, rather than a or mx. Skip ptr, which is deprecated, and never leave a trailing +all.
As a rule of thumb (mine, not the RFC’s), keep a couple of lookups of headroom and re-count whenever anyone adds a vendor. After a change, check the record with a second implementation if mail matters, and keep an eye on your DMARC aggregate reports for permerrors.
Check many domains at once
The script checks one domain at a time. If you look after a lot of them, my Apify Actor (linked below) returns the recursive SPF lookup count for each domain, along with DMARC, DKIM, MTA-STS, TLS and header checks.
Reproduce it
run.sh in the evidence folder regenerates every output on this page. It needs Python, curl for the live part, and pyspf with dnspython in a virtualenv, which tested-tools/setup.sh installs.
Related
- SPF only authenticates the sending server. To decide what happens to mail that fails, read DMARC from p=none to reject.
- Other DNS-level debugging: DNSSEC SERVFAIL, broken signatures or broken DNS?
- Another tested guide on this site: GitHub Actions script injection and actionlint.