SPF too many DNS lookups: the limit of 10 and how to get under it

By TechCompare · Updated · How we check

Count every include, a, mx, ptr and exists term and every redirect, including the ones inside included records. Ten is the most you get, and ip4, ip6 and all are free.

RFC 7208 caps an SPF check at 10 DNS lookups. Every include, a, mx, ptr and exists term costs one, and so does a redirect. The terms inside each included record count too, so a few email services can use up the whole budget on their own. Go over and receivers stop with a permanent error, so SPF can't pass for any of your mail.

Topic
SPF lookup limit
SPF
Category
Email records
SPF, DKIM and DMARC

How this is calculated

The limit protects receivers. Without it, one SPF record could make a mail server send dozens of DNS queries for every message, and an attacker could use that to flood someone else's name servers. So the RFC sets a hard cap, and a receiver that follows it stops as soon as an eleventh lookup is needed.

It's easy to go over without noticing. Each email service you add hands you an include, and that include often has includes of its own. The record on your domain might show four terms while the real count is twelve. RFC 7208 also tells receivers to allow at most two void lookups (ones that come back with no records or a name that doesn't exist), so includes that point at retired names hurt twice.

Ways to get back under the limit, from safest to riskiest:

  • Remove includes for services that no longer send mail for you.
  • Replace a and mx terms with the ip4 and ip6 ranges they stand for, if those addresses rarely change.
  • Drop ptr. The RFC says not to use it.
  • Move a bulk sender to its own subdomain, like news.example.com, with its own SPF record.
  • Flatten includes into IP lists. This works, but it breaks quietly when a provider changes its addresses, so only do it with a service that keeps the list up to date.

The DNS Lookup follows every include and redirect, counts the lookups through the whole tree, and shows how many each include uses, so you can see which one to cut.

Verdict

Keep a margin and aim for 8 or fewer, since providers add includes without telling you. Start by deleting includes for services you've stopped using, then move bulk senders to subdomains. Flattening is a last resort. Check the count again after any change to your mail setup, and whenever a provider announces new sending addresses.

More DNS scenarios

TXT records
The free text record that holds verification codes, SPF, DKIM keys and DMARC policies.
View details
SPF vs DKIM vs DMARC
SPF checks the sending server, DKIM checks the message, and DMARC ties both to the From address.
View details
MX records
How senders find your mail servers, what the priority number does, and the null MX for domains that take no mail.
View details

Frequently asked questions

Which SPF terms count toward the 10 lookup limit?
include, a, mx, ptr and exists, plus the redirect modifier. Terms inside included records count too. ip4, ip6 and all don't touch DNS, so they're free.
What happens when SPF goes over 10 lookups?
The receiver stops and returns a permanent error (permerror). SPF then can't pass for any message, so DMARC has to rely on DKIM alone, and some receivers treat the error as a plain fail.
Is SPF flattening safe?
It works until a provider changes its sending addresses. A flattened record lists IP ranges instead of includes, so it doesn't pick up the change, and mail from the new addresses fails SPF. Use it only with a service or script that rebuilds the list on a schedule.