What is SPF flattening?
SPF flattening means replacing include: mechanisms in an SPF record with the ip4: and ip6: addresses those includes resolve to. Address terms cost no DNS lookups, so flattening keeps a record under the 10-lookup limit of RFC 7208. The price is maintenance: when a provider changes its addresses, a flattened record goes stale without warning.
Microsoft describes it the same way in its SPF setup guide: "the practice of replacing include: mechanisms with the resolved IP addresses to reduce DNS lookups." This article covers when to flatten, what can go wrong, the alternatives and portfolio operations. For SPF basics, see the SPF guide.
Key takeaways
- Flattening trades DNS lookups for maintenance. It fixes the 10-lookup limit but creates a record that does not follow provider changes on its own.
- Never flatten Microsoft 365 or Google Workspace. Both say their sending addresses change often, and Microsoft names
include:spf.protection.outlook.comas something you should not flatten. - Try the alternatives first, in this order: remove unused includes, move senders to subdomains, rely on aligned DKIM for DMARC, and only then consider macros or flattening.
- A flattened record must stay inside DNS size limits: 255 octets per TXT string and, ideally, a response under 512 octets.
- If you flatten, document every replaced include, re-check it on a schedule and watch DMARC aggregate reports for SPF failures from known senders.
Why does the 10-lookup limit make flattening necessary?
Because every include: costs at least one DNS lookup, and nested includes cost more. RFC 7208 Section 4.6.4 says receivers "MUST limit the total number of those terms to 10". Exceeding it returns permerror, which means SPF passes for no sender on the domain.
The terms that count are include, a, mx, ptr, exists and the redirect modifier. The terms that do not count are all, ip4, ip6 and exp. Flattening exploits exactly that difference: it moves authorised senders from the first group into the second.
Microsoft warns that "having fewer than 10 include: statements doesn't guarantee fewer than 10 DNS lookups." The counting method and the effect of a permerror are covered in SPF too many DNS lookups and SPF permerror: what it means and how to fix it.
What does a flattened SPF record look like?
A flattened record keeps the includes you cannot safely replace and swaps the rest for address ranges. The example below uses a fictional client and documentation addresses (RFC 5737 and RFC 3849 ranges), not real provider data, to show the mechanics.
Before flattening
The client uses Microsoft 365, a CRM, a billing platform and a helpdesk tool, all sending with the client's domain in the envelope sender:
example.com. TXT "v=spf1 include:spf.protection.outlook.com include:_spf.crm.example.net include:spf.billing.example.org include:mail.helpdesk.example.com -all"
Suppose the CRM include nests three further includes, the billing include nests two and the helpdesk include nests two. Together with Microsoft 365, the check now needs more than 10 lookups and returns permerror.
After flattening
The billing platform and the helpdesk vendor both publish a stable, documented list of sending ranges. Those two includes are replaced with the addresses they resolve to. Microsoft 365 and the CRM stay as includes:
example.com. TXT "v=spf1 include:spf.protection.outlook.com include:_spf.crm.example.net ip4:192.0.2.0/25 ip4:198.51.100.16/28 ip4:203.0.113.0/24 ip6:2001:db8:10::/48 -all"
The billing and helpdesk entries now cost zero lookups. This partial flattening is what most MSPs should aim for: replace only what is stable and documented, and keep dynamic infrastructure behind an include.
How do you verify the flattened record?
Resolve every replaced include and compare it with what you published, term by term. Then send a test message from each sender and check for spf=pass in the Authentication-Results header.
# What the vendor publishes today
dig +short TXT spf.billing.example.org
# What you published
dig +short TXT example.com | grep -i "v=spf1"
Resolve nested includes too; how to check your SPF record covers the commands.
What are the risks of SPF flattening?
The main risk is silent breakage. A flattened record is a snapshot of a provider's addresses on the day you copied them. When the provider adds a range, mail from the new range fails SPF, and nothing in your DNS changes to warn you. Size limits and record ownership are the other risks.
Why do provider IP changes break SPF silently?
An include: is resolved at check time, so it follows the provider automatically. An ip4: term is fixed. If the provider starts sending from a range you did not copy, those messages get fail or softfail from receivers, and the first sign is usually a DMARC failure or a user complaint.
Big platforms are explicit that this happens. Microsoft says its "sending infrastructure uses dynamic IP addresses that change frequently" and lists Microsoft 365 under "When you shouldn't flatten". Google's page on IP address ranges for outbound mail servers says its mail servers "have a large range of IP addresses, and the addresses change often". Google's Set up SPF article gives the value to publish as v=spf1 include:_spf.google.com ~all.
The reverse also happens: a retired range that is later reassigned stays authorised in a stale record.
How long can a flattened SPF record be?
A single DNS character-string holds at most 255 octets, so a long record has to be split into several quoted strings inside one TXT record. RFC 7208 Section 3.3 says those strings "MUST be treated as if those strings are concatenated together without adding spaces."
That last part catches people out. The space between terms has to sit inside one of the strings, or two terms merge into one invalid term:
; Correct: the space before ip4 is inside the second string
example.com. TXT ( "v=spf1 include:spf.protection.outlook.com ip4:192.0.2.0/25"
" ip4:198.51.100.16/28 ip6:2001:db8:10::/48 -all" )
Total size matters too. Section 3.4 says the record "SHOULD remain small enough that the results of a query for it will fit within 512 octets", and gives a rule of thumb: if the DNS name plus the text of all TXT records at that name stays "under 450 octets, then DNS answers ought to fit in UDP packets."
An ip4: term with a prefix is around 20 characters, so a fully flattened large provider passes 450 octets quickly. Automated flatteners often split the result into sub-records (such as _spf1.example.com) and include those, at one lookup each: fewer lookups, but a record nobody can read at a glance.
What else goes wrong?
Three operational problems are common: syntax errors, lost history and over-authorising. All three come from editing addresses by hand without a record of where they came from.
- Syntax errors during manual edits. A missing prefix length, a hostname in
ip4:or a lost space between strings returnspermerror. The SPF syntax reference lists the valid forms. - Lost history. Six months later, nobody remembers which addresses belong to which vendor, so dead ranges never get removed.
- Over-authorising. Copying broad shared ranges authorises every customer of that provider, not only your client.
What should you try before flattening?
Try four alternatives first, in this order: remove includes nobody uses, move third-party senders to subdomains, rely on aligned DKIM for DMARC, and, rarely, use macros. Each reduces lookups without creating an address list you must maintain. Flatten only what is left after these steps.
1. Remove includes nobody uses
Old records collect includes for services the client cancelled years ago. Check DMARC aggregate reports for the last 30 days: a vendor that never appears as a source on the domain is a candidate for removal. The full cleanup is in the lookup limit guide.
Also check whether the vendor uses the client's domain in the envelope sender at all. Many sending platforms use their own bounce domain in MAIL FROM, which means SPF is checked against their domain, not the client's. An include for such a sender on the client's apex never authorises anything.
2. Move senders to subdomains
Each domain name has its own SPF record and its own 10-lookup budget. Microsoft recommends this directly: "Move non-Microsoft email services to subdomains. For example, use marketing.contoso.com for marketing email with its own SPF record. Each subdomain has its own 10 lookup budget." For bulk senders it also says a subdomain protects the reputation of mail from the main domain.
With relaxed alignment, an SPF pass for bounce.mail.example.com still aligns with a From: address at example.com. See subdomain or separate domain for bulk email and DMARC alignment explained.
3. Rely on DKIM alignment for DMARC
DMARC does not need SPF to pass. RFC 9989 Section 5.3.5 says a message passes "If one or more of the Authenticated Identifiers align with the Author Domain". One aligned DKIM signature is enough.
So if a sender signs with the client's domain using a custom DKIM key, its SPF include adds little for DMARC. Move its envelope to a bounce subdomain and take the include off the apex, after confirming in aggregate reports that its DKIM passes and aligns.
4. Use SPF macros, cautiously
The exists mechanism with macros (for example exists:%{i}._spf.example.com) can authorise many addresses with one lookup, because a DNS server you run answers per connecting IP. It is powerful but rarely the right choice for an MSP. RFC 7208 Section 7 warns that some macros "severely limit the ability of implementations to cache results", and says sending domains should avoid the s, l, o and h macros. It also says the p macro "SHOULD NOT be published". You also need DNS infrastructure that can answer those queries reliably.
Automated flattening or manual flattening?
Manual flattening suits a few stable vendors on a small number of domains. Automated flattening suits larger portfolios or vendors that change ranges often, but it adds a dependency on the service that rewrites the client's DNS. Either way, Microsoft's advice applies: document, monitor and review regularly.
| Aspect | Manual flattening | Automated flattening service |
|---|---|---|
| How it works | An engineer resolves includes and edits the record | A service resolves includes on a schedule and republishes |
| Reaction to provider changes | Only at the next review | Usually within the service's check interval |
| DNS control | Stays with the MSP | Often requires DNS delegation, API access or including the service's own hostname |
| Failure mode | Stale addresses | Service outage or misconfiguration affects every client using it |
| Audit trail | Whatever you write in the change note | Depends on the service's change log |
| Best for | Two or three stable vendors | Many domains, frequently changing vendors |
Microsoft suggests evaluating flattening services "if manual maintenance is impractical". If you choose one, check how it handles includes it cannot resolve, whether it alerts you to changes, and how you return to the original includes if you leave.
When should an MSP flatten an SPF record?
Flatten when a domain is over the 10-lookup limit, the alternatives above are exhausted, and the remaining senders publish stable, documented ranges. Do not flatten dynamic platforms, and do not flatten to avoid a cleanup you should do anyway. The table gives a quick decision per sender.
| Situation | Recommendation |
|---|---|
| Microsoft 365 or Google Workspace | Keep the include. Never flatten |
| Vendor no longer appears in aggregate reports | Remove the include |
Vendor uses its own domain in MAIL FROM |
Remove the include from the apex; rely on DKIM alignment |
| Vendor signs with an aligned custom DKIM key | Move its envelope to a subdomain or remove the include |
| Bulk or marketing platform | Move to a subdomain with its own SPF record |
| On-premises server or a fixed relay you control | Use ip4:/ip6: directly; nothing to flatten |
| Vendor with a stable, documented range list | Flatten if still over budget, with a review date |
| Vendor with undocumented or frequently changing ranges | Do not flatten; use a subdomain or DKIM instead |
How should MSPs run flattened records across a portfolio?
Treat every flattened record as a configuration item with an owner, a source list and a review date. The record in DNS is the output; the list of original includes is the source of truth. Monitoring should catch a stale range before a client moves from p=none to p=quarantine or p=reject.
What should the change note contain?
Microsoft's checklist for flattened records is to "Document which include: entries you replaced and when", monitor vendor documentation, "Review and update the flattened entries at least quarterly" and test SPF after each change. A practical change note per client domain records:
- The original record, before flattening.
- Each replaced include, the vendor and the URL of the vendor's published range list.
- The resolved addresses on the date of the change.
- The lookup count and record size after the change.
- The next review date and the engineer responsible.
How do you monitor flattened records?
Use two checks. A scheduled job re-resolves each original include and diffs the result against the published addresses. DMARC aggregate reports (RFC 9990) then show the effect from the receiver side: a known sender whose SPF result changes from pass to fail or softfail is the typical sign of a missing range.
DMARC AI collects aggregate reports for all client domains in one multi-tenant view and uses AI to classify sending sources, which makes a known vendor failing SPF easier to spot. Through DMARC AI notification emails, those alerts can create tickets in Autotask.
Which providers publish their IP lists?
Check each vendor's own documentation, and flatten only when it publishes a maintained range list. For the two platforms most clients use, keep the include: Microsoft says most organisations "require include:spf.protection.outlook.com", and Google publishes include:_spf.google.com. See the Microsoft 365 SPF record explained and the Google Workspace SPF record explained.
For UK clients, the NCSC retired Mail Check on 31 March 2026, so SPF and DMARC monitoring now has to come from the MSP's own tooling.
FAQ
Is SPF flattening bad practice?
Not in itself, but it is a last resort. Flattening a vendor with a stable, documented range list is reasonable when other options are exhausted. Flattening Microsoft 365, Google Workspace or any dynamic platform is bad practice, because their addresses change and the record goes stale. Remove unused includes and use subdomains first.
How often should a flattened SPF record be reviewed?
Microsoft recommends reviewing and updating flattened entries at least quarterly, and testing SPF after every change. For vendors that change often, check more frequently with an automated job that re-resolves the original includes and alerts on differences. Aggregate reports give a second signal when a known sender starts failing SPF.
Does SPF flattening affect deliverability?
A correct flattened record authorises the same addresses as the includes it replaced, so receivers see the same SPF result. Deliverability suffers when the record goes stale or exceeds DNS size limits. Mail from a missing range fails SPF and, without aligned DKIM, fails DMARC, which matters once the policy is p=quarantine or p=reject.
Can I flatten Microsoft 365 or Google Workspace?
No. Microsoft lists include:spf.protection.outlook.com under "When you shouldn't flatten" because its sending addresses change frequently. Google says its mail server addresses "change often" and publishes include:_spf.google.com as the SPF value. Keep both as includes and free up lookups elsewhere, for example by moving other senders to subdomains.