Blog/ Deliverability & authentication

How to Fix the SPF "Too Many DNS Lookups" PermError

Nafiul HasanNafiul Hasan· 11 min read
Diagram of an SPF record crossing the RFC 7208 ten DNS-lookup limit and returning a PermError, with the four fixes to reduce SPF DNS lookups

The short answer

Your SPF record fails because RFC 7208 caps evaluation at 10 DNS-querying terms — include, a, mx, ptr, exists, and redirect — and nested includes quietly push you over, returning a PermError. Fix it by swapping includes for ip4/ip6 addresses, moving senders to subdomains, consolidating vendors, or carefully flattening stable senders.

SPF fails with a 'too many DNS lookups' PermError once your record passes RFC 7208's 10-lookup cap. How to fix SPF too many DNS lookups, cause by cause.

On this page
  1. 01What the SPF 'too many DNS lookups' error actually means
  2. 02What counts toward the SPF 10-lookup limit (does ip4 count?)
  3. 03Common causes of the SPF lookup error
  4. 04Fix 1: Replace includes with ip4 and ip6 addresses
  5. 05Fix 2: Move email services onto subdomains
  6. 06Fix 3: Consolidate the services that send as you
  7. 07Fix 4: Flatten your SPF record — carefully
  8. 08How to tell which cause you have
  9. 09Preventing it from coming back
  10. 10Does your mail client add to the SPF budget?

If your mail is bouncing or getting flagged and a checker says your SPF record has "too many DNS lookups," your record has crossed a hard limit written into the SPF standard itself. This guide covers how to fix SPF too many DNS lookups, from the one-minute diagnosis to the four durable fixes: replacing includes with IP ranges, moving senders onto subdomains, consolidating vendors, and controlled flattening.

The error is common, specific, and fixable without guesswork. The trap is that the limit has nothing to do with how long your record looks. It counts hidden DNS lookups buried inside the services you already trust, so a record with only four or five includes can quietly blow past the cap.

What the SPF 'too many DNS lookups' error actually means#

SPF (Sender Policy Framework) lets a receiving server check whether the server sending your mail is authorized to. To do that, the receiver reads your SPF TXT record and follows every include, a, and mx term it points to — each of which is a live DNS query. RFC 7208, the SPF standard, caps how much of that work a receiver has to do.

The exact rule is in RFC 7208 §4.6.4: "SPF implementations MUST limit the total number of those terms to 10 during SPF evaluation, to avoid unreasonable load on the DNS." Cross the tenth DNS-querying term and the standard requires the receiver to return a PermError — a permanent error meaning your SPF record is broken, not merely that one message failed a check.

That matters because a PermError is treated as an SPF failure. On its own it may only weaken your standing, but paired with a DMARC policy of p=reject it can get messages rejected outright, and receivers like Gmail and Outlook.com bounce or divert affected mail. So the practical symptom is unreliable delivery from a record that looks perfectly fine at a glance.

PermError is not the same as a soft SPF fail

A '-all' or '~all' failure means a sender was not on your list. A PermError means the receiver could not finish evaluating your record at all — here, because it hit the 10-lookup ceiling. Many receivers treat that as an SPF failure, and under a strict DMARC policy it can mean rejection.

What counts toward the SPF 10-lookup limit (does ip4 count?)#

The limit counts DNS-querying terms, not characters and not includes alone. Per RFC 7208 §4.6.4, the terms that cause a DNS query are the include, a, mx, ptr, and exists mechanisms, plus the redirect modifier. Each one the receiver evaluates spends one of your ten.

The terms that never query DNS do not count. The RFC is explicit that "the all, ip4, and ip6 mechanisms, and the exp modifier" do not cause DNS queries. So no — an ip4: or ip6: entry does not count toward the limit, no matter how many addresses or CIDR ranges you list. That single fact is the basis of half the fixes below.

SPF termCounts toward the 10?What to know
include:Yes — 1 eachThe usual culprit. One include can pull in nested includes that each cost another lookup.
aYes — 1Resolves the named domain's A/AAAA records.
mxYes — 1Plus a sub-limit: a single mx must not query more than 10 address records, or it PermErrors on its own.
ptrYes — 1It counts, and the standard discourages ptr entirely. Remove it.
existsYes — 1Used in macros; each evaluation is a lookup.
redirectYes — 1A modifier that hands evaluation to another record — still a lookup.
ip4: / ip6:NoIndividual addresses and CIDR ranges are free. This is why the IP-based fixes work.
allNoThe -all or ~all at the end never queries DNS.

Common causes of the SPF lookup error#

Almost every case traces to one of a few patterns. The table below maps each cause to a fast way to confirm it and the fix that follows, so you can go straight to the one you have.

Likely causeHow to confirmFix
Too many include: services stacked on one domainRun the record through an SPF checker that reports the total lookup count, not just the includes.Consolidate vendors and move some to subdomains (Fixes 2 and 3).
One include quietly nests several moreA checker that expands the tree shows a single include resolving to four or more lookups.Replace that vendor's include with its published ip4/ip6 (Fix 1), or flatten it (Fix 4).
A vendor you no longer use is still listedMatch each include to a service you actively send from today.Delete the stale include — this costs nothing and risks nothing.
A leftover ptr, or a redundant mx or aLook for a ptr term, or a/mx mechanisms that duplicate coverage an include already provides.Remove ptr; drop any a or mx you do not need.

Fix 1: Replace includes with ip4 and ip6 addresses#

The most direct fix uses the rule from the counting table: ip4 and ip6 entries are free. If a vendor publishes a stable, documented list of sending IPs, you can swap their include for those addresses and reclaim the lookups the include cost you.

Only do this for senders whose IPs actually stay put. If a vendor rotates addresses, a frozen list silently stops authorizing real mail — which is why Microsoft warns against pinning dynamic senders like Microsoft 365 (include:spf.protection.outlook.com) and says to keep those as an include.

  1. 1

    Expand the include

    Look up the vendor's own SPF record or documentation and note every ip4 and ip6 range it authorizes.

  2. 2

    Add the IPs to your record

    Replace include:vendor.example with the ip4: and ip6: values you found, keeping your -all at the end.

  3. 3

    Remove the include

    Delete the include line so you are not paying the lookup cost for both the include and the IPs.

  4. 4

    Retest

    Re-run an SPF checker and confirm the total lookup count dropped and the record still validates.

Fix 2: Move email services onto subdomains#

Every domain and subdomain gets its own separate 10-lookup budget. Moving a sending service onto a subdomain gives it a clean record of its own instead of crowding your main domain's. Microsoft recommends exactly this for services you do not directly control, such as bulk mailers.

  1. 1

    Pick a subdomain

    Choose something descriptive, such as marketing.example.com for a bulk-email service or news.example.com for a newsletter tool.

  2. 2

    Point the service at it

    Configure that service to send using the subdomain as its envelope-from domain.

  3. 3

    Give the subdomain its own SPF record

    Create a separate SPF TXT record on the subdomain containing only that service's include and a -all.

  4. 4

    Remove it from the root record

    Delete that service's include from your main domain's record. Remember: the root record does not cover subdomains, so each one needs its own.

Fix 3: Consolidate the services that send as you#

Often the cheapest fix is to send from fewer places. Every distinct sending service is at least one include, and that count creeps upward as tools get added over the years and never removed. Cutting the list back is free and permanent.

  • Audit: list every service that sends mail as your domain and match each one to an include in your record.
  • Cut: remove any service you have stopped using, along with its include.
  • Merge: where two tools do the same job, standardize on one and drop the other's include.
  • Route transactional and marketing mail through as few providers as you reasonably can.

Fix 4: Flatten your SPF record — carefully#

Flattening replaces includes with the IP addresses they currently resolve to, collapsing many DNS lookups into free ip4 and ip6 entries. It works, and it is the last resort when subdomains and consolidation still leave you over the line. The catch is that it trades a maintenance-free record for one whose upkeep you now own.

Treat it as a deliberate maintenance commitment, not a one-time edit. Weigh the trade-offs of flattening before you reach for it, because a stale flattened record fails silently — mail keeps sending, but from IPs your record no longer lists.

Flattening breaks the moment a vendor changes IPs

The addresses you freeze today are only correct today. Microsoft warns against flattening dynamic senders such as Microsoft 365, whose IPs change frequently, because a stale list quietly stops authorizing real mail. Flatten only stable, documented senders, record what you replaced and when, and recheck at least quarterly.

How to tell which cause you have#

Diagnosis takes about a minute with the right tool. Run your domain through an SPF checker that reports the total lookup count and expands the include tree, then follow the branch that matches what it shows.

If the total is 11 or higher, you are over the limit — note which includes contribute the most lookups. If one include expands into several nested ones, that vendor is your best candidate for an ip4 swap or flattening. If you see includes for services you no longer recognize, they are stale, so delete those first: it is the fix that costs nothing and risks nothing.

Decision tree for diagnosing an SPF too many DNS lookups error: check the total lookup count, then branch to deleting stale includes, swapping includes for ip4, moving senders to subdomains, or flattening
Work the free, safe fixes first — delete stale includes and remove ptr — then subdomains and consolidation, and only reach for flattening if the count is still over ten.

Preventing it from coming back#

The lookup count creeps up over time, so treat your SPF record as something you maintain, not something you set once and forget. A little discipline keeps you clear of the ceiling for good.

  • Keep a budget in mind: aim to stay at or below seven lookups so you have headroom for the next vendor.
  • Add an include only when you add a real sending service, and remove it the day you stop using that service.
  • Prefer subdomains for anything you do not directly control, so the main domain stays lean.
  • Recheck the lookup count after any change to your mail stack, and on a recurring calendar reminder.

Give yourself headroom below ten

Ten is the hard ceiling, not a target. Sitting at nine means the next tool you add breaks authentication with no warning. Aim for seven or fewer so there is room to grow without an emergency edit.

Does your mail client add to the SPF budget?#

Notice that the count climbs because each new sending service bolts another include onto your record. A mail client you read and reply in is not one of those services. AI Emaily sends through the Gmail, Outlook, or IMAP account you connect, using that provider's own authenticated infrastructure — so it never adds an include or a DNS lookup to your SPF budget, and it will not fix your DNS for you either; the four fixes above and your DNS host handle that. We build AI Emaily, and it triages and drafts on the mailbox you already send from, not a new sending domain you would have to authorize.

If you want that on the inbox you already run, AI Emaily offers a 7-day free trial on its paid plans — and the fix to your SPF record stays exactly the same either way.

Frequently asked

Nafiul Hasan

Written by

Nafiul Hasan

Nafiul Hasan is an entrepreneur and AI automation system builder with 10+ years of experience turning messy, manual workflows into reliable automated systems. He designs and ships AI enterprise solutions end-to-end — the agent logic, the data plumbing, and the product people actually use — and founded AI Emaily to give busy professionals their attention back. He writes here from the builder's seat: what works, what breaks, and how to put AI to work without giving up control.

EntrepreneurAI Automation System BuilderAI EnthusiastBuilds AI Enterprise Solutions10+ years experience
More from Nafiul
Ready when you are

Fix the record, then let AI Emaily run the inbox.

AI Emaily sends through your existing Gmail, Outlook, or IMAP account, so it never touches your SPF budget — it just triages and drafts on the mailbox you already run. Start a 7-day free trial.

  • 7-day free trial
  • Cancel anytime
  • Every provider