How to flatten TXT records safely?
Still have a question, spotted an error, or have a better explanation or a source we should cite?
If you've ever checked your SPF record and seen a warning about too many DNS lookups, flattening is probably the fix people have told you to try. But before you start swapping out include: statements for raw IP addresses, it's worth understanding what you're actually signing up for.
What flattening means in practice: SPF flattening replaces include: mechanisms with the literal IP addresses they point to. So instead of v=spf1 include:_spf.google.com ~all, you'd write out the actual IP ranges directly. The goal is to stay under the 10-lookup limit that SPF enforces. Go over that, and receiving servers treat your record as a fail, even if you've authorised every legitimate sender.
When does flattening actually make sense? Most senders don't need it. If you're using two or three services (say, Google Workspace, Postmark, and one marketing platform), you're probably well under the limit. Run a free check first before touching anything. If you're creeping toward 8 or 9 lookups, that's when flattening starts to look attractive.
The real risk people skip over: Email providers update their IP ranges. Google Workspace, Twilio SendGrid, Mailgun. They all change their sending infrastructure from time to time. When you've flattened their include: into hard-coded IPs, you won't automatically get those updates. Your record quietly goes stale. Mail starts failing SPF for no obvious reason, and you're left debugging a problem that never should have existed.
There's no set schedule for how often providers change their IPs. Some go a year without touching them. Others update quietly with no announcement. So if you flatten manually, you're committing to checking for changes regularly (realistically every few weeks, or after any major sending incident).
How to flatten without shooting yourself in the foot:
- Check how many lookups you're currently using. Our free SPF checker will show you the count instantly.
- If you do need to flatten, use an automated flattening tool rather than doing it by hand. Several services monitor upstream records and push updates automatically when a provider changes their IPs.
- After any update, test the record end-to-end. Don't assume the tool got it right.
- Keep a note of every service you've flattened, so that when something breaks, you know exactly what to check.
Manual flattening for a high-volume sender with six or seven ESPs is genuinely painful to maintain. If that's your situation, an automated solution pays for itself quickly. For most senders with a handful of includes, it's worth exploring whether you can reduce lookups another way first (removing old or unused include: statements is often the simplest win).
If you're not sure whether you actually need to flatten, check your current lookup count with our free SPF checker. It takes about 30 seconds and tells you exactly where you stand.
Contributors
Who worked on this answer
Every name links to their profile. Every company links to their site. Real people, real accountability.