Skip to content
AdminKit

Fixing SPF "too many DNS lookups" (PermError)

SPF has a hard limit of 10 DNS lookups per check, set by RFC 7208, and going even one over turns the entire check into a PermError, not a soft warning, so mail can fail authentication even though every sender is legitimate. AdminKit's SPF check counts your lookups; here's how to fix an over-limit record.

By AdminKit team, Netbase JSC · Updated

Key takeaways

  • RFC 7208 allows at most 10 lookup-causing terms (include, a, mx, ptr, exists, redirect) per SPF evaluation, counting every term inside nested includes. One more and the result is permerror.
  • ip4, ip6 and all cost nothing. Neither do the address lookups behind an mx term, which have their own separate cap of 10 per term.
  • Evaluation stops at the first match, so an over-limit record can pass for some senders and fail for others. That makes it look like an intermittent fault.
  • Fix it in this order: remove senders you no longer use, move bulk senders to a subdomain, replace a/mx for your own servers with ip4/ip6, and only then flatten third-party includes.
  • Check the draft with AdminKit’s offline SPF validator, publish, wait out the TTL, then confirm the live count with the SPF check.

What is the 10-lookup limit?

RFC 7208 §4.6.4 (also on the IETF Datatracker) caps SPF evaluation at 10 DNS lookups triggered by the mechanisms include, a, mx, ptr, exists, and the redirect modifier. The limit exists so a receiving server never has to chase an unbounded chain of DNS queries just to check one sender’s authorization — and the RFC is explicit that exceeding it is a PermError, a permanent failure of the whole check, not a warning or a partial result. A domain can have every real sending service correctly listed and still fail SPF entirely, purely because the record asks for an 11th lookup.

ip4, ip6, and the trailing all mechanism never cost a lookup — they’re evaluated directly against the connecting IP without touching DNS, so you can add as many of those as needed without affecting the count. Microsoft’s own SPF setup guidance independently confirms the same 10-lookup ceiling and lists include:, a, mx, exists and redirect as the mechanisms that count toward it.

The same RFC 7208 §4.6.4 also tracks a separate, smaller budget: a void lookup is any of those DNS queries that comes back empty or NXDOMAIN, and the RFC recommends capping those at 2 for the whole evaluation — independently of the 10-lookup count above. A stale include: left pointing at a vendor that deleted its SPF record is the usual cause, and it can turn into a PermError on its own even when the record is nowhere near 10 real lookups.

Here is how each SPF term is charged, per RFC 7208 §4.6.4:

TermCounts toward the 10?What else to know
include:Yes, 1Every lookup term inside the included record counts too
redirect=Yes, 1Ignored if the record also has an all mechanism (§6.1)
a, exists:Yes, 1 each
mxYes, 1Looking up the MX hosts’ addresses has its own cap of 10 per mx term
ptrYes, 1§5.5 says it “SHOULD NOT be published” at all
ip4:, ip6:, allNoMatched directly against the connecting IP

Why does the count creep up without anyone noticing?

Nobody writes an 11-lookup SPF record on purpose. It accumulates one legitimate addition at a time:

  • Each new sending tool (a CRM, a help desk, an invoicing platform, a newsletter service) typically asks you to add its own include: line.
  • Many of those include: targets are not flat IP lists themselves — they nest further includes, a, or mx mechanisms inside the provider’s own SPF record, and every one of those counts against your 10-lookup budget, not just the provider’s. Google’s SPF troubleshooting page gives the same warning: domains included by an included domain “are counted toward your DNS lookup limit”.
  • Records are rarely cleaned up. Google’s advice is to “only include domains that are actively sending email for you”, which in practice means someone has to check when a tool is retired.

A note on mx, because it is often over-counted: the mx term itself costs one lookup against the 10. Resolving the addresses of the mail hosts it returns does not add to that count. RFC 7208 instead sets a separate limit of 10 address lookups for each mx term, and exceeding it makes that term return permerror. AdminKit’s SPF check follows the same rule and charges mx once.

How do you count your lookups?

Start with AdminKit’s SPF check, which reads your domain’s SPF record and flags when it’s at or over the limit. It follows every include and redirect through nested records and charges each lookup-causing term once. Once the count passes 10 it stops following further includes, so an over-limit result reads “at least” a number rather than an exact total. To verify manually, use DNS lookup to pull the TXT record, then walk through it mechanism by mechanism.

Take this record for an imaginary domain. The provider names are placeholders, and the nested counts are made up for the example:

v=spf1 include:_spf.mail.example include:send.crm.example include:bounce.news.example a mx include:spf.helpdesk.example -all
TermOwn lookupLookups inside itRunning total
include:_spf.mail.example13 (three nested includes)4
include:send.crm.example116
include:bounce.news.example10 (only ip4 ranges)7
a108
mx10 (address lookups capped separately)9
include:spf.helpdesk.example1212

The top-level record has only six lookup terms, but the nested ones bring the total to 12. Microsoft’s page puts it simply: “having fewer than 10 include: statements doesn’t guarantee fewer than 10 DNS lookups.”

Why does PermError only hit some messages?

SPF evaluates terms from left to right and stops at the first match (RFC 7208 §4.6.2). Microsoft notes the consequence: a record can contain enough terms to need more than 10 lookups, yet checks for some senders never “go deep enough in the record to result in an error”. In the example above, mail from the main mailbox provider matches inside the first include, within the first four lookups, and passes. Mail from the help desk, or from an unlisted server that should get -all, needs the evaluation to reach the twelfth lookup and gets permerror instead.

So when one tool’s mail fails and another’s doesn’t, check the lookup count before you blame the vendor. It also means you can’t confirm a fix by sending one test message from your main mailbox.

Which fix should you try first?

Before flattening anything, check whether every include: is still needed. A tool you stopped using six months ago that never had its include: removed is the cheapest fix available — it costs nothing in ongoing maintenance, unlike flattening.

For services you do still need, these options remain, roughly from least to most maintenance:

  1. Move a sender to a subdomain. Microsoft recommends sending bulk or third-party mail from a subdomain (such as marketing.example.com). The subdomain gets its own SPF record and its own budget of 10, and problems with that mail don’t affect your main domain’s reputation.
  2. Replace a and mx for servers you run. If your own outbound servers have fixed addresses, list them as ip4/ip6. You control those addresses, so you’ll know when they change.
  3. Flatten the record. Resolve the provider’s current include: target to its underlying ip4/ip6 ranges and publish those directly instead of the include:. This removes the lookup entirely, but the provider can change its sending IP ranges without notifying you, so a flattened record needs a recurring re-check — it isn’t a one-time fix.
FixLookups savedOngoing costWhen it fits
Remove an unused includeAll of that include’s lookupsNoneThe service no longer sends for you
Move a sender to a subdomainAll of that sender’s lookupsOne more record to manageBulk, marketing or vendor mail
ip4/ip6 instead of a/mx1 per termUpdate when your servers moveYour own servers with fixed addresses
Flatten a third-party includeAll of that include’s lookupsWatch the vendor’s IP changesVendors with stable, documented ranges

Microsoft’s guidance on when to flatten matches the last row. It suits “non-Microsoft vendors with stable, documented IP address ranges”, and should be avoided for Microsoft 365 itself and for “any cloud service with dynamic or frequently changing IP addresses”. If you do flatten, Microsoft suggests recording which includes you replaced and when, and watching the vendor’s documentation for changes.

Applied to the example, removing the retired newsletter service and listing your own servers as ip4 brings the count from 12 to 9:

v=spf1 include:_spf.mail.example include:send.crm.example ip4:192.0.2.25 ip4:198.51.100.0/28 include:spf.helpdesk.example -all

How do you re-check before publishing?

Before publishing the edited record, you can check its syntax and lookup-causing term count straight from the text with the SPF validator — it reads the record you paste and counts the same include, a, mx, ptr, exists and redirect terms against the 10-lookup limit, entirely offline, so you don’t need the record to be live yet. It can’t see inside includes it never resolves, so treat its count as the top-level part only. After editing the record, re-run SPF check to confirm the lookup count is now under 10 and that -all (or your intended policy) is still the last mechanism. A changed record only takes effect once DNS has propagated it, which depends on the record’s TTL and intermediate resolver caching, so don’t assume a fix is live the instant you publish it — re-check after waiting out the old TTL. Google tells Workspace admins to allow 24 to 48 hours.

Two smaller limits matter once you swap includes for address ranges. Google notes that each string inside a TXT record is limited to 255 characters, and RFC 7208 §3.3 lets a long SPF record be published as several strings that receivers join back together. AdminKit’s TXT record splitter breaks a long value into strings that fit. Keep the whole thing to one SPF record per name: Microsoft and RFC 7208 §4.5 both treat two SPF records on the same name as permerror.

What happens if you ignore it?

A PermError isn’t cosmetic. RFC 7208 §8.7 describes it as an error that “definitely requires DNS operator intervention to be resolved”, and a receiver that rejects for it during SMTP should use reply code 550 with enhanced status 5.5.2. Even receivers that don’t reject outright no longer have an SPF pass for your domain. For DMARC, that leaves only DKIM to carry the message, so any stream without an aligned DKIM signature fails DMARC. Google also warns that receivers’ error messages vary, and some may say you have no SPF record at all, even though you do. Legitimate mail from your correctly listed senders can land in spam or be rejected until the count is back under the limit, with no warning beyond what your own SPF or DMARC tooling shows you.

If you’re setting up SPF, DKIM, and DMARC together for the first time, our SPF, DKIM and DMARC explained guide covers how the three records work together before you hit this specific failure mode. If SPF fails only for mail that passed through another server, the cause is forwarding rather than the lookup count; see why email forwarding breaks SPF. This guide is part of AdminKit’s email authentication cluster of SPF, DKIM and DMARC guides and tools.

This guide is general information, not a security audit of your specific network — see our disclaimer for what AdminKit's guidance does and does not commit to.

Frequently asked questions

Why does going over the limit cause a total failure instead of just ignoring the extra entries?

RFC 7208 specifies that exceeding 10 DNS-querying mechanisms during evaluation must produce a PermError, treated as a permanent, unrecoverable failure of the whole check — not a partial pass. The limit exists so a malicious or misconfigured record can't force a receiver into unbounded DNS lookups.

Which SPF mechanisms actually count toward the 10-lookup limit?

`include`, `a`, `mx`, `ptr`, `exists`, and `redirect` each count as one term toward the limit, and every such term inside a nested `include` counts too. `mx` and `ptr` can also trigger address lookups for the hosts they return, but RFC 7208 §4.6.4 caps those separately, at 10 address lookups per `mx` or `ptr` term, on top of the 10-term limit. `ip4`, `ip6`, and `all` never require a DNS lookup, so they're free to add without affecting the count.

Does nesting make the limit worse?

Yes. Each `include:` pulls in another domain's SPF record, and every lookup mechanism inside that nested record also counts against your original 10-lookup budget. A record with three `include`s that each nest two more `include`s can quietly burn through the limit without your own top-level record looking long.

Can I just switch to a `~all` or remove mechanisms to dodge the limit?

Removing mechanisms changes which senders are authorized, so only remove ones for services you no longer use. Switching `-all` to `~all` doesn't address the lookup count at all — PermError happens during evaluation, before the `all` mechanism is even reached, so it doesn't help.

What's "flattening" and is it always the right fix?

Flattening replaces `include:` mechanisms with the static `ip4`/`ip6` ranges they currently resolve to, cutting lookups to zero for that entry. It works, but those IP ranges can change without notice from the provider's side, so a flattened record needs to be re-checked periodically — it trades a lookup-count problem for a maintenance one. Microsoft advises against flattening its own Microsoft 365 include, because that sending infrastructure uses IP addresses that change frequently.

Why do only some of my messages fail with PermError?

SPF evaluates terms from left to right and stops at the first match (RFC 7208 §4.6.2). Mail from a sender listed early in the record can match before the evaluation reaches the eleventh lookup, so it passes; mail from a sender listed later, or from an unlisted server, runs into the limit and gets PermError. That makes an over-limit record look like an intermittent problem.

Want AdminKit to watch this for you?

Free checks tell you the state today. Protective DNS and monitoring tell you when it changes.

Huy Nguyen (David), Founder and CEO of Netbase JSC

Talk to an expert

Huy Nguyen (David), Founder & CEO, Netbase JSC

Ask whether this fix applies to your setup, or get a second pair of eyes on your DNS and mail records.