Common questions about how SPF flattening works, when you need it, and how to maintain a flattened SPF record
What is SPF flattening and when do I need it?
SPF flattening is the process of recursively resolving all include: and redirect= mechanisms in an SPF record to their actual underlying IP addresses, then replacing the nested lookup chain with explicit ip4: and ip6: entries. You need SPF flattening when your domain uses multiple email service providers -- such as Google Workspace, SendGrid, Mailchimp, Salesforce, and HubSpot simultaneously -- because each include: directive adds one or more DNS lookups. RFC 7208 limits SPF evaluation to exactly 10 DNS lookups. When you exceed this limit, the receiving mail server returns a PermError status, meaning your SPF record fails validation regardless of whether the sending IP is legitimately authorised.
Why does SPF have a 10 DNS lookup limit and what happens when you exceed it?
The 10-lookup limit was established in RFC 7208 (the SPF specification) to prevent denial-of-service attacks where a malicious SPF record could trigger an unbounded chain of DNS queries against arbitrary servers, amplifying the attack and consuming server resources. When a receiving mail server evaluates your SPF record and encounters more than 10 mechanisms that require a DNS lookup (include:, a, mx, ptr, exists:, redirect=), it returns a PermError result. This PermError is treated as an SPF failure. If your DMARC policy is p=quarantine or p=reject, this means legitimate email from your domain may be sent to spam or rejected outright -- not because it came from an unauthorised server, but purely due to the lookup count.
How does SPF record flattening work technically?
SPF flattening works by performing a depth-first traversal of the include: and redirect= chain in your SPF record. Starting with your domain's root SPF record, the flattener fetches the TXT record, parses it, and for each include: mechanism, recursively fetches and parses the included domain's SPF record. This continues until all include chains are resolved or a depth limit is reached (typically 5-6 levels). At each level, any ip4: and ip6: entries are collected directly, and any a: or mx: mechanisms are resolved to their current IP addresses via additional DNS lookups. The final output is a single SPF record containing only explicit ip4: and ip6: entries plus the policy qualifier (-all, ~all, or ?all), requiring only one DNS lookup to evaluate.
What is the difference between -all, ~all, and ?all in an SPF record?
The all mechanism at the end of an SPF record defines how receiving servers should treat mail from senders not listed in the record. -all (hard fail) instructs receiving servers to reject mail that does not match any mechanism in the record -- this is the most secure option and recommended for domains where you fully control and know all sending sources. ~all (soft fail) instructs servers to mark non-matching mail as suspicious but typically still deliver it, usually with a header flag -- this is appropriate for domains that are still validating their sending sources. ?all (neutral) takes no position and effectively disables enforcement, treating all mail the same regardless of SPF result. For a flattened record where you have resolved all IPs, -all is the correct choice as you have explicitly enumerated every authorised sender.
How many IP addresses can a flattened SPF record contain?
There is no RFC-defined hard limit on the number of ip4: and ip6: entries in an SPF record, but practical limits exist due to DNS TXT record size constraints. A single DNS TXT record string is limited to 255 characters, but multiple strings can be concatenated within a single TXT record response up to a total of approximately 2048 bytes (varying by DNS server implementation). In practice, very large corporate SPF records can easily contain 100-200 IP ranges when flattened. If your flattened record approaches 2000 characters, you may need to split authorised senders across subdomains and use include: to reference those subdomains, keeping the total to two or three includes within the 10-lookup budget.
What are the downsides of SPF flattening and how do I maintain a flattened record?
The primary downside of SPF flattening is that it captures a snapshot of your email providers' IP addresses at the time of flattening. Major ESPs like Google, SendGrid, Mailchimp, and Salesforce regularly add, remove, and rotate IP addresses in their infrastructure. When they do, your flattened SPF record becomes out of date -- it may either fail to authorise legitimate mail from new IPs (causing SPF failures) or continue to authorise IPs that have been reassigned to other senders (a security risk). To maintain a flattened record, set a calendar reminder to re-run this flattening tool every 60-90 days and update your DNS TXT record with the refreshed output. Alternatively, consider a dynamic SPF flattening service that automatically monitors your includes and updates your DNS records when upstream IPs change.
How do I check how many DNS lookups my current SPF record uses?
Enter your domain in this SPF flattening tool and the Original Lookups counter in the results summary will show you the number of DNS lookups required to evaluate your current SPF record. Each include:, redirect=, a, mx, ptr, and exists: mechanism counts as one lookup. Note that ip4: and ip6: entries do not count toward the lookup limit because they specify IPs directly without requiring a DNS query. The lookup counter in this tool counts the mechanisms in your root SPF record only -- the recursive lookups required inside each include chain also count toward the limit during evaluation, which is why the actual lookup count during evaluation is often much higher than the count of mechanisms visible in your root record.
Can SPF flattening break my email deliverability?
Incorrectly applied SPF flattening can break deliverability if the flattened record is missing IP addresses that your email providers use for sending. This can happen if: the flattening tool did not fully resolve all include chains (for example, if a DNS timeout occurred during resolution), if you copy the record with errors, or if you use the flattened record as a replacement for the original but the original included mechanisms that resolve to more IPs than were captured. Before replacing your live SPF record, verify the flattened output by checking that it contains IPs from all your sending services. After publishing, send a test email through each provider and check the email headers for SPF: pass results. You can also use the SMTP tester on this site to re-validate the configuration after the DNS change propagates.
How do I publish a flattened SPF record in DNS?
To publish the flattened SPF record, log into your DNS control panel (Cloudflare, GoDaddy, Namecheap, Route 53, or your hosting provider's DNS management interface). Find the existing TXT record at your domain root (typically displayed as @ or your domain name) that starts with v=spf1. Delete or edit this record and replace the entire value with the flattened record from this tool. Do not add the flattened record as a second TXT record -- domains must have exactly one SPF record and having two TXT records starting with v=spf1 causes an SPF PermError. After saving, DNS propagation typically takes 5 minutes to a few hours depending on your TTL setting. Re-run this tool or use an SPF checker to confirm the new record is live and valid.
What is the include tree visualization in this SPF flattening tool?
The include tree tab in this tool shows the full recursive structure of your SPF record as a collapsible tree diagram. The root node shows your domain's SPF record, and each include: or redirect= mechanism expands into a child node showing the included domain, its SPF record, and how many IPs it contributes. This visualization makes it immediately clear which of your email service providers are contributing the most IP addresses and how deep the include chain goes. Domains using more than three levels of nested includes are the most common cause of lookup limit issues because the lookup count compounds at each level. The tree view is particularly useful for identifying redundant includes -- cases where two different includes from different services resolve to overlapping IP ranges that can potentially be consolidated.