SPF flattening: fixing the 10-lookup limit

Last updated: October 27, 2026

RFC 7208 limits SPF evaluation to 10 DNS-querying mechanisms per check. Every include, a, mx, ptr, exists and redirect counts — and includes count recursively: include:_spf.google.com alone costs 3–4 lookups once you expand what it references. Add two or three ESPs and you are suddenly at 11 lookups, SPF returns permerror (treated as fail), and receivers start junking or rejecting your mail.

SPF flattening replaces include mechanisms with the actual ip4/ip6 ranges they resolve to. A flattened record with twenty networks costs zero lookups. The trade-off: when your ESP changes its IP ranges, your flattened record silently goes stale — which is why flattening must be automated or scheduled, never a one-time paste.

Before flattening, try the structural fixes: drop mechanisms you no longer use, move one-off senders to subdomains with their own SPF record, and prefer ip4: entries for your own servers over mx/a mechanisms that each cost a lookup.

Not sure if this affects you? Run a free domain audit and see the exact check result.

Run the free domain check

Step by step

Reduce before you flatten

  1. Audit the record: remove includes for ESPs you no longer use (the most common bloat).
  2. Replace mx and a mechanisms with explicit ip4:/ip6: — each mx/a costs a lookup and rarely matches what you actually send from.
  3. Move a bulky sender to a dedicated subdomain (news.example.com) with its own SPF record — each MAIL FROM domain gets its own 10-lookup budget.
  4. Re-count: if you are back under 10, stop here — a native record needs no maintenance.

Flatten what remains

  1. Resolve each remaining include down to its ip4/ip6 networks — use our SPF flattening tool (Toolbox → SPF flattener) or a resolver script; never copy ranges from a blog post.
  2. Assemble one record: v=spf1 ip4:... ip4:... ip6:... -all, keeping your own static IPs first.
  3. Publish with a low TTL, verify spf=pass from every ESP path, then raise TTL.
  4. Set a recurring re-flatten: ESPs publish their ranges via SPF precisely so they can change them. Re-run the flatten weekly or automate it (a cron script that re-resolves and updates DNS via your DNS provider's API).

Alternatives to manual flattening

  1. Hosted SPF services (some DNS providers and ESPs offer dynamic SPF) serve an always-current flattened record at an include target you control.
  2. Subdomain delegation: send bulk mail from a subdomain whose SPF record is managed by the ESP itself.
  3. For most domains, the best answer is subtraction, not flattening: three includes or fewer rarely exceed the limit.

Copy-paste examples

Over the limit — 13 lookups once includes expand
v=spf1 include:_spf.google.com include:sendgrid.net include:mailgun.org include:servers.mcsv.net include:amazonses.com -all
Flattened equivalent (illustrative — resolve current ranges yourself)
v=spf1 ip4:203.0.113.10 ip4:172.217.0.0/19 ip4:108.177.8.0/21 ip4:159.112.240.0/20 -all
Subdomain split — each record stays small
example.com        TXT  "v=spf1 include:_spf.google.com -all"
news.example.com   TXT  "v=spf1 include:sendgrid.net -all"

Common mistakes

  • Flattening once and forgetting — ESP IP ranges change; a stale flattened record fails silently for the ESP that changed.
  • Counting only top-level includes — the limit applies after recursive expansion; include:_spf.google.com is several lookups deep.
  • Keeping mx in the record when you send from a dedicated server — mx costs a lookup and authorizes your inbound servers, which usually do not send bulk.
  • Exceeding 255 characters per TXT string without splitting — long flattened records must be split into quoted chunks; most DNS panels handle this, verify yours does.
  • ptr mechanism to 'save' space — deprecated and itself costs lookups.
  • Forgetting ip6: when your own server sends over IPv6 — receivers connecting over IPv6 then fail SPF.

FAQ

How do I count my current lookups?

Run your domain through our Domain Audit — the SPF check reports the exact lookup count and warns at 8+ and fails over 10. Command line: dig TXT yourdomain.com, then recursively dig each include target.

Is flattening against the SPF spec?

No — the record is syntactically legal. The risk is operational staleness, not compliance. The spec authors intended includes to be used; the 10-lookup cap is the guardrail that makes heavy include chains fail.

How often must I re-flatten?

As often as your ESPs change ranges — in practice, re-check weekly and automate if any ESP changes more than rarely. If you cannot automate, prefer the subdomain-split strategy instead.

Does flattening improve deliverability by itself?

Only by restoring SPF from permerror to pass. A record within the limit and a flattened record pass identically — flattening fixes the failure, it does not add reputation.

What about macros or exists mechanisms?

Advanced, rarely needed, and each exists costs a lookup at evaluation time. For typical sender domains, static mechanisms plus flattening are simpler and safer.

Is there a record-length limit as well as a lookup limit?

Yes — DNS TXT strings are limited to 255 characters each, and the whole record should stay well inside one DNS UDP response. Long flattened records must be split into multiple quoted strings within one TXT record (v=spf1 ip4:... " "ip4:... -all); most DNS panels do this automatically. If a flattened record grows past roughly 450 characters, prefer the subdomain-split strategy over ever-longer flattening.

Fixed it? Prove it.

Send a test email and watch every check go green.

Send a test email to verify the fix

Related guides