SPF is the oldest of the three sender-authentication mechanisms and the one most domains have published wrong. This article is the operator-grade treatment we use when auditing a client domain — the mechanisms in plain language, the 10-lookup limit that silently breaks records, the qualifier progression from ?all to -all, and the techniques for keeping a record valid while a third-party sender list grows.
How to verify
Look at what is published today, then run a validator that walks the includes. The DNS shows one TXT record; the validator shows the actual lookup count and the resolved IP universe.
dig +short TXT example.com | grep -i 'v=spf1'
dig +short TXT _spf.google.com
dig +short TXT spf.protection.outlook.com
# online check that counts lookups:
# https://www.kitterman.com/spf/validate.html
# https://mxtoolbox.com/spf.aspx
echo "test" | mail -s "spf probe" check-auth@verifier.port25.com
The port25 verifier returns spf=pass, spf=neutral, spf=fail, or spf=softfail in the reply email. Combined with the lookup-count tool, you have the two facts that matter: does the record cover your legitimate senders, and is it under the 10-lookup ceiling.
What’s happening
SPF is a TXT record at the org domain (and optionally at subdomains) that lists which IPs are allowed to send mail with that domain in the envelope MAIL FROM (also called Return-Path). It does not authenticate the From: header — DMARC adds the alignment between envelope and header.
The mechanisms, in the order they typically appear:
v=spf1— required version tag, always first.ip4:1.2.3.4/ip4:1.2.3.0/24— literal v4 address or range.ip6:2001:db8::/32— literal v6 range.a— the A/AAAA record(s) of the domain itself.mx— the MX records’ IPs.include:_spf.example.net— pull in another domain’s SPF record. Eachincludecosts one DNS lookup; the included record may include further, and each of those costs another lookup.exists:%{i}._spf.example.com— query a synthetic record per sending IP (rarely used outside macro-heavy designs).all— terminal match. Always last.
The qualifiers in front of each mechanism control verdict:
+(default) — pass.-— fail. The receiver MAY reject the message at SMTP time.~— softfail. The receiver should accept but mark suspicious.?— neutral. No verdict.
The terminal mechanism is almost always all with a qualifier:
?all— explicit neutrality. Useful while building the record.~all— softfail. The safe choice during a DMARCp=noneobservation window.-all— hardfail. The end-state once DMARC is enforcing and every sender is in the record.
The 10-lookup limit
RFC 7208 §4.6.4 caps DNS lookups during SPF evaluation at 10. The mechanisms that count: include, a, mx, ptr, exists, plus redirect. The mechanisms that do NOT count: ip4, ip6, all.
A real-world tally for a mid-sized organization:
v=spf1
include:_spf.google.com # 1, but expands to 3 more = 4 total
include:spf.protection.outlook.com # 5
include:_spf.mailgun.org # 6
include:mail.zendesk.com # 7
include:_spf.salesforce.com # 8, expands to 9 total
include:mktomail.com # 10
-all # over the cap — record is PermError
PermError is the most dangerous SPF state — receivers MAY treat it as fail, MAY treat it as no-policy, and behavior varies by receiver. You will get inconsistent delivery and never know why until you run a checker.
The decision
There are three approaches when a record approaches the 10-lookup ceiling. Pick deliberately.
-
Cut. Remove senders the business no longer uses. Half the records we audit have an
include:for a SaaS the marketing team canceled two years ago. -
Flatten. Replace
include:_spf.vendor.comwith the literalip4:/ip6:ranges that vendor publishes. Pros: no lookup cost. Cons: the vendor changes IPs and your record goes stale — silent breakage. Only flatten vendors with published, stable, communicated IP ranges; never flatten Google, Microsoft, or Mailgun whose IP pools change weekly. -
Subdomain split. Move some senders to a subdomain (
mg.example.com,marketing.example.com) with its own SPF record. The vendor’sFrom:becomesnews@marketing.example.com. Each subdomain has its own 10-lookup budget. This is the cleanest pattern for organizations that send from many distinct programs.
The procedure
-
Inventory every sender of your domain. Walk through:
- Mail servers you operate (this Postfix).
- Mailbox provider for staff (Google Workspace, Microsoft 365).
- Transactional ESP (Mailgun, Postmark, Sendgrid, AWS SES).
- Marketing platform (Mailchimp, Marketo, HubSpot).
- Support/ticketing (Zendesk, Freshdesk, Helpscout).
- CRM (Salesforce, Pipedrive, HubSpot CRM).
- Internal apps that send notifications (Jira, GitLab, CI runners).
The fastest source for the inventory: a DMARC
p=noneRUA report from a tool likeparsedmarc— see opendmarc-validation-postfix. -
Build the record incrementally. Start with
~allwhile observing:example.com. 3600 IN TXT "v=spf1 ip4:203.0.113.10 include:_spf.google.com include:spf.protection.outlook.com include:_spf.mailgun.org ~all" -
Count lookups. Run the kitterman.com checker; it reports total lookups. Aim for ≤8 to leave headroom for future senders.
-
Promote to
-allonly when DMARC RUA reports show >99% pass. Order: SPF~all→ DMARCp=none→ wait 4 weeks → SPF-all→ DMARCp=quarantine→ DMARCp=reject. -
Document the record. Keep the SPF in version-controlled zone data with a comment per
include:explaining which program it covers. When the marketing director asks why aninclude:is there in 18 months, the comment is the answer.
Subdomain inheritance
DNS does not let SPF inherit. A subdomain with no SPF record of its own is treated as no policy by SPF. But DMARC inherits via the org domain — so mail.example.com with no SPF still falls under _dmarc.example.com. If you don’t want subdomains accidentally claiming the org SPF, publish explicit empty-but-fail records:
internal.example.com. 3600 IN TXT "v=spf1 -all"
A subdomain like that says “no one is allowed to send as internal.example.com” — useful for legacy subdomains that should never originate mail.
Common pitfalls
- The record uses
+all(often left in from a vendor template) — every IP on the internet passes SPF; the record is worse than having none. - The record exceeds 10 lookups and shows
PermErrorin DMARC reports; the operator can’t see this fromdigand assumes SPF is working. - The
MAIL FROMisbounces.example.com(set by some ESPs) but onlyexample.comhas an SPF — SPF passes for the envelope but DMARC fails alignment underaspf=s; either align the envelope or publish SPF at the subdomain. - Multiple
v=spf1TXT records on the same domain — RFC 7208 says this is PermError; only one SPF record allowed per domain. - Flattening a vendor’s IP ranges with
ip4:and then the vendor adds a new range; the flatten becomes stale silently. Set a calendar reminder to re-flatten quarterly, or don’t flatten.
Stack Harbor audits SPF as a quarterly artifact in the engagements we run — record under 8 lookups, every include: annotated to a live program, qualifier matched to DMARC posture, and changes flow through version-controlled zone data so the audit trail outlives any individual administrator. If you have a domain showing erratic deliverability and an SPF nobody has dared touch since 2019, that audit is part of our Managed Operations practice.