SPF mechanisms: include, a, mx, ip4, ip6, redirect
include, a, mx, ip4, and ip6 are SPF mechanisms: each one describes a set of IP addresses, and if the connecting server's IP is in that set, the mechanism matches and decides the SPF result. redirect is different. It's a modifier that hands the whole evaluation to another domain's record when nothing else matched. The other mechanisms are all, which matches everything and belongs at the end, exists, an expert tool, and ptr, which you shouldn't use. Six terms (include, a, mx, exists, ptr, and redirect) cost a DNS lookup each, and that matters because a check can use at most 10.
For how the terms fit into a full record (the SPF record syntax as a whole), see How to write an SPF record.
How terms are read
An SPF record is v=spf1 followed by terms separated by spaces. Receivers evaluate them left to right, and the first mechanism that matches wins. Its qualifier sets the result:
| Qualifier | Result when it matches |
|---|---|
+ (or nothing) |
pass |
- |
fail |
~ |
softfail |
? |
neutral |
So ip4:192.0.2.10 and +ip4:192.0.2.10 mean the same thing. Mechanism and modifier names aren't case-sensitive. Unknown modifiers are ignored.
Reference table
| Term | Type | What it does | Costs a DNS lookup? |
|---|---|---|---|
ip4:<address>[/prefix] |
mechanism | Matches if the IPv4 address is in that network. Default is /32, a single address. Write ranges in CIDR form: 192.0.2.0/24, not 192.0.2. |
No |
ip6:<address>[/prefix] |
mechanism | The same for IPv6. Default is /128. | No |
a[:domain][/prefix] |
mechanism | Matches if the IP is one of the domain's A or AAAA addresses. With no domain, it uses the current one. | Yes |
mx[:domain][/prefix] |
mechanism | Looks up the domain's MX hosts, then their addresses. An mx term that needs more than 10 address lookups returns permerror. |
Yes |
include:<domain> |
mechanism | Runs a full SPF check against another domain's record and matches only if that check returns pass. A target with no SPF record gives permerror. | Yes, plus every lookup inside the included record |
exists:<domain> |
mechanism | Matches if the (usually macro-built) name has an A record. For experts. | Yes |
ptr[:domain] |
mechanism | Reverse-DNS test. Don't publish it. | Yes |
all |
mechanism | Always matches. Put it last; anything after it is ignored. | No |
redirect=<domain> |
modifier | Used only if no mechanism matched. The target record's result becomes this record's result. Ignored if the record contains all. |
Yes |
exp=<domain> |
modifier | Points to an explanation text that a receiver may show on fail. |
No |
The lookup rules, including nested ones, are in The 10-lookup limit and SPF permerror.
include: "also allow whoever that domain allows"
include is how you authorize a service run by someone else, such as your mailbox provider or a marketing platform:
v=spf1 include:_spf.google.com include:spf.protection.outlook.com ~all
The name misleads people: it doesn't copy the other record into yours. It evaluates that record on its own and uses only the outcome:
- If the included record returns pass, your
includematches and your result is pass (or whatever qualifier you put on theinclude). - If it returns fail, softfail, or neutral, your
includesimply doesn't match, and evaluation moves on to your next term. - If it returns temperror or permerror, that error comes back to your check.
That's why a vendor's -all inside its own record doesn't make your record strict, and doesn't end your evaluation. Your own final all still decides for everything not matched.
Two practical consequences:
- An
include:pointing at a domain with no SPF record gives permerror. Typos and retired vendors are the usual cause. - An include can authorize far more than you expect, because you're trusting everything the other domain lists. SPF authorizes infrastructure, not individual customers, so anyone sending through the same shared platform may pass for your domain. Add only includes a vendor documents, and remove them when you stop using the vendor.
Choosing between a vendor's include: and aligned DKIM from that vendor is covered in SPF include vs DKIM from the vendor; adding a vendor end to end is in How to add a third-party sender without breaking DMARC.
redirect: "use that record's whole answer"
redirect is for sharing one policy across domains you control. If you run many brand domains, each can point to one maintained record:
brand-a.example. TXT "v=spf1 redirect=_spf.example.com"
brand-b.example. TXT "v=spf1 redirect=_spf.example.com"
When nothing in the record matched, the receiver evaluates _spf.example.com and uses its result, including that record's own all. A few rules matter:
- It's ignored if
allappears anywhere in the record.v=spf1 include:_spf.google.com redirect=_spf.example.com ~allnever uses the redirect. - A redirect target with no SPF record gives permerror.
- Use it at most once. Put it last, though that position isn't required.
- Use it only for domains under your own administrative control. You can't reliably redirect to a domain you don't control.
To authorize two vendors, use two includes and your own ending, v=spf1 include:vendor-a.example include:vendor-b.example ~all. Writing include:vendor-a.example redirect=vendor-b.example is valid syntax, but it gives vendor B's record control over your final result.
a and mx: use only when you mean them
a and mx are convenient, but each costs a lookup, and they follow your DNS: if you move your website or MX hosts, the set of authorized IPs moves too. In most cases, a and mx are no longer the best choice. The a mx that some templates put at the front of every record often authorizes web servers that never send mail.
Use mx only if your inbound mail servers really do send outbound mail. For your own fixed servers, ip4: and ip6: are cheaper and exact.
One correction you'll see in other guides: if your record has no mx mechanism, receivers do not fall back to your MX records. With no match and no redirect, the result is neutral.
exists, ptr, and macros
existschecks whether a name resolves. It's mostly used with SPF macros such as%{i}(the sender's IP) to build per-message names. If the name doesn't exist, that's just no match; evaluation continues. It's an advanced tool for large senders, and you rarely need it.ptrdepends on reverse DNS. It's slow, unreliable, and a burden on the reverse-DNS servers. Don't publish it, and remove it if you find it.
all: the ending
all matches everything that's left, so its qualifier sets the result for every server you didn't list. Our default for sending domains is ~all; v=spf1 -all is right for domains that send no mail. Never +all or a bare all, which authorize the whole internet. The full comparison is in Softfail vs fail (~all vs -all).
Mistakes worth avoiding
redirect=together with~allor-all, so the redirect is silently ignored.- An
include:for a vendor you no longer use. It wastes lookups and keeps authorizing them. - Habitual
a mxat the front of the record. ip4:192.0.2(truncated) instead ofip4:192.0.2.0/24.include=domain, or a space after the colon.
If you're over 10 lookups, see The 10-lookup limit and SPF permerror and SPF permerror: too many DNS lookups. If you must list a source that's deliberately permissive but don't want it to produce an SPF pass for DMARC, you can give it the ? qualifier. That's an advanced case; shared sending setups are covered in Shared domains and multi-service setups.
Free DMARC account
Turn raw DMARC reports into a readable dashboard
Point your rua address to our platform and read the results by sender and source instead of opening XML files.
- Results grouped by sending source
- SPF, DKIM and alignment results per sender
- The original XML reports are still there to download
FAQ
What's the difference between include and redirect?
include says "also allow whoever that other domain allows," and your record still decides everything else. redirect says "use that other record's whole answer," and it's for domains you control.
Does ip4 use a DNS lookup?
No. ip4, ip6, and all don't count. include, a, mx, ptr, exists, and redirect do.
Is the SPF a mechanism the same as a DNS A record?
No. A DNS A record maps a name to an IP address. The SPF a mechanism uses a domain's A (and AAAA) records to decide which IPs match, and it costs one lookup.
Should I use ptr?
No. Don't publish it.
Why doesn't my include of a vendor with -all make everything fail?
Because include only looks for a pass in the other record. Anything else just means "no match here," and your record carries on.