SPF "too many DNS lookups": why it happens and how to fix it
What the ten-lookup limit in RFC 7208 counts, how to tally your own record, and the fixes that work without silently breaking mail.
In short
SPF returns "too many DNS lookups" when evaluating a record takes more than ten DNS lookups, the cap in RFC 7208, and SPF then returns a permanent error, so it cannot pass. Every include, a, mx, exists, ptr and redirect counts, nested ones included. Remove unused includes, drop a and mx if they send nothing, or move senders to subdomains.
On this page
"SPF PermError: too many DNS lookups" is one of the most common email authentication faults, and one of the most damaging, because it fails quietly. Nothing bounces at first. Your SPF record is simply treated as broken by receivers that check it, and once you enforce DMARC, mail that was relying on SPF starts going missing.
It usually creeps up on a domain. Each new service – a helpdesk, a newsletter tool, a payment platform – asks you to add an include: to your SPF record, and one day the record crosses a limit most people never knew existed.
What the limit actually is
#RFC 7208, the SPF specification, caps the number of DNS lookups a receiver will make while evaluating one SPF record at ten. The cap exists to stop SPF being used to make receivers flood DNS servers with queries. Exceed it and the result is permerror: a permanent error, meaning the record could not be interpreted, so SPF cannot pass.
Not every part of a record counts. These terms trigger a lookup:
| Term | Counts? | Why |
|---|---|---|
include: | Yes, 1 – plus everything inside it | Fetches another domain's SPF record |
a, a: | Yes, 1 | Looks up the domain's address records |
mx, mx: | Yes, 1 | Looks up MX records (and then their addresses) |
exists: | Yes, 1 | Checks whether a constructed name exists |
ptr | Yes, 1 | Reverse lookup; deprecated – the RFC says not to publish it |
redirect= | Yes, 1 | Hands evaluation to another domain's record |
ip4:, ip6: | No | The address is in the record itself |
all | No | Matches everything |
The crucial detail is the first row. An include counts as one lookup and every lookup inside the record it points to counts too, all the way down. A single include for a large provider can cost three or four lookups on its own, and providers change their records without telling you, so a record that was within the limit last year may not be today.
There is a second, lesser-known limit, which the RFC recommends rather than requires: no more than two "void" lookups – terms that return no answer at all, typically an include for a service you cancelled whose record has since been deleted. A receiver that applies it also returns a permanent error.
Counting your own record
#Take a typical small-business record:
v=spf1 a mx include:spf.protection.outlook.com include:servers.mcsv.net
include:_spf.helpdesk.example include:sendgrid.net ~allThe top level already costs six: a, mx and four includes. Now open each include. Use our DNS Lookup tool to fetch the TXT record for each included domain, and count the lookup terms you find there, then repeat for any includes inside those. Write the tree down:
a 1
mx 1
include:spf.protection.outlook.com 1 (+ any nested includes)
include:servers.mcsv.net 1 (+ any nested includes)
include:_spf.helpdesk.example 1 (+ any nested includes)
include:sendgrid.net 1 (+ any nested includes)
--
at least 6If the nested totals take you past ten, you have found the problem. Our Email Validator reports the SPF record for a domain, and the DMARC & DKIM Checker shows whether SPF is published and whether more than one SPF record exists – a separate fault that is just as fatal.
The fixes, best first
#1. Remove what you no longer use
The cheapest lookups to save are the ones doing nothing. Records accumulate includes for trials that ended, agencies that left and platforms you migrated away from. Check each against the list of services you actually send through today. Removing a dead include also removes a likely void lookup.
2. Drop a and mx unless they send mail
Many records start with a mx because a hosting control panel put it there. That authorises your web server and your inbound mail servers to send. If your mail goes through Microsoft 365 or Google Workspace, your MX records point at their receiving servers, which the provider's include already covers, and your website probably sends through an SMTP service rather than directly. If nothing sends from those addresses, delete them: two lookups saved. If your own server does send, replace a with its fixed ip4: address, which costs nothing.
3. Check whether an include does anything for you
This is the fix most people miss. SPF is checked against the envelope sender – the Return-Path or bounce address – not the From: address your recipients see. Most bulk-mail and CRM platforms use their own bounce domain by default, so SPF is evaluated against their domain, and the include in your record is never consulted.
Look at the headers of a message the platform sent for you. If the Return-Path is on the platform's domain rather than yours, the include in your record is dead weight and can go. What makes that platform pass DMARC is DKIM signing with your domain, which you set up in the platform's domain-authentication settings. That is the better route anyway: DKIM survives forwarding and SPF does not.
4. Move senders to subdomains
Each subdomain has its own SPF record with its own budget of ten lookups. Sending marketing mail from news.example.co.uk and transactional mail from mail.example.co.uk splits the load and has a second benefit: a reputation problem on your newsletter cannot drag down delivery of your invoices. With DMARC's relaxed alignment (the default), the authenticated domain only has to share an organisational domain with the From: address, so mail sent through news.example.co.uk can still pass DMARC for a From: address on example.co.uk, because both share the organisational domain example.co.uk.
5. Flattening, with care
"Flattening" replaces includes with the IP ranges they currently resolve to, as ip4: and ip6: terms that cost no lookups. It works, but it freezes a snapshot of someone else's infrastructure into your DNS. When the provider adds a server, your record does not know, and mail from the new server fails SPF without warning. Flatten only with an automated service that re-resolves and republishes the record regularly, and never by hand for a large provider.
What not to do
#- Do not split SPF into two records. Publishing a second
v=spf1record to hold the overflow makes SPF a permanent error immediately, for every message. - Do not switch to
+all. It authorises every server on the internet and is worse than having no record. - Do not rely on
~allto hide the problem. A permanent error is not a soft fail; the qualifier onallis never reached.
Why it matters more once DMARC is enforcing
#Under DMARC, a message passes if either SPF or DKIM passes with alignment. A broken SPF record therefore removes one of your two routes to a pass. Mail that is properly DKIM-signed with your domain carries on regardless; mail that was relying on SPF alone – often a website contact form or an old line-of-business application – starts to fail the moment your policy reaches quarantine or reject. Fixing SPF, and making sure every sender also signs with DKIM, keeps that from happening.
If you are setting up a Microsoft 365 domain from scratch, our step-by-step Microsoft 365 guide covers SPF, DKIM and DMARC together.