If you manage the email infrastructure for a structured company, sooner or later you will run into the dreaded SPF PermError (Too Many DNS Lookups). This silent error causes your messages to be rejected by providers like Gmail and Outlook, destroying deliverability rates for both newsletters and transactional emails.
In this technical cornerstone guide, we will analyze why the IETF (Internet Engineering Task Force) imposed this draconian limit via RFC 7208, and how to implement the SPF Flattening technique on the server side to resolve it definitively.
1. Anatomy of RFC 7208 and the 10 Lookup Limit
Sender Policy Framework (SPF) protects your domain from spoofing by listing the IPs authorized to send emails on your behalf. But listing individual IPs (e.g. ip4:192.168.0.1) is impractical for SaaS giants (like Google Workspace or Sendgrid) that change servers monthly.
For this reason, RFC 7208 allows TXT records to use the include: or a or mx mechanism to delegate authorization to another domain's DNS.
The problem arises when a receiving MTA must extract these hidden IPs, triggering a chain reaction (DNS Recursion).
- Mechanisms that COST a lookup:
include:,a,mx,ptr,exists. - FREE mechanisms (0 lookups):
all,ip4,ip6.
Why a Strict Limit of 10?
The IETF set a hard, non-negotiable limit of 10 recursive DNS lookups to prevent Distributed Denial of Service (DDoS) attacks against DNS resolvers worldwide. If a hacker created an SPF record that called other domains indefinitely, they could crash Gmail's routing infrastructure.
2. The Snowball Effect (Nested Includes)
Disaster strikes because your vendors' include: mechanisms bring their own nested include: mechanisms.
Suppose you use a simple stack: GSuite + Mailchimp.
Your corporate record (3 Includes = Looks like 3 lookups):
v=spf1 include:_spf.google.com include:servers.mcsv.net include:sendgrid.net -all
But let's analyze what actually happens on the Mailchimp server:
servers.mcsv.net => (1 lookup)
L Calls include:spf.mandrillapp.com (1 lookup)
L Calls include:mail.mailchimpapp.com (1 lookup)
Real total just for Mailchimp: 3 to 5 Lookups.3. How SPF Flattening Works (IP Compression)
SPF Flattening is the process of server-side force-resolving every domain hidden behind the "includes", turning the entire tree of DNS dependencies into a long, static textual list of raw IPs. Since they are ip4: declarations, they have a lookup cost of zero.
- Manual Method: Extract and ping all IP blocks of Google Workspace and paste them raw into your TXT record or crontab (Not recommended, because when Google changes its IPs, you will fail spectacularly).
- Automation Method (Macro-Flattening via proxy): Use a CNAME pointing to a service (like Cloudflare, or specialized DMARC vendors) that flattens the record daily. So instead of having 12 includes, you will have a simulated construct:
include:flattenspf.yourdomain.com. When an MTA queries your domain, the proxy responds on-the-fly with the pre-compiled, cleaned IP block (costing only 1 global lookup).
4. Secondary Obstacle: The UDP Length Limit
Resolving the 10 DNS lookups limit by flattening the array using raw lists of IP subnets opens a new problem: the UDP string limit in DNS response packets (historically set at 512 bytes per packet to avoid expensive fallback to TCP).
RFC 4408 String Chunking
A single TXT record (RR) from the semantic perspective of the DNS parser cannot exceed 255 characters per single 'string'. If a flattened record is 1000 characters long, it must be fragmented (chunked) into multiple contiguous strings within the same record, enclosed in double quotes and separated by a space. E.g.: "v=spf1 ip4:..." "ip4:..." "-all"
Conclusions
Maintaining the health of the record is not a "set and forget" event. With marketing teams constantly adding new CRMs, support helpdesks, and ESPs to the corporate arsenal, an 11-lookup PermError scenario is always lurking.
You must adopt a DevOps culture where no third party is added to the corporate outbound mail infrastructure (and consequently to the DMARC shield) without first simulating how many recursive DNS queries the external provider's record will generate.
Strumenti Correlati
Bulk SPF & DNS Lookup Extractor
This advanced tool performs recursive lookup extraction (deep-unrolling) of your domain. It simulates the Mail Transfer Agent's behavior, extracting and counting all hidden subdomains to see how close you are to the dangerous 10-lookup limit.
DMARC Health Analyzer
If your SPF check fails due to Timeout or DNS Limits, your DMARC record will go into soft or hard reject depending on your P=policy. Use our DMARC analyzer to verify the syntax of your security constructs.



