Flattening a record
Enter the domain
The domain whose SPF record is over, or close to, the limit. A web address or email address on it works too.
Run Flatten SPF
The tool reads the record, follows every include and redirect, and looks up the addresses behind any a and mx terms (up to ten such terms).
Compare before and after
Figures show lookups now, lookups after flattening, the number of ranges and how many records the result needs. A meter shows both counts against the limit.
Read the warnings
Terms that cannot be flattened, such as exists or macros, are kept as they are and listed. Terms that are not passes, such as -include, are left out and listed too.
Copy or export
Copy the main record, export CSV or JSON, or download zone file lines with each value split into quoted strings of 255 characters.
Example: a law firm at 11 lookups
Bracken Law (fictional) uses its own mail server, a CRM, a newsletter service and a help desk. Expanded, the record needs 11 lookups, one over the limit, so every message currently fails SPF with a permanent error.
Flattening resolves the mx term to the firm's server address, collects eight ranges (one /26 is dropped because it sits inside a /25 already listed) and keeps the help desk's exists term, which cannot be expanded. The result needs one lookup and fits in a single record.
v=spf1 mx include:_spf.crm.example include:_spf.news.example include:_spf.helpdesk.example ~all
Lookups now: 11 (over the limit of 10) Lookups flattened: 1 Ranges: 8 Records: 1
v=spf1 ip4:192.0.2.0/24 ip4:198.51.100.0/25 ip4:198.51.102.0/24 ip4:198.51.103.0/24 ip4:198.51.104.0/23 ip4:203.0.113.25 ip4:203.0.113.128/25 ip6:2001:db8:10::/48 exists:%{i}._spf.helpdesk.example ~all
Info: exists in _spf.helpdesk.example cannot be flattened and is kept as it is.When the result needs more than one record
A single TXT string is limited to 255 characters, and long SPF records are harder to manage even when split. If the flattened ranges do not fit, the tool moves them into records named _spf1.yourdomain, _spf2.yourdomain and so on, each ending in -all, and the main record includes those. Each include costs one lookup, so a result with three part records uses three lookups plus anything that had to be kept.
Publish the part records first and the main record last, so there is never a moment when the main record points at names that do not exist yet. The zone file export lists them in that spirit: the main record first for reference, then each part.
- IPv4 ranges inside a larger listed range are removed; IPv6 ranges are only de-duplicated.
- The all term from your current record is kept. If there was none, ~all is used.
- Lookups are sent to Cloudflare only in this tool.
Questions people ask
What is SPF flattening?
SPF flattening replaces include, a and mx terms with the IP addresses they resolve to, written as ip4 and ip6 ranges. Receivers do not need a DNS lookup for literal ranges, so a record that needed 11 or 15 lookups can drop to one or two. The trade-off is that you, rather than your providers, become responsible for keeping those ranges up to date.
Is SPF flattening safe?
It is safe on the day you do it, as long as you copy the result accurately. The risk comes later: when a provider adds new sending servers, your flattened record does not know about them and their mail starts to fail SPF. Re-run the flattener regularly, or keep the include for any provider that changes its ranges often.
Should I flatten or remove includes?
Remove first. Many records carry includes for tools no longer in use, or for services that could send from a subdomain with its own SPF record. Each one removed lowers the lookup count permanently with no maintenance. Flatten what remains only if you are still over the limit.
Why are some terms kept or left out?
exists terms, ptr and anything using SPF macros such as %{i} depend on the sending server's address at the time of delivery, so they cannot be turned into a fixed list and are kept as written. Terms with a qualifier other than pass, for example -include or ~a, are left out of the flattened ranges and listed in the warnings, so check whether you meant them.
Where your data goes
The domain and every name it includes are resolved through Cloudflare's public DNS over HTTPS, directly from your browser. Only domain and host names are sent, and the list of requests is shown under the result; nothing passes through Map Extract.
Checked against the tool on