Your marketing team adds a newsletter platform, finance connects an invoicing service, support moves to a new help desk, and each of them asks you to "add our include to your SPF record". One day a DMARC report or a bounce message says spf=permerror, and mail that used to land in inboxes starts going to spam. Nothing is wrong with any single include. The record as a whole has simply become too expensive to evaluate.
This guide explains how SPF lookups are counted, why the limit of 10 exists, how to see exactly where your lookups go, and the realistic options for getting back under the limit without breaking legitimate senders.
How SPF evaluation works
SPF (Sender Policy Framework, RFC 7208) is a single TXT record on your domain that starts with v=spf1. When a receiving server gets a message, it takes the domain from the envelope sender (the Return-Path, not the visible From address), fetches that domain's SPF record and checks the connecting IP address against the mechanisms in it, left to right.
Some mechanisms are free because the answer is right there in the record. Others force the receiver to make another DNS query:
| Term | Costs a DNS lookup? | What it does |
|---|---|---|
ip4:, ip6: |
No | Matches an address or CIDR range written in the record |
all |
No | Matches everything; the qualifier decides the result |
include: |
Yes | Evaluates another domain's SPF record |
a, mx |
Yes | Matches the domain's A/AAAA or MX hosts |
exists: |
Yes | Matches if a (usually macro-built) name resolves |
redirect= |
Yes | Replaces this record with another domain's |
ptr |
Yes | Reverse DNS match; deprecated, avoid it |
The limit is 10 lookup-causing terms in total, counted across the whole tree. If include:_spf.example-mailer.com itself contains three more includes, that one line costs four. RFC 7208 also limits void lookups (queries that return no record or NXDOMAIN) to two, which catches includes pointing at services you cancelled long ago.
When a receiver hits either limit, it stops and returns PermError. Under DMARC, a PermError counts as an SPF fail, so every message relying on SPF alignment loses that pass.
Check your record and count lookups
The SPF Record Checker fetches the record from Cloudflare DNS and expands every include and redirect for you.
- Open the SPF Record Checker and type your domain, for example
example.com. - Click Check SPF.
- Read the badge next to the domain: SPF valid, Valid with warnings or SPF problems.
- Look at the four tiles. DNS lookups shows the total against 10, Void lookups against 2, plus the number of IPv4 and IPv6 ranges the record authorises.
- Read the findings list. It flags lookups over the limit, multiple SPF records,
+all,ptr, missingall, loops and unparseable terms. - Open the Include tree section and click each record. Terms that cost a lookup are highlighted, so you can see which branch is the most expensive.
If the checker shows 8 or 9 lookups, it warns you even though the record still passes, because the next vendor you add will tip it over.
Ways to get back under 10 lookups
Work through these in order. The first ones are cheap and safe; the last ones need ongoing maintenance.
1. Remove services you no longer use
Every organisation accumulates dead includes. Compare the include tree with the list of tools that actually send mail today. A good source of truth is your DMARC aggregate reports, which show which IPs send as your domain and whether they pass. If a service has not appeared in reports for months, remove it.
2. Drop a, mx and ptr unless they send mail
Many templates ship with v=spf1 a mx include:... ~all. If your web server and inbound MX hosts never send outbound mail as your domain, a and mx cost two lookups for nothing. ptr is deprecated and slow; remove it in all cases.
3. Move senders to subdomains
SPF is checked against the envelope sender domain, which you can often change per service. Send newsletters from news.example.com and transactional mail from mail.example.com, each with its own SPF record. Your root record then only needs the office mail provider. This is the cleanest long-term fix, and it also isolates the reputation of bulk mail from your staff mailboxes.
4. Replace an include with ip4/ip6 ranges
If a small vendor sends from a fixed, documented set of IP addresses, you can list them with ip4: and ip6: instead of including their record. Only do this when the provider publishes the ranges and commits to announcing changes.
5. Flatten, carefully
"Flattening" resolves every include into its current IP ranges and publishes those directly. It fixes the count instantly but freezes a snapshot. Large providers change their sending ranges without notice, and a stale flattened record silently fails legitimate mail. If you flatten, automate it: a scheduled job or a managed SPF service should regenerate the record regularly. Never flatten by hand and forget about it.
Other ways to inspect SPF
The command line shows the raw record, but it will not expand the tree or count anything:
dig +short TXT example.com
nslookup -type=txt example.com
On Windows PowerShell, Resolve-DnsName example.com -Type TXT does the same. To count by hand, repeat the query for every include, then every include inside those, and keep a tally. It is doable for a small record and error-prone for a large one, which is why an expanding checker is worth using. If you want to see all TXT records on the domain, not just SPF, use the TXT Record Lookup.
Other common SPF mistakes
Two SPF records
A domain may publish only one v=spf1 record. Two records, often one from an old host and one from a new provider, cause PermError. Merge them into one record with all the mechanisms.
+all or ?all
+all authorises every server on the internet and defeats the purpose of SPF. ?all gives a Neutral result and no protection. End the record with ~all (soft fail) while you verify senders, or -all once you are confident. With a DMARC policy in place, ~all is widely used and safe.
Mechanisms after all
Anything written after all is never evaluated. If you added include: at the end of the line, move it before ~all.
Records near the size limit
Very long records can exceed what fits in a single UDP DNS response. The checker warns above 450 characters. Subdomains and removing dead entries fix this better than squeezing whitespace.
After you fix SPF
SPF alone does not stop someone forging your visible From address, because it checks the envelope domain. Pair it with DKIM signatures, checked with the DKIM Checker, and a DMARC policy, checked with the DMARC Checker. DMARC passes when either SPF or DKIM passes and aligns with the From domain, so a strong DKIM setup also protects you on the day an SPF include breaks. The MX Lookup is useful for confirming which provider handles your inbound mail, which is often the same one that needs to be in SPF.
Frequently asked questions
Which SPF terms count toward the 10-lookup limit?
include, a, mx, ptr, exists and the redirect modifier each count as one, including every one nested inside included records. ip4, ip6 and all do not count.
Is it safe to go over 10 lookups if most receivers seem fine?
No. The limit is part of the standard, and receivers that enforce it return PermError. You may not notice until a large mailbox provider starts failing your mail, so treat 10 as a hard ceiling.
Should I use ~all or -all?
Both are valid. ~all marks unlisted senders as suspicious and lets DMARC decide the outcome, which is forgiving while you discover all your senders. -all asks receivers to reject them outright once your list is complete.
Does flattening SPF have downsides?
Yes. A flattened record is a snapshot of the provider's IP ranges at one moment. When the provider adds new ranges, your mail from those addresses fails SPF until you regenerate the record, so flattening must be automated and monitored.
How long until an SPF change takes effect?
Receivers cache the old TXT record for up to its TTL. Check the TTL in a DNS lookup; once that time has passed after your edit, new messages are evaluated against the new record.