SPF flattening
SPF Flattening Tool: get under the SPF lookup limit
Enter a domain to see how many of the 10 allowed DNS lookups its SPF record uses. If it’s over the limit, we show you how to flatten the SPF record just enough to get back under it.
We only read public DNS. You publish the records yourself, and nothing changes until you do.
Example result
Sample data, not a live check. Run the tool above to see your own result.
Result for
loja.example
Needs fixing
DNS lookups
Over the limit at 18 lookups. The records below bring it down to 10.
A flattened record is a snapshot
Records to publish
If there are numbered records, publish them first and wait until they appear in DNS. The record at loja.example replaces your current SPF record. Then confirm the result in the SPF Checker.
v=spf1 ip4:13.110.208.0/21 ip4:13.111.0.0/16 ip4:35.190.247.0/24 ip4:35.191.0.0/16 ip4:64.233.160.0/19 ip4:66.102.0.0/20 ip4:66.249.80.0/20 ip4:69.72.32.0/20 ip4:72.14.192.0/18 ip4:74.125.0.0/16 ip4:108.177.8.0/21 ip4:108.177.96.0/19 ip4:130.211.0.0/22 ip4:136.146.208.0/20 ip4:141.193.32.0/23 ip4:159.135.140.80/29 ip4:159.135.224.0/20 ip4:161.38.192.0/20 ip4:166.78.68.0/22 ip4:172.217.0.0/19 ip4:172.217.32.0/20 ~all
419 characters: how to enter it as 2 strings
A TXT string holds at most 255 characters, so DNS stores this record as several strings joined without spaces. Many DNS panels split long values for you: paste the record above and check that it was saved whole. Use this quoted version only where the panel or zone file expects quoted strings.
"v=spf1 ip4:13.110.208.0/21 ip4:13.111.0.0/16 ip4:35.190.247.0/24 ip4:35.191.0.0/16 ip4:64.233.160.0/19 ip4:66.102.0.0/20 ip4:66.249.80.0/20 ip4:69.72.32.0/20 ip4:72.14.192.0/18 ip4:74.125.0.0/16 ip4:108.177.8.0/21 ip4:108.177.96.0/19 ip4:130.211.0.0/22" " ip4:136.146.208.0/20 ip4:141.193.32.0/23 ip4:159.135.140.80/29 ip4:159.135.224.0/20 ip4:161.38.192.0/20 ip4:166.78.68.0/22 ip4:172.217.0.0/19 ip4:172.217.32.0/20 ~all"
v=spf1 ip4:172.217.128.0/19 ip4:173.194.0.0/16 ip4:198.61.254.0/23 ip4:209.61.151.0/24 ip4:209.85.128.0/17 ip4:216.58.192.0/19 ip4:216.239.32.0/19 ip6:2001:4860:4000::/36 ip6:2404:6800:4000::/36 ip6:2607:f8b0:4000::/36 ip6:2800:3f0:4000::/36 ip6:2a00:1450:4000::/36 ip6:2c0f:fb50:4000::/36 ~all
294 characters: how to enter it as 2 strings
A TXT string holds at most 255 characters, so DNS stores this record as several strings joined without spaces. Many DNS panels split long values for you: paste the record above and check that it was saved whole. Use this quoted version only where the panel or zone file expects quoted strings.
"v=spf1 ip4:172.217.128.0/19 ip4:173.194.0.0/16 ip4:198.61.254.0/23 ip4:209.61.151.0/24 ip4:209.85.128.0/17 ip4:216.58.192.0/19 ip4:216.239.32.0/19 ip6:2001:4860:4000::/36 ip6:2404:6800:4000::/36 ip6:2607:f8b0:4000::/36 ip6:2800:3f0:4000::/36" " ip6:2a00:1450:4000::/36 ip6:2c0f:fb50:4000::/36 ~all"
v=spf1 include:_spf1.loja.example include:_spf2.loja.example include:servers.mcsv.net include:spf.brevo.com include:sendgrid.net include:amazonses.com include:spf.mtasv.net a mx ~all
What changed
Lookups count towards the limit of 10. Whatever stays in the record keeps resolving live.
Replaced with IP ranges
- include:_spf.google.com 4 lookups 23 IP ranges
- include:_spf.salesforce.com 3 lookups 3 IP ranges
- include:mailgun.org 3 lookups 8 IP ranges
Left in the record
- include:servers.mcsv.net 1 lookup Stays live. Flattening it wasn’t needed to get under the limit.
- include:spf.brevo.com 2 lookups Stays live. Flattening it wasn’t needed to get under the limit.
- include:sendgrid.net 1 lookup Stays live. Flattening it wasn’t needed to get under the limit.
- include:amazonses.com 1 lookup Stays live. Flattening it wasn’t needed to get under the limit.
- include:spf.mtasv.net 1 lookup Stays live. Flattening it wasn’t needed to get under the limit.
- a 1 lookup Stays live. Flattening it wasn’t needed to get under the limit.
- mx 1 lookup Stays live. Flattening it wasn’t needed to get under the limit.
What to do with the result
The result lists records to publish
Save a copy of your current SPF record first.
- If the result has numbered records, add each as a new TXT record, such as
_spf1.example.com. If it has only the main record, go to step 3. - Wait until the SPF Checker finds that name. It reuses a result for 15 minutes. If the main record goes live first, its
includefinds nothing and receivers returnpermerror, a permanent error. - Replace the value of the existing TXT record at the root of example.com with the main record from the result. A second
v=spf1record also causespermerror. - After the old TTL (cache time), confirm in the SPF Checker. Send a test from each service and check it in the Email Header Analyzer.
Your flattened record needs upkeep
Replaced terms are now copies of provider IP ranges. When a provider adds a range, mail sent from it fails SPF until you update the record. Microsoft suggests reviewing flattened entries at least quarterly. It advises against flattening include:spf.protection.outlook.com, because those IPs change often. If your result replaced it, remove unused senders or move one to a subdomain, then run the tool again.
If the domain has no DMARC record yet, publish one at p=none (monitoring only) with a rua address. If it already has one, keep its policy and make sure that same record has a rua address, without adding a second record. Receivers send aggregate reports there. Each one lists sending IPs and their SPF results, so a stale range appears as SPF failures from that provider. Enforce only after reports show your legitimate mail passing.
The record is within the limit
The record uses 10 lookups or fewer, so the tool generates nothing to publish. Your includes keep following each provider’s changes, which a fixed list of IPs would not do.
At 8, 9 or 10 lookups, a provider can add a nested include and push you over. Remove senders that have stopped sending, and run this tool again before you add a service. Here the tool reports only the count. If the verdict reads Needs fixing or Works, with things to improve, the SPF Checker lists the cause, such as a broken include or a missing all.
Flattening cannot bring this record under the limit
The tool generated no records. The count stays above 10, or your providers publish too many IP ranges to list. The SPF standard requires permerror once a receiver reaches the eleventh lookup, so some senders pass and others fail.
- If terms appear under Left in the record, read why each stayed. For one we could not resolve, run the tool again after 15 minutes. Fix any term with an error.
- Remove services you have confirmed no longer send.
- Move a service to a subdomain with its own SPF record. It must use that subdomain as its envelope sender (Return-Path). Delete the old include only after the move.
The domain has no SPF record, or has several
The tool shows no lookup count, because it has no single record to work from.
With no record, receivers get the SPF result none. If the findings also report timed-out lookups, wait 15 minutes and run the tool again before you touch DNS. Otherwise, build one record with the SPF Generator. Start with ~all, since -all can get mail from a forgotten service refused.
With two or more, receivers return permerror. Merge every term into one line that starts with v=spf1 and ends with a single all. Delete the other records in the same DNS change. Then run this tool again.
Explained
What SPF flattening does
SPF flattening replaces include, a and mx mechanisms with the ip4 and ip6 ranges they resolve to. IP mechanisms need no DNS query, so the record uses fewer lookups. The trade-off is that the ranges no longer follow your providers: whatever they publish next is missing from your record until you update it.
The SPF lookup limit
RFC 7208 §4.6.4 limits an SPF evaluation to 10 terms that cause DNS queries: include, a, mx, ptr, exists and the redirect modifier, including the ones nested inside your providers’ records. ip4, ip6 and all don’t count. Over the limit, the result is permerror.
How to flatten an SPF record safely
- Flatten only what you need to get under the limit, starting with the provider that costs the most lookups.
- Keep your original
allqualifier. Flattening is no reason to change~allto-all. - If the ranges don’t fit in one record, split them into numbered records under your domain. Each one costs one lookup, so count them.
- Keep each TXT string to 255 characters and each answer under 450 bytes, as RFC 7208 §3.3 and §3.4 describe.
- Run the check again regularly: a flattened record doesn’t update itself when a provider changes its IPs.
Frequently asked questions
What is SPF flattening?
include, a and mx mechanisms of an SPF record with the ip4 and ip6 ranges they resolve to. IP mechanisms cost no DNS lookups, so the record evaluates with fewer queries.What is the SPF lookup limit?
include, a, mx, ptr, exists and redirect, counting the nested ones. Going over the limit produces a permerror.Is SPF flattening safe?
Which mechanisms can’t be flattened?
exists and ptr depend on each message or on live DNS, so they have no fixed list of IPs. They stay in the record, along with any include whose own record uses them, and the result says why.What if the flattened record is too long?
_spf1.yourcompany.com, and include them from the main record. Each one costs one lookup and we count it in the result. The numbered records stay under the 450 bytes RFC 7208 §3.4 suggests, in TXT strings of at most 255 characters. The main record keeps everything that can’t be flattened, so it can pass that size. When it does, the result says so, and DNS can still deliver it over TCP or EDNS.Does flattening change my ~all or -all?
~all into -all.Keep it healthy
Know the moment something breaks
Point your DMARC reports to DMARC Pulse and see who sends email as your domain, what fails and why — with a calm alert when anything changes.
Free plan: 1 domain, no credit card.
Related tools