Glossary
SPF Flattening
Reduces SPF DNS lookup count by resolving includes into IP addresses
SPF flattening is a technique that replaces DNS-querying SPF mechanisms such as "include:" and "a" with their resolved IP addresses, reducing the number of DNS lookups required to evaluate an SPF record and keeping it under the RFC 7208 limit of ten lookups.
What is SPF Flattening?
SPF flattening is a practice used to solve the SPF 10-lookup problem. The SPF specification (RFC 7208) limits SPF record evaluation to a maximum of ten DNS lookups. Every "include:", "a", "mx", "ptr", and "exists" mechanism in an SPF record consumes one lookup toward this limit. Many organisations that use multiple email services — such as Google Workspace, Salesforce, Mailchimp, Zendesk, and others — quickly exceed this limit.
When the 10-lookup limit is exceeded, the SPF evaluation returns a "PermError" result rather than a Pass or Fail. Many receiving mail servers treat PermError as a fail, meaning legitimate email can be rejected or marked as spam. SPF flattening resolves this by replacing the include mechanisms with the actual IP addresses they resolve to, eliminating the need for additional DNS lookups during evaluation.
Flattening effectively converts a record with many dynamic includes into a compact list of "ip4:" and "ip6:" ranges that require zero DNS lookups to evaluate.
How Does SPF Flattening Work?
The flattening process begins by recursively resolving all "include:" mechanisms in an SPF record. For each included domain, its SPF record is fetched and any further includes are resolved in turn, until all mechanisms have been traced back to raw IP addresses. The result is a comprehensive list of all IPv4 and IPv6 CIDR ranges that are authorised to send mail for the original domain.
These IP addresses are then written directly into the flattened SPF record as "ip4:" and "ip6:" entries, replacing the original include mechanisms. Because IP address mechanisms do not trigger DNS lookups during evaluation, the flattened record can authorise dozens of sending services while staying within the 10-lookup limit — or even using zero lookups at all.
The key challenge with flattening is maintenance. Email service providers change their IP addresses over time, and a flattened record that is not kept up to date will become inaccurate, potentially causing legitimate mail to fail SPF. Automated flattening tools and services monitor upstream changes and regenerate the flattened record when IP ranges change.
How to Flatten Your SPF Record
You can analyse your current SPF record's lookup count and generate a flattened version using the SPF Flattening Tool at nslookup.net/tools/spf-flattening-tool. Enter your domain and the tool will recursively resolve all includes, count the DNS lookups consumed, list all resolved IP ranges, and produce a flattened SPF record ready to publish in DNS.
Before replacing your existing SPF record, review the generated list of IP ranges to confirm it matches your expected sending infrastructure. After publishing the flattened record, use the SPF Checker to confirm the lookup count is now within limits.
Related Tool
SPF Flattening Tool