SPF permerror: too many DNS lookups, and how to get back to 10 or fewer
An SPF record gets 10 DNS lookups. The receiver reaches the eleventh, stops, and returns permerror [1]. DMARC only counts an SPF result of pass [2], and Gmail and Outlook.com expect bulk mail to pass SPF [6][7].
The record can look fine for months. Receivers count lookups while they evaluate, left to right, and stop at the first match [1]. Mail from the services near the start of the record passes. Mail from the services near the end fails.
The short answer
permerror with too many DNS lookups means a receiver needed more than 10 DNS-querying terms to evaluate your SPF record. The terms include, a, mx, ptr, exists and redirect each cost one, and so does each of them inside the records you include [1]. Remove includes you no longer use, then move bulk senders to their own Return-Path subdomain.
What the error looks like
You will see it in one of these forms, depending on where you look.
In the headers of a delivered message, written by the receiving server in the Authentication-Results format of RFC 8601 [3]:
Authentication-Results: mx.example.net;
spf=permerror smtp.mailfrom=example.com
From the Python SPF library pyspf, whose source builds the message from 'SPF Permanent Error: ' and 'Too many DNS lookups' [18]:
From Gmail, when you send in bulk and your mail fails SPF [6]:
RFC 7208 tells receivers that reject a message for a permerror during the SMTP session to use reply code 550 with enhanced status code 5.5.2 [1].
What counts toward the 10 DNS lookups?
| Term | Costs a lookup? | Notes |
|---|---|---|
include: |
Yes, 1 | Plus every lookup inside the included record, all the way down. |
a, mx |
Yes, 1 each | mx has a second limit: it may look up addresses for at most 10 mail servers, or it returns permerror. |
ptr |
Yes, 1 | RFC 7208 says this mechanism SHOULD NOT be published. |
exists: |
Yes, 1 | Often written with macros, like exists:%{i}._spf.example.net. |
redirect= |
Yes, 1 | Plus the lookups in the record it points to. |
ip4:, ip6:, all |
No | Free. |
exp= |
No | Looked up only after a fail, outside the limit. |
Source: RFC 7208, section 4.6.4 [1].
A second limit sits next to the first one. When a term queries DNS and gets no answer at all (an empty answer or NXDOMAIN), that is a void lookup. RFC 7208 says receivers SHOULD allow only two, and going over also produces permerror [1]. a: and mx: terms that name hosts you deleted use up this limit.
Why it fails for some mail and passes for the rest
Receivers that follow RFC 7208 count lookups during evaluation [1]. Evaluation runs left to right and stops at the first mechanism that matches [1]. If a message comes from an IP listed in your first include, the receiver never reaches lookup 11, and SPF passes. Microsoft describes the same behavior for Microsoft 365 [17].
With one record of 14 lookups, a message from an IP in the first include passes, and a message from an IP in the last include gets permerror. That is why the symptom often reads “invoices from the billing tool fail SPF, and normal mail is fine”. The billing tool’s include sits at the end of the record.
How to count your SPF lookups
You need the record and every record behind it. On macOS or Linux, dig does it:
dig +short TXT example.com | grep spf1
Take every include: and redirect= target from the answer and query it the same way. Keep going until you reach records with only ip4, ip6 and all. Add 1 for each include, a, mx, ptr, exists and redirect you met on the way.
On Windows, nslookup -type=TXT example.com returns the same TXT records.
A worked example. A company moved from Microsoft 365 to Google Workspace and added senders over time:
example.com. TXT "v=spf1 a mx include:_spf.google.com include:spf.protection.outlook.com include:sendgrid.net include:mailgun.org include:_spf.salesforce.com include:amazonses.com ~all"
| Term | Lookups |
|---|---|
a |
1 |
mx |
1 |
include: |
1 |
include: |
1 |
include: |
2 |
include: |
5 |
include: |
2 |
include: |
1 |
| Total | 14 |
Four over the limit. Mail from an IP that only matches after the tenth lookup gets permerror. So does mail that matches nothing at all, which means a forged message gets permerror instead of the fail or softfail your all asks for.
What common includes cost today
These totals come from querying each provider’s published SPF record with dig on 18 November 2026 [19]. Providers change their records without notice, so treat this as a snapshot and count your own.
| Include | Documented by | Lookups it costs |
|---|---|---|
_ (Google Workspace) |
Google [12] | 1 |
spf. (Microsoft 365) |
Microsoft [17] | 1 |
amazonses. (Amazon SES) |
Amazon [8] | 1 |
spf. (Postmark) |
Postmark [10] | 1 |
spf. (Fastmail) |
Fastmail [13] | 1 |
mail. (Zendesk) |
Zendesk [16] | 1 |
_ (Cloudflare Email Routing) |
Cloudflare [15] | 1 |
sendgrid. (SendGrid) |
SendGrid [11] | 2 |
_ (Salesforce) |
Google’s list of common senders [12] | 2 |
mailgun. (Mailgun) |
Mailgun [14] | 5 |
Mailgun’s mailgun.org is the one to watch: it nests four more includes [19]. Salesforce’s record relies on an exists: macro [19], which matters if you plan to flatten (see below).
Fix it, cheapest step first
1. Delete includes for services you stopped using
In the example, the company left Microsoft 365. include:spf.protection.outlook.com authorizes Microsoft’s servers to send as example.com and does nothing else. Remove it.
Old includes can break SPF on their own. If the former provider stops publishing SPF at that name, RFC 7208 turns the include into permerror, even with fewer than 10 lookups [1].
2. Remove a and mx unless those hosts send mail
a authorizes the address example.com resolves to: your website, or the CDN in front of it. mx authorizes the addresses of your inbound mail servers. Hosted mailbox providers document an include for outgoing mail, such as include:_spf.google.com for Google Workspace [12] or include:spf.messagingengine.com for Fastmail [13], and those two setup guides do not ask for mx. If a server you run sends mail, list its address with ip4: or ip6:, which costs nothing [1].
3. Move bulk senders to their own Return-Path subdomain
SPF checks the domain in the envelope sender (MAIL FROM) [1], which the delivered message shows as Return-Path [20]. The visible From address is DMARC’s job [2]. Amazon SES, Postmark and SendGrid let you put that envelope sender on a subdomain of yours [8][9][11]. SPF for that mail is then checked on the subdomain’s own record, with its own budget of 10 lookups, and your root record no longer needs the vendor’s include.
Some of those includes never helped in the root record. Amazon SES sends from a subdomain of amazonses.com by default, and SPF passes there [8]. SendGrid documents include:sendgrid.net on its own em subdomain [11]. In both cases the include in your root record only spends lookups.
DMARC still passes on SPF, because its default relaxed alignment accepts bounce.example.com for a From address at example.com [2].
How three of the larger services do it:
- Amazon SES: a custom MAIL FROM domain. You publish an MX record (
10 feedback-smtp.<region>.amazonses.com) and a TXT record (v=spf1 include:amazonses.com ~all) on a subdomain such asbounce.example.com[8]. - Postmark: a custom Return-Path. You add a CNAME from
pm-bounces.example.comtopm.mtasv.net[9]. - SendGrid: with automated security on, SendGrid gives you an
emsubdomain CNAME to add, and that CNAME carries SPF for its mail. You can also choose your own return-path name [11].
After steps 1 to 3 in the example (Microsoft 365 removed, a and mx removed, SES and SendGrid moved to subdomains):
example.com. TXT "v=spf1 include:_spf.google.com include:_spf.salesforce.com include:mailgun.org ~all"
bounce.example.com. MX 10 feedback-smtp.eu-west-1.amazonses.com.
bounce.example.com. TXT "v=spf1 include:amazonses.com ~all"
em1234.example.com. CNAME u1234567.wl123.sendgrid.net.
Root record: 1 + 2 + 5 = 8 lookups, with room for two more. The SendGrid CNAME name and target here are placeholders in the shape SendGrid documents: copy the exact ones from your SendGrid dashboard [11].
4. Replace includes with addresses only for servers you control
If a server you run sends mail from a fixed address, ip4:203.0.113.25 costs nothing and never changes behind your back. Do this for your own servers. For a provider’s servers, prefer step 3.
5. Flatten, as a last resort
Flattening means replacing an include: with the IP ranges it resolves to today. It brings the count down at once, and it comes with three costs:
- Your copy goes stale. When the provider adds an IP range, your flattened record does not change, and mail from the new range fails SPF. Someone or something has to flatten again on a schedule.
- Some records cannot be flattened. Salesforce’s record relies on
exists:%{i}._spf.mta.salesforce.com[19]. The%{i}macro is the connecting IP address, so the answer changes with each sending server, and DNS cannot expand it into a list of ranges [1]. - The record grows. A single TXT string holds at most 255 characters, so long records are split into several quoted strings [1]. RFC 7208 also asks you to keep the whole SPF answer small enough to fit in 512 bytes [1].
Automated flattening services take on the first cost, and from then on a third party decides which IP addresses your SPF record authorizes. Try step 3 first.
Mistakes to avoid
- Adding a second SPF record to make room. Two TXT records starting with
v=spf1on the same name are a permerror by themselves [1]. See two SPF records on one domain. - Counting only the includes you can see.
mailgun.orglooks like one lookup and costs five [19]. - Keeping includes for vendors that use their own Return-Path. Postmark says that adding
include:spf.mtasv.netto your root record “will do nothing for you” once its custom Return-Path is in place [10]. The include still costs a lookup. - Using
ptr. It costs lookups, depends on reverse DNS you may not control, and RFC 7208 says not to publish it [1]. - Leaving dead targets. A dead
include:breaks SPF on its own (step 1). A deada:ormx:target is a void lookup, and the third void lookup is a permerror [1].
Does it matter if DKIM passes?
For DMARC, one aligned pass is enough. A message with a valid DKIM signature from example.com passes DMARC even while SPF returns permerror [2]. If DMARC on your domain still sits at p=none, moving from p=none to p=reject is the next step after this fix.
Mailbox providers ask for more. Gmail requires bulk senders, those that send close to 5,000 messages or more to personal Gmail accounts in 24 hours, to set up both SPF and DKIM [4][5], and rate-limits or blocks bulk mail that fails SPF with the 4.7.27 and 5.7.27 codes above [6]. Outlook.com requires SPF and DKIM to pass for domains that send 5,000 or more messages to its consumer services, and rejects mail that falls short [7]:
Fix the record even if DKIM covers you today. If you changed mail providers, old DKIM selectors can linger too: see remove old DKIM records. More SPF problems are on the SPF record page.
Check your SPF lookups now
The SPF checker walks your SPF record and every include in your browser, counts DNS lookups and void lookups, and shows which term crosses the limit.
Runs in your browser. Your domain is not sent to this site or stored.
See it on a test domain
Check these names under badmail.dev to see this in a result, without checking your own domain.
spf-11-lookups.badmail.dev: check it or see its records
Related guides
Two SPF records on one domain: why both stop working, and how to merge them
Two SPF records on one domain make SPF fail for both providers. Receivers return permerror. Find the duplicate and merge them into one valid TXT record.
From DMARC p=none to p=reject without blocking your own mail
Move DMARC from p=none to quarantine and then reject without losing real mail. What to fix first, how long to wait, and how t=y, pct and subdomains behave.
DKIM records still pointing at your old provider: what to keep and what to remove
Old DKIM keys keep validating mail signed for your domain. Find the selectors an old provider left, remove or revoke them safely, and fix dangling CNAMEs.
