What are the SPF record best practices?
SPF record best practices come down to a short checklist: publish exactly one record per name, stay under the 10 DNS-lookup limit and the void lookup limit of two, never use +all or ptr, end with -all or ~all, protect non-sending domains with v=spf1 -all, and remember that DMARC also needs alignment.
Most of these rules come straight from RFC 7208, the Sender Policy Framework (SPF) standard. The rest come from how DMARC (RFC 9989) uses SPF, and from Microsoft and Google documentation. This article is the checklist. Where a topic has its own deep dive, it links there. For the basics, start with the SPF guide or what SPF is and why it matters for DMARC.
Key takeaways
- One
v=spf1record per name. Two records give a permanent error (permerror) for every sender. - Budget for the three lookup limits in RFC 7208 Section 4.6.4: 10 DNS-querying terms, 10 addresses per
mx, two void lookups. - SPF only checks the envelope
MAIL FROMdomain. DMARC needs that domain to align with the visible From domain, or an aligned DKIM signature. - Every name that sends mail needs its own record, and every name that does not send mail should say so with
v=spf1 -all. - For an MSP, SPF is a recurring audit, not a one-off setup: vendors change their records even when your clients change nothing.
What does RFC 7208 require of every SPF record?
RFC 7208 sets hard rules that decide whether receivers can read the record at all. Break one and the result is permerror, which removes SPF for every sender on the domain at once.
Why must there be only one SPF record per name?
Because receivers do not choose or merge. Section 3.2 says a domain "MUST NOT have multiple records that would cause an authorization check to select more than one record", and Section 4.5 turns that into permerror. The usual cause is a vendor guide that says "add this TXT record". Merge the mechanisms into one record instead, as shown in multiple SPF records: how to merge them.
What is the 10 DNS-lookup limit?
Section 4.6.4 says implementations "MUST limit the total number of those terms to 10". The terms that count are include, a, mx, ptr, exists and the redirect modifier, through every nested record. ip4, ip6 and all cost nothing. Microsoft's SPF setup guide adds a useful warning: "having fewer than 10 include: statements doesn't guarantee fewer than 10 DNS lookups." Counting and reducing lookups is covered step by step in SPF too many DNS lookups.
What is the void lookup limit?
Section 4.6.4 also says implementations "SHOULD limit "void lookups" to two". A void lookup is a query that returns NXDOMAIN or an empty answer. They pile up when a client retires a service but leaves a:oldcrm.example.com or an old include: in the record. Treat any term that resolves to nothing as a bug and remove it. Section 4.6.4 also caps each mx term at 10 address lookups, so mx on a domain with many MX hosts can fail on its own.
How long can an SPF record be?
A single TXT string holds at most 255 octets. Section 3.3 allows several strings in one TXT record and says receivers join them "without adding spaces". So put the space inside a string, not between them:
example.com. TXT ( "v=spf1 ip4:192.0.2.0/24 include:spf.protection.outlook.com "
"include:_spf.mailer.example.net -all" )
Size matters beyond the string limit. Section 3.4 says the record "SHOULD remain small enough" for the DNS answer to fit in 512 octets, and notes that under 450 octets for the name plus all TXT records the answer ought to fit in a UDP packet. The UK National Cyber Security Centre (NCSC) SPF guidance uses the same 450-byte figure.
Which mechanisms should you avoid?
Avoid +all, ?all in production, ptr, and macros you do not fully understand. Each one either authorises too much, adds lookups, or makes the record hard to audit.
+all: theallmechanism matches every host, and+means pass. A record ending in+allauthorises the whole internet to send as your domain.?all: neutral gives receivers nothing to act on. Microsoft says "we don't recommend this value in production environments."ptr: Section 5.5 says "This mechanism SHOULD NOT be published" because it is slow, unreliable and costs lookups. Useip4,ip6orincludeinstead.- Macros: Section 7.3 warns that expansion must not exceed the 63-character DNS label limit and that senders should avoid the
s,l,oandhmacros with mechanisms, because per-user queries defeat caching. Thepmacro "SHOULD NOT be published". Section 11.6 adds that DNS queries, especially fromexists, can reveal who is sending mail. - Terms after
all: Section 5.1 says mechanisms afterall"MUST be ignored", and aredirectis ignored if the record containsallanywhere.
Exact syntax for each mechanism, qualifier and modifier is in the SPF syntax reference.
Does the order of mechanisms matter?
Yes, for cost and clarity, not for the final answer. Receivers evaluate terms "from left to right" (Section 4.6.2), and Microsoft notes that "evaluation stops when the message source is validated." Section 10.1.1 recommends "placing lower-cost mechanisms earlier in the SPF record". In practice:
- Put
ip4andip6first. They match without any DNS query. - Follow with
include:terms, with the sender that handles most of the domain's mail early, so most checks stop sooner. - Avoid
aandmxunless the hosts change often. Section 10.1.2 says it is better to use "ip4" and "ip6" over "a" unless renumbering is common. - End with one
allterm and nothing after it.
Section 10.1.1 gives a clear contrast. v=spf1 ip4:192.0.2.1 ip4:192.0.2.129 -all is efficient. v=spf1 ip4:192.0.2.0/24 mx -all is called wasteful, because the mx term adds lookups the network range already covers.
Should you use -all or ~all?
Use -all (fail) once the record lists every legitimate sender, and ~all (softfail) while you are still discovering senders. With DMARC in place, the difference is smaller than it looks, but it is not zero.
Both count as an SPF failure for DMARC. Microsoft puts it plainly: "DMARC treats -all (hard fail) and ~all (soft fail) as SPF failures." The catch is timing. RFC 9989 Section 7.1 warns that a hard fail such as -all can lead a receiver to reject the message during the SMTP transaction, before DMARC runs. That message might have passed DMARC on an aligned DKIM signature, and because it never reaches the DATA phase it will not show in aggregate reports. RFC 9989 says domain owners choosing -all "should be aware of this."
The two big providers lean different ways:
| Provider | Published guidance | Source |
|---|---|---|
| Microsoft 365 | Recommends -all "because we also recommend DKIM and DMARC for the domain" |
Microsoft Learn |
| Google Workspace | "Google recommends you use ~all in your SPF record" | Google Workspace Admin Help |
| RFC 7208 | Receivers "SHOULD NOT reject the message based solely on" softfail (Section 8.5) | RFC 7208 |
A practical rule: make sure every sender signs with aligned DKIM, then choose. With aligned DKIM everywhere, -all is safe for mail you send directly. If mail is forwarded through a host that is not in your record, ~all reduces the chance of early rejection. The full comparison is in SPF ~all vs -all with DMARC.
Why is SPF alone not enough for DMARC?
Because SPF only checks the envelope sender, not the From address people see. RFC 9989 Section 3.2.4 says "DMARC relies solely on SPF validation of the MAIL FROM identity", and Section 4.4.2 makes that domain the SPF-authenticated identifier only when SPF validates it.
DMARC then needs alignment. Under the default relaxed mode (aspf=r), the MAIL FROM domain and the From domain must share an organisational domain. Under strict mode they must match exactly. A SaaS platform that uses its own bounce domain can pass SPF and still fail DMARC. Section 5.1 asks domain owners for at least one aligned identifier, and preferably two, so SPF and DKIM together is the target. See why DMARC fails when SPF passes and DMARC alignment explained.
How should you handle SPF on subdomains?
Publish a separate record on every name that sends mail. SPF records are not inherited. Microsoft says "the SPF TXT record for contoso.com doesn't cover marketing.contoso.com", and Google says "you must add an SPF record for each subdomain."
This is also a design tool. The NCSC guidance notes that each subdomain "has its own lookup and character limits", and Microsoft suggests a subdomain such as marketing.contoso.com for third-party bulk senders to protect the main domain's reputation. Giving a newsletter platform news.example.com keeps its includes out of the apex record. The trade-offs are in subdomain or separate domain for bulk email and DMARC for subdomains.
Do not forget the names RFC 7208 checks that you might not think about:
- Return-path subdomains such as
bounce.example.com, used by many senders as the envelope domain. - Mail server hostnames used in HELO. For bounces with an empty
MAIL FROM, Section 2.4 makes the HELO name the identity checked. Section 10.1.2 suggestsv=spf1 a -allfor individual mail hosts.
How do you protect domains that send no mail?
Publish v=spf1 -all. Section 10.1.2 of RFC 7208 gives exactly this record for domains that send no mail, and Microsoft gives the same value for parked domains. It tells receivers that no host is authorised.
UK government guidance on protecting domains that do not send email pairs it with three more records:
| Record | Host | Value |
|---|---|---|
| SPF (TXT) | @ |
v=spf1 -all |
| DMARC (TXT) | _dmarc |
v=DMARC1; p=reject; sp=reject; adkim=s; aspf=s; plus a reporting address |
| Null MX | @ |
0 . |
| Empty DKIM (TXT) | *._domainkey |
v=DKIM1; p= |
SPF only covers the names you publish it on, so subdomains of a parked domain are not covered by the apex record. DMARC handles those better: sp=reject covers existing subdomains and the RFC 9989 np tag covers names that do not exist. See should parked domains have a DMARC record and non-existent subdomains and the DMARC np tag.
What does the full best-practice table look like?
This is the checklist in one place, with the reason and an example for each item.
| Practice | Why | Example |
|---|---|---|
| One record per name | Two records give permerror (RFC 7208 Section 4.5) | Merge into one v=spf1 record |
| 10 DNS-querying terms or fewer | Section 4.6.4 limit, counted through nested includes | Replace a/mx with ip4; move senders to subdomains |
| No more than two void lookups | Section 4.6.4; dead names cause permerror | Remove a:oldcrm.example.com |
| Cheap terms first | Section 10.1.1; fewer queries per check | v=spf1 ip4:192.0.2.25 include:spf.protection.outlook.com -all |
End with -all or ~all |
Section 4.7 recommends an explicit end; ?all is not for production |
... -all |
Never +all |
Authorises every host | Delete it |
No ptr |
Section 5.5: "SHOULD NOT be published" | Use ip4/ip6 |
| Avoid per-user macros | Section 7.3; caching and label length | Use static includes |
| Keep under 450 octets | Section 3.4; answer fits in UDP | Split strings at 255, trim includes |
| Every sending name gets a record | Records are not inherited | bounce.example.com TXT "v=spf1 include:_spf.mailer.example.net -all" |
| Non-sending names say so | Section 10.1.2 | v=spf1 -all |
| Aligned DKIM on every sender | DMARC passes on either aligned identifier | DKIM with d=example.com |
| TTL of at least an hour | Microsoft recommends at least 3600 seconds | 3600 |
Where the lookup budget is still too tight, flattening includes into IP addresses is an option with real maintenance costs. Microsoft does not recommend it for Microsoft 365 because its addresses change often. The trade-offs are in SPF flattening explained for MSPs. Provider specifics are in the Microsoft 365 SPF record and Google Workspace SPF record guides.
How should an MSP audit SPF across a client portfolio?
Run the same checks on every client domain on a schedule and after every DNS change. RFC 9989 Section 7.1 itself encourages domain owners to review SPF records before publishing a DMARC policy and periodically afterwards, because records drift from current needs.
A routine that works across tenants:
- Inventory names, not just domains. For each client, list the apex, every subdomain that appears as the envelope domain in DMARC aggregate reports, every HELO hostname, and every parked domain.
- Lint each record. One
v=spf1record, no syntax errors, no+all,?allorptr, nothing afterall. The DMARC checker and how to check your SPF record help here. - Count lookups and void lookups. Record the total per domain so you can see a client creeping towards 10, and resolve every include target. A vendor that changes its own record can break clients who changed nothing.
- Map each include to a sender and an owner. Includes with no current business reason are removal candidates. Ask the client before deleting.
- Compare SPF with what reports show. Sources in aggregate reports that pass DKIM but fail SPF alignment are fine. Sources that rely on SPF alone need aligned DKIM before you move from
p=nonetop=quarantineand thenp=reject. - Lock down parked domains with the four-record set above.
- Put changes through change control with a before and after check, as in DMARC change management for MSP portfolios.
When something does break, SPF permerror: what it means and how to fix it maps each cause to its fix. DMARC AI collects aggregate reports for every client domain in one multi-tenant view and uses AI to classify the sending sources, so an SPF change that breaks a sender shows up per client.
Frequently asked questions
How many includes can an SPF record have?
There is no separate include limit. The limit is 10 DNS-querying terms in total, and every include, a, mx, ptr, exists and redirect counts, including those inside nested records. One include can use several lookups on its own, so count the full tree, not the includes you can see.
Is ~all or -all better with DMARC?
Both count as SPF failure for DMARC. The difference is that -all can trigger rejection before DMARC runs, which RFC 9989 Section 7.1 warns about. Microsoft recommends -all, Google recommends ~all. Make sure every sender passes aligned DKIM first, then pick the one that suits the client's mail flows.
Do subdomains inherit the parent domain's SPF record?
No. SPF is checked on the exact name in the envelope MAIL FROM, so news.example.com needs its own record. Both Microsoft and Google say so in their setup guides. DMARC is different: subdomains can inherit the organisational domain's policy, which is why sp and np matter.
What SPF record should a parked domain have?
Publish v=spf1 -all, which RFC 7208 Section 10.1.2 gives for domains that send no mail. Pair it with a DMARC record at p=reject, a null MX record and an empty DKIM record, as UK government guidance recommends. That stops the domain being used for spoofing while it sits unused.
Should SPF records use the ptr mechanism?
No. RFC 7208 Section 5.5 says the ptr mechanism "SHOULD NOT be published" because it is slow, unreliable and costs DNS lookups. Receivers still have to support it for old records. If a client record contains ptr, replace it with the matching ip4 or ip6 ranges or the sender's own include.