"SPF PermError: too many DNS lookups" means your SPF record needs more than 10 DNS queries to evaluate, so receivers give up and treat SPF as failed for every message from your domain. The fix is to bring the count to 10 or below, usually by removing services you no longer use, dropping mechanisms that are not needed and moving some senders to their own subdomain.
Why the limit exists
Every time a receiving server checks your SPF record, it may have to make further DNS queries to resolve includes and hostnames. To stop SPF being abused to flood DNS servers, RFC 7208 caps the number of lookup-causing terms at 10 per evaluation. It also caps void lookups (queries that return no answer or a domain that does not exist) at 2. Exceed either and the result is PermError: a permanent error that the receiver treats as an SPF failure.
The painful part is that nothing tells you when you cross the line. Your record keeps "working" in the sense that it is published and looks fine, but every receiver silently stops trusting it. If you rely on SPF for DMARC alignment from any service, that service's mail starts failing DMARC.
What counts towards the 10
| Term | Counts? | Notes |
|---|---|---|
include: | Yes | 1 for the include itself, plus every lookup inside the included record |
a | Yes | 1 |
mx | Yes | 1, and each MX host then needs an address lookup (those are capped separately at 10) |
exists: | Yes | 1 |
redirect= | Yes | 1, plus the lookups in the target record |
ptr | Yes | Deprecated. Remove it. |
ip4: / ip6: | No | Free |
all | No | Free |
The fetch of your own SPF record does not count. Nested includes are where the count gets away from people. A single include: for a large provider can itself contain three or four further includes, so one line in your record might cost four or five lookups.
Step 1: audit your record
Here is a realistic record that has grown over a few years:
v=spf1 a mx include:_spf.google.com include:spf.protection.outlook.com include:sendgrid.net include:mailgun.org include:servers.mcsv.net include:_spf.oldcrm.example ptr ~all
Work through it line by line and, for each term, write down:
- What service it is for. If nobody knows, that is a strong hint it is no longer needed.
- How many lookups it costs, including nested ones. Look up the included record and count its own includes, then repeat for those.
- Whether that service actually sends mail with your domain in the envelope sender. This is the question most people skip.
A Mail Tester UK report shows the SPF result and flags a PermError when the limit is exceeded, which is the quickest way to confirm this is your problem before you start editing.
Step 2: remove what you do not need
This is the safest fix and often enough on its own.
- Cancelled services. An include for a CRM you left two years ago does nothing except cost lookups. If its domain no longer publishes SPF, it also counts as a void lookup.
- Both Google and Microsoft. Businesses that migrated from one to the other frequently still have both includes. You only need the one you actually send through.
aandmx. These are often added out of habit.mxauthorises your inbound mail servers, which for Google Workspace or Microsoft 365 are already covered by their include.aauthorises your website's server; you only need it if the website sends mail directly, and even then anip4:is cheaper.ptr. Deprecated, slow and costly. Remove it.- Platforms that use their own return-path. Many newsletter and transactional platforms send with an envelope sender on their own domain or on a custom subdomain of yours. In that case SPF is checked against that domain, not your root, and an include on your root record does nothing. Check each platform's domain authentication settings.
Applied to the example above, removing a, mx, ptr, the old CRM and a duplicate mailbox provider might leave:
v=spf1 include:spf.protection.outlook.com include:sendgrid.net include:mailgun.org ~all
Step 3: give senders their own subdomain
If you genuinely use more services than fit in one record, split them up. Each subdomain gets its own SPF record with its own budget of 10 lookups.
For example, configure your newsletter platform to use news.example.co.uk as its return-path, and your transactional platform to use mail.example.co.uk:
example.co.uk. TXT "v=spf1 include:spf.protection.outlook.com ~all" news.example.co.uk. TXT "v=spf1 include:servers.mcsv.net ~all" mail.example.co.uk. TXT "v=spf1 include:sendgrid.net ~all"
Your recipients still see hello@example.co.uk in the From line. Under DMARC's default relaxed alignment, an envelope sender on news.example.co.uk aligns with a From address on example.co.uk, so SPF still counts towards DMARC. This is the cleanest long-term fix, and it also separates the reputation of your marketing mail from your everyday mailbox.
Most platforms set this up through their "custom return-path" or "bounce domain" settings, which usually ask you to publish a CNAME on the subdomain.
Domains, DNS & emaildijitul DNSRegister and transfer .uk and .com domains, with Cloudflare DNS management and business email. SPF, DKIM and DMARC set up properly.Fix your DNS with dijitulStep 4, if you must: flattening with ip4 and ip6
Flattening replaces includes with the IP ranges they resolve to. Since ip4: and ip6: cost nothing, the lookup count drops sharply:
v=spf1 include:spf.protection.outlook.com ip4:198.51.100.0/24 ip4:203.0.113.0/25 ip6:2001:db8:1234::/48 ~all
It works, but it carries a real risk. When you flatten, you take a snapshot of the provider's addresses. Providers add and retire IP ranges regularly and do not tell you. The day they start sending from a new range, your mail from that range fails SPF, and nothing alerts you.
Flattening also makes the record long. Past 255 characters it needs splitting into multiple strings, and very long records can cause DNS responses to exceed size limits for some resolvers. Use it to shave off one or two lookups, not as the main fix.
Do not forget the void lookup limit
Even with fewer than 10 lookups, more than 2 void lookups also triggers PermError. A void lookup is any query that returns no records or a non-existent domain. The usual causes are includes for services that have since closed or changed their SPF hostname, and typos in include domains. Check that every include you keep actually resolves to a valid SPF record.
Lean on DKIM as well
Getting SPF under the limit matters, but it should not be your only line of defence. Make sure every service also signs with DKIM using your domain. DMARC passes if either SPF or DKIM passes with alignment, so aligned DKIM keeps mail flowing even if a future change pushes SPF back into PermError, and it survives forwarding where SPF does not.
Checklist
- Count lookups including nested includes: 10 or fewer.
- Count void lookups: 2 or fewer.
- Remove cancelled services,
ptr, and unneededaandmx. - Remove includes for platforms that use their own return-path.
- Move high-volume platforms to their own subdomain.
- Flatten only with automated maintenance.
- Re-test from every sending service after each change.
Frequently asked questions
What is the SPF 10 lookup limit?
RFC 7208 says evaluating an SPF record may trigger no more than 10 DNS lookups, counting include, a, mx, ptr, exists and redirect, including any nested inside included records. Going over makes SPF return PermError.
Do ip4 and ip6 count towards the SPF lookup limit?
No. ip4, ip6 and all do not need a DNS lookup, so they never count. That is why flattening replaces includes with IP addresses.
What happens to my email if SPF has a PermError?
Receivers treat SPF as failed for every message from the domain. Mail can still pass DMARC through aligned DKIM, but anything relying on SPF alone will fail and is more likely to land in spam or be rejected.
Is SPF flattening safe?
It works, but it creates a maintenance job. Providers change their IP ranges without warning, and a flattened record does not update itself, so you need an automated tool or regular checks to keep it accurate.