Safeguard
Security Guides•

Should you flatten your SPF record to stay under 10 lookups?

SPF flattening swaps includes for IP lists to dodge the 10 lookup limit, but stale addresses cause silent failures. Compare it with the safer options.

Safeguard Security Team
3 min read

Flattening replaces include mechanisms with the IP addresses they resolve to, which cuts DNS lookups. It works, but the list goes stale when a vendor changes addresses, and your mail then fails SPF. Try removing unused senders and splitting streams across subdomains first. Flatten last, and with automation that refreshes the list.

The limit that causes this

The SPF specification, RFC 7208, caps evaluation at 10 mechanisms and modifiers that cause DNS lookups. The include, a, mx, ptr and exists mechanisms and the redirect modifier count. Ip4 and ip6 do not. Go past the limit and the result is a permanent error, so receivers may treat your SPF as broken. The same document also advises limiting void lookups, queries that return nothing, to two. Our post on the 10 lookup limit explains the error in detail.

What flattening does

A flattened record expands each include into the address ranges behind it:

v=spf1 include:mailer.example.net -all

becomes something like:

v=spf1 ip4:192.0.2.0/24 ip4:198.51.100.0/25 -all

The addresses above are documentation examples. The new record uses no lookups for those senders.

The catch

The include is a live pointer. When the vendor adds or retires servers, your record follows automatically. A flattened copy does not. If the vendor starts sending from a new range, your mail fails SPF until someone updates the record. If they drop a range, you keep authorising addresses that someone else may later receive. Failures are silent and arrive at the worst time.

DNS text records also have size constraints, so a long flattened record may need splitting across multiple strings.

Options compared

ApproachEffect on lookupsUpkeepRisk
Remove senders you no longer useLowerLowLow, if you verify first
Split streams across subdomainsEach record has its own budgetMediumLow
Rely on DKIM for third partiesSPF can stay smallMediumLow if DKIM aligns
Manual flatteningLowestHighStale lists
Automated flattening that refreshesLowestLow, but you depend on a serviceService outage or error

Decision steps

  1. Count. Check your lookups with an SPF checker, and include nested ones.
  2. Prune. Remove vendors you stopped using. Verify with aggregate reports before deleting.
  3. Split. Move marketing, support and product mail to subdomains, see separate sending subdomains.
  4. Lean on DKIM. DMARC needs one aligned pass, and DKIM covers many third parties.
  5. Flatten last. If you do, automate refresh, alert on change, and keep the original includes documented.

A note on ptr and macros

The RFC discourages the ptr mechanism. Avoid it. It is slow and counts against the limit.

Safeguard is a software supply chain platform and does not manage SPF, but you can run the free scan at gold.safeguard.sh/scan on your repositories while you tidy your mail setup.

Quick check

Does ip4 count toward the 10 lookup limit?

No. The ip4 and ip6 mechanisms need no DNS query, so they do not count.

Is exceeding the limit a warning or a failure?

It produces a permanent error result, which receivers may handle as a failure. Treat it as a real fault.

Sources

Last reviewed: 19 October 2026.

Never miss an update

Weekly insights on software supply chain security, delivered to your inbox.

Self-healing security runs on Safeguard.

Your first fix PR is minutes away.

No sales call required, even your agent can complete the purchase over MCP.