Glossary · Authentication
What is SPF flattening?
The short answer
SPF flattening is a way to shorten an SPF record by replacing its include entries with the actual IP addresses they stand for. People do it to stay under SPF's limit of 10 DNS lookups. A flattened SPF record needs fewer lookups, but it has to be kept up to date.
Also called: flatten SPF record, SPF record flattening, SPF flattener, SPF compression
By Ali Tahir Sajjad · Updated · 4 min read
SPF flattening: what to remember
- An SPF record is only allowed 10 DNS lookups. Go over, and SPF fails.
- SPF flattening swaps include entries for plain IP addresses, which need no lookups.
- The risk: providers change their IP addresses, and a flattened record does not update by itself.
- A cold email domain that only sends through Google or Microsoft does not need SPF flattening.
What does SPF flattening mean?
To understand SPF flattening, you first need one fact about SPF.
SPF is the record in your DNS that lists who is allowed to send email for your domain. Most of the time you do not list servers one by one. You write a shortcut, called an include, that says “also allow everyone on this other company’s list”:
v=spf1 include:_spf.google.com ~all
Each include is a pointer. To follow a pointer, the receiving mail server has to make a DNS lookup. And here is the rule that causes all the trouble: SPF allows only 10 DNS lookups.
SPF flattening is the fix. You replace the pointers with the actual IP addresses they lead to. IP addresses need no lookups, so the record becomes “flat”.
Think of a note on your front door that says “the spare key is with the neighbour, who left it with her sister, who gave it to a friend”. Every hop takes time. Flattening is replacing that note with the key itself.
Why SPF has a 10 lookup limit
The limit protects mail servers. Without it, someone could publish an SPF record that sends a server on thousands of lookups for every email, and slow it to a crawl.
The catch is that includes are nested. One include can contain three more inside it. A record that looks like it has four includes might really use twelve lookups.
When a record goes over 10, the result is not a warning. It is an SPF permerror, a permanent error, and SPF is treated as failed for every email you send.
An SPF flattening example
Before flattening. This record uses five services, and together they need more than 10 lookups:
v=spf1 include:_spf.google.com include:servers.newsletter.example
include:mail.crm.example include:helpdesk.example
include:spf.billing.example ~all
After flattening. The includes are replaced with the IP address ranges they stood for:
v=spf1 ip4:198.51.100.0/24 ip4:203.0.113.0/25 ip4:192.0.2.64/26
ip4:198.51.100.128/27 ~all
The flattened record allows the same servers, but the receiving mail server reads the answer directly. It now needs zero lookups for those entries.
How SPF flattening works
- A tool reads your SPF record.
- It follows every include, and every include inside those, until it has the full list of IP addresses.
- It writes a new SPF record that lists those IP addresses directly.
- You publish the new record in your DNS in place of the old one.
- A good flattening service repeats this automatically, so the record changes when a provider changes its IP addresses.
The risk of SPF flattening
Flattening has one real danger: it goes out of date.
When you use an include, the other company keeps its own list current. When you flatten, you take a photo of that list on one day. If the provider adds new servers next month, your photo does not show them, and email sent from the new servers fails SPF.
That is why flattening by hand, once, is a bad idea. If you flatten, use a service that checks and rewrites the record on its own.
Do you need SPF flattening for cold email?
Almost never, and here is why.
A domain used for cold email should do one job: send from your inboxes. Its SPF record has a single include, for Google or for Microsoft, which uses only a few of the 10 lookups. There is nothing to flatten.
SPF flattening is a problem for busy company domains, where the same domain is used by the mailbox provider, a newsletter tool, a CRM, a help desk and a billing system all at once.
This is one more reason well-built cold email infrastructure keeps sending on separate domains: each domain has a short, simple SPF record that cannot hit the limit.
PureMail writes that record for you on every domain when it sets up your Google Workspace inboxes or Microsoft 365 inboxes.
What to try before SPF flattening
- Remove services you no longer use. Old includes are the most common cause of going over the limit.
- Move a service to a subdomain. Send newsletters from
news.example.com, with its own SPF record and its own 10 lookups. - Drop entries you do not need. The
aandmxentries each cost a lookup and are often not needed. - Never add a second SPF record. Two records on one domain is an error in itself.
How to count your SPF lookups
Paste your domain into an SPF checker such as MXToolbox. It shows your record, follows each include and tells you the total number of lookups. Under 10 is fine. Over 10 needs fixing, and SPF flattening is one of the ways to do it.