Most broken SPF records are not wrong about which servers may send mail, they are invalid because they ask receivers to do more DNS work than RFC 7208 allows. Every new mail platform, CRM or ticketing tool tends to add another include:, and once nested includes push evaluation past ten DNS-querying terms the result is permerror, which DMARC treats as an SPF failure. This guide is a syntax and limits reference for email and DNS administrators: what each mechanism and modifier costs, how the 10 lookup and void lookup limits are counted, how to cut lookups without creating new risk, and how to watch the result in DMARC reports. For how SPF fits with DKIM and DMARC overall, see the DMARC, SPF and DKIM Guide.
Key takeaways
- Ten terms, not ten includes. RFC 7208 section 4.6.4 counts
include,a,mx,ptr,existsandredirect, including every one found inside nested includes, and the total must not exceed 10. - Some terms are free.
ip4,ip6,alland theexpmodifier cause no DNS query during evaluation and do not count. - Void lookups break records quietly. Receivers should return
permerrorafter more than two lookups that return no answer or NXDOMAIN, which often comes from stale includes for retired vendors. - One record per name. Two
v=spf1TXT records at the same name producepermerrorbefore any mechanism is evaluated. - Flattening is a trade, not a fix. Replacing includes with IP ranges saves lookups but moves the job of tracking vendor IP changes to you; Microsoft advises against flattening its own include.
SPF record anatomy
An SPF record is a single DNS TXT record published at the domain used in the SMTP MAIL FROM (and optionally HELO) identity. It starts with the version tag v=spf1, followed by space-separated terms that receivers evaluate left to right. The first mechanism that matches decides the result; modifiers apply only as described below.
A typical record looks like this:
1 Sample only, based on the public documentation cited. Assess it independently against the current official documentation, test outside production and back up first.
example.com. TXT "v=spf1 ip4:192.0.2.0/24 include:_spf.mailvendor.example mx -all"- Version:
v=spf1must come first. Records without it are ignored as SPF. - Mechanisms:
ip4:192.0.2.0/24,include:...andmxeach describe a set of authorised hosts. - Default:
-allmatches everything not already matched and returns fail. - One record: RFC 7208 section 3.2 says a domain must not publish multiple records that would cause more than one to be selected, and section 4.5 makes more than one record a
permerror. Microsoft's SPF documentation gives the same rule for each domain and subdomain. - Size: RFC 7208 section 3.4 advises keeping the record small enough that the DNS answer fits in 512 octets, and keeping the name plus all TXT records of that type under 450 octets so the reply fits in UDP. A single TXT character-string is limited to 255 octets in DNS, so long records are split into several quoted strings that receivers join without spaces.
- Scope: a record covers only the exact name it is published at. Microsoft notes that the record for the parent domain does not cover a subdomain such as
marketing.example.com; each sending subdomain needs its own record.
RFC 7208 is a Proposed Standard (April 2014) that obsoletes RFC 4408 and has since been updated by RFC 7372, RFC 8553 and RFC 8616. Publish SPF as a TXT record only: RFC 7208 retired the separate SPF record type.
Mechanisms and qualifiers reference
RFC 7208 section 5 defines eight mechanisms and section 6 defines two modifiers. The lookup cost column is what each term adds to the section 4.6.4 counter.
| Term | Type | What it matches | Counts towards 10 | Notes |
|---|---|---|---|---|
all | Mechanism | Always matches | No | Put last. Anything after it is never evaluated. |
include:<domain> | Mechanism | Matches if the target domain's SPF evaluation returns pass | Yes, 1 plus every counted term inside the target | The main source of over-limit records. A target with no SPF record gives permerror. |
a / a:<domain> | Mechanism | Sender IP equals an A or AAAA record of the domain | Yes, 1 | Optional CIDR suffix, e.g. a/24. |
mx / mx:<domain> | Mechanism | Sender IP equals an address of one of the domain's MX hosts | Yes, 1 | Each MX evaluation must not query more than 10 address records, or the result is permerror. |
ptr | Mechanism | Validated reverse DNS name ends in the domain | Yes, 1 | RFC 7208 section 5.5: should not be published. Slow and unreliable; remove it. |
ip4:<net> | Mechanism | Sender IPv4 in the range | No | Use CIDR, e.g. ip4:198.51.100.0/24. |
ip6:<net> | Mechanism | Sender IPv6 in the range | No | Include IPv6 ranges for any sender that delivers over IPv6. |
exists:<domain> | Mechanism | Matches if an A record exists for the (usually macro-expanded) name | Yes, 1 | Used by some large senders with macros. Check what the macro reveals before adopting. |
redirect=<domain> | Modifier | If no mechanism matched, evaluation continues with the target's record | Yes, 1 | Ignored if the record contains all. At most once per record. |
exp=<domain> | Modifier | On fail, supplies an explanation string from a TXT record | No | Rarely used in practice. At most once per record. |
Each mechanism can carry a qualifier prefix that sets the result when it matches. With no prefix the qualifier is +.
| Qualifier | Result on match | Typical use | Effect under DMARC |
|---|---|---|---|
+ (default) | pass | Authorised senders | Counts as SPF pass if the MAIL FROM domain aligns with the From domain |
- | fail | -all once every sender is listed | SPF fail; some receivers reject at SMTP time before DMARC runs |
~ | softfail | ~all while inventory is incomplete | Not a pass, so DMARC treats it as SPF not aligned and passing |
? | neutral | Testing only | Not a pass; Microsoft does not recommend ?all in production |
The other evaluation results defined in RFC 7208 section 2.6 are none (no record), temperror (a transient DNS problem, retry may succeed) and permerror (the published record cannot be interpreted and needs fixing by the DNS operator).
What counts towards the 10 lookup limit
RFC 7208 section 4.6.4 says implementations must limit the total number of include, a, mx, ptr and exists mechanisms and redirect modifiers to 10 during an evaluation, and return permerror if the limit is exceeded. The count is for the whole evaluation, so every counted term inside every nested include is added to your total.
Worked count
v=spf1 ip4:192.0.2.10 include:spf.protection.outlook.com include:_spf.crm.example include:mail.ticketing.example mx -allip4and-all: 0.mx: 1.- Each
include: 1 each, so 3. - Inside each include: count its own
include,a,mx,ptr,existsandredirectterms, recursively. If the CRM include itself includes three regional records, that is 3 more.
The total is the number you must keep at 10 or below. Vendors change their own records without notice, so a record that counted 9 last quarter can count 11 today with no change on your side.
Sub-limits that also produce errors
| Limit | Source | Behaviour when exceeded |
|---|---|---|
| 10 DNS-querying terms per evaluation | RFC 7208 s4.6.4 | permerror |
10 address lookups per mx evaluation | RFC 7208 s4.6.4 | permerror |
10 names per ptr evaluation | RFC 7208 s4.6.4 | Names after the first 10 are ignored, no error |
| 2 void lookups | RFC 7208 s4.6.4 (SHOULD) | permerror |
| More than one SPF record at a name | RFC 7208 s4.5 | permerror |
redirect or exp more than once | RFC 7208 s6 | Syntax error, permerror |
Microsoft's documentation adds a practical point: receivers stop at the first matching mechanism, so some mail still passes when a record is over the limit. Over-limit records can therefore go unnoticed for weeks.
The void lookup limit and permerror
A void lookup is a DNS query made during SPF evaluation that returns either no answer records or NXDOMAIN. RFC 7208 says implementations should limit void lookups to two and return permerror when more occur. The limit exists to stop records that point at names which no longer exist from generating needless DNS load.
Common causes:
- Retired vendors: an
include:for a marketing or helpdesk platform you stopped using, whose SPF name has since been deleted. - Typos:
include:spf.protection.outlook.coor a missing underscore in_spf. - Bare
aormxon a name with no records: for examplemxon a sending-only subdomain that has no MX records.
Void lookups also count towards the 10 term limit, so a stale include costs you twice. A dangling include also has a security angle: if the old vendor domain lapses and is re-registered by someone else, they control part of your SPF policy. Remove includes as part of vendor offboarding, the same way you remove the vendor's API keys and accounts.
Reducing lookups safely
Work through these options in order. The earlier ones remove lookups without adding maintenance.
- Remove what is not used. Delete includes for retired services,
ptrand anyaormxthat does not correspond to a host that actually sends mail as this domain. DMARC aggregate reports tell you which sources really send. - Replace your own hosts with
ip4andip6. Your own outbound relays rarely change address; listing their ranges costs nothing. - Move third-party senders to subdomains. Give the marketing platform
news.example.comand the ticketing toolsupport.example.comas the MAIL FROM domain, each with its own SPF record and its own 10 lookup budget. Microsoft recommends this for senders you do not control, so their problems do not affect the main domain. Under DMARC relaxed alignment a subdomain MAIL FROM still aligns with the organisational domain in the From header. - Prefer DKIM for platforms that sign. If a vendor signs with an aligned DKIM key for your domain, DMARC can pass on DKIM alone. RFC 9989 notes that domain owners can rely on DKIM-only DMARC, while recommending both. The vendor's include may then belong on a subdomain or not be needed at all.
- Flatten only stable vendor ranges. Flattening replaces an include with the IP ranges it resolves to.
Flattening: when and when not
| Approach | Lookups saved | Risk | Fits |
|---|---|---|---|
| Manual flattening | All for that include | Vendor adds IPs, your mail from those IPs fails SPF until you notice | Small vendors with documented, rarely changing ranges |
| Automated flattening service | All | The service now controls your SPF record; its outage or error affects all mail | Large estates that cannot use subdomains, with change alerts |
| Subdomain per sender | All, from the main record | More DNS records to manage | Most organisations; the preferred route |
| DKIM-only for a sender | All for that sender | Mail fails DMARC if the DKIM signature breaks in forwarding or the key is rotated badly | Vendors with aligned DKIM support |
Microsoft advises not flattening include:spf.protection.outlook.com because its sending IPs change frequently, and asks that anyone who flattens documents the change, monitors vendor IP updates, reviews at least quarterly and tests after each change. Treat flattened records as configuration with an owner, a review date and a change record, under your normal change control.
Decision guidance by organisation size
- Small organisations with one mail platform and one or two senders usually fit inside the limit with includes and
-all. The main job is removing stale includes during vendor changes. - Mid-sized organisations with five to ten SaaS senders should move bulk and transactional senders to subdomains before they reach eight counted terms, leaving headroom for vendor changes.
- Large organisations with many business units should run SPF as a managed service: a register of sending sources, an owner per subdomain, automated lookup counting in CI for DNS changes, and alerts on DMARC SPF permerror rates.
Testing and monitoring with DMARC reports
SPF records fail silently from the sender's view. DMARC aggregate reports are the cheapest way to see what receivers actually computed. DMARC itself is now specified in RFC 9989 (Proposed Standard, May 2026), which obsoletes RFC 7489 and RFC 9091; see the DMARCbis Changes Guide. Under RFC 9989, DMARC uses SPF results for the MAIL FROM identity only, not HELO, and the SPF-authenticated domain must align with the From domain.
Rollout and change procedure
- Inventory: collect two to four weeks of DMARC aggregate reports at
p=noneand list every source IP and MAIL FROM domain that sends as your domain. - Draft and count: write the new record, expand every include recursively with
dig TXTand count the terms by hand or with a checker. Target 8 or fewer for headroom. See the DNS Investigation with dig and nslookup Guide. - Lower TTL first: reduce the TXT record TTL a day ahead so a bad change can be reverted quickly.
- Publish with
~allif inventory is uncertain, then watch reports for a full business cycle, including month-end and marketing sends. - Move to
-allwhen reports show no legitimate source failing. Microsoft recommends-allwith DKIM and DMARC. RFC 9989 notes that a hard fail can lead some receivers to reject before DMARC is evaluated, which also bypasses a DKIM pass, so make sure every legitimate source either passes SPF or uses its own subdomain. - Roll back by republishing the previous record text, which you keep in version control with the change ticket.
What to monitor
- SPF result by source: aggregate report rows where
spfresult ispermerrorortemperror. - Unknown sources passing SPF: an IP passing SPF that you do not recognise means a range in an include is broader than you thought.
- Lookup count: a scheduled job that expands the record daily and alerts above 8, because vendor records change underneath you.
- Record changes: DNS change logs for TXT records at sending names. See the Authoritative DNS and Registrar Account Security Guide.
Metrics
| Metric | Target |
|---|---|
| Counted SPF lookups per sending domain (fully expanded) | 8 or fewer |
Share of DMARC-reported mail with SPF permerror | 0% |
| Legitimate sources passing aligned SPF or aligned DKIM | 100% |
Sending domains ending in -all, plus non-sending domains with v=spf1 -all | 100% |
| Days from vendor offboarding to include removal | Under 30 |
For per-message diagnosis of a failing record, see the DMARC, SPF and DKIM Failure Troubleshooting Guide.
Common failure patterns
- Two SPF records: a new vendor's onboarding guide says "add this TXT record" and someone adds a second
v=spf1record instead of merging. Every message getspermerror. - Include creep: each team adds its SaaS sender to the main domain until nested includes exceed 10. Mail from the sender listed last starts failing first.
- Stale includes: retired platforms left in the record create void lookups and a takeover path if their domain lapses.
- Flattened and forgotten: a flattened vendor range drifts out of date and a share of that vendor's mail fails SPF months later.
- Parked domains with no record: domains that never send mail but publish nothing are easy to spoof. Publish
v=spf1 -alland a DMARCp=rejectrecord on them, as Microsoft's guidance describes. - Using
+allor?allto "fix" failures:+allauthorises every IP on the internet and removes SPF's value entirely.
Framework mapping
| Framework | Reference | How SPF hygiene supports it |
|---|---|---|
| NIST CSF 2.0 | PR.PS-01 | SPF records managed as configuration with change control |
| NIST CSF 2.0 | DE.CM-01 | DMARC report monitoring of email authentication results |
| NIST SP 800-53 Rev 5 | SI-8 Spam Protection | Sender authentication supports receivers' spam and spoofing protection |
| NIST SP 800-177 Rev 1 | Trustworthy Email | Recommends SPF with DKIM and DMARC for sending domain authentication |
| CIS Controls v8.1 | Control 9 Email and Web Browser Protections | Valid SPF and DKIM underpin DMARC enforcement against email threats |
| MITRE ATT&CK | T1684.002 Email Spoofing; T1566 Phishing | Enforced SPF with DMARC limits direct spoofing of your domains |
Practitioner checklist
- Confirm exactly one
v=spf1TXT record at each sending name and subdomain. - Expand every include recursively and keep the counted total at 8 or fewer.
- Remove
ptr, stale includes and anyaormxthat does not send mail. - Check for void lookups (NXDOMAIN or empty answers) and fix them before they exceed two.
- Move third-party senders to their own subdomains with separate SPF records.
- Flatten only stable vendor ranges, with an owner, a quarterly review and change alerts; never flatten frequently changing provider includes.
- Publish
v=spf1 -allon every domain and subdomain that sends no mail. - Move from
~allto-allonce DMARC reports show every legitimate source passing. - Keep SPF records in version control and schedule a daily lookup-count check with alerting.
- Add include removal to the vendor offboarding checklist.
Standards and references
- IETF: RFC 7208 Sender Policy Framework (SPF) for Authorizing Use of Domains in Email, Version 1
- IETF: RFC 9989 Domain-based Message Authentication, Reporting, and Conformance (DMARC)
- NIST: SP 800-177 Rev. 1 Trustworthy Email
- Microsoft Learn: Set up SPF to identify valid email sources for your Microsoft 365 domain
- CIS: Critical Security Controls, Control 9 Email and Web Browser Protections
- MITRE ATT&CK: T1684.002 Email Spoofing
Related NHI Mgmt Group resources: DMARC, SPF and DKIM Guide · DMARC, SPF and DKIM Failure Troubleshooting Guide · DMARCbis Changes Guide · Email Authentication Checklist · DNS Security Guide