SPF, DKIM and DMARC
What Is an SPF Record? Syntax, Mechanisms, and -all vs ~all
An SPF record is a DNS TXT record listing the servers allowed to send mail for your domain. Here's how the syntax works and when to use -all or ~all.
On this page
An SPF (Sender Policy Framework) record is a DNS TXT record that lists the servers allowed to send email for your domain. When a message arrives, the receiving server looks up the SPF record for the domain in the envelope sender (the Return-Path) and checks whether the sending IP is on the list. The record ends with an all mechanism that says what to conclude when it isn't: -all means fail, ~all means softfail.
A minimal record looks like this:
v=spf1 include:spf.protection.outlook.com ip4:203.0.113.7 -all
That says: Microsoft 365's servers and 203.0.113.7 may send for this domain, and anything else should fail.
What SPF actually checks
This is the part most people get wrong. SPF doesn't check the From address you see in your mail client. It checks the domain in the SMTP MAIL FROM command, also called the envelope sender, Return-Path or bounce address. RFC 7208 also allows receivers to check the HELO name the sending server announces, but MAIL FROM is the one that matters in practice.
So if you send through an email service provider that uses its own bounce domain, the receiver checks the provider's SPF record, not yours. Your SPF record only comes into play for mail whose Return-Path is your domain or a subdomain you've set it to.
That's also why SPF alone doesn't stop someone spoofing your From address. DMARC fixes that by requiring the SPF-checked domain to align with the From domain. See what DMARC is and how SPF, DKIM and DMARC work together.
Anatomy of an SPF record
Every record starts with v=spf1 and is published as a TXT record. (There used to be a separate SPF record type in DNS; RFC 7208 discontinued it.) After the version come mechanisms, evaluated left to right. The first one that matches the sending IP decides the result, and evaluation stops.
Mechanisms
| Mechanism | What it matches | Costs a DNS lookup? |
|---|---|---|
ip4:203.0.113.0/24 | That IPv4 address or range | No |
ip6:2001:db8::/32 | That IPv6 address or range | No |
a | The IPs of the domain's A/AAAA records | Yes |
mx | The IPs of the domain's MX hosts | Yes |
include:example.net | Whatever example.net's SPF record passes | Yes, plus its own lookups |
exists: | Any domain that resolves, used with macros | Yes |
ptr | Reverse DNS of the sender | Yes, and RFC 7208 says it SHOULD NOT be published |
all | Everything | No |
a and mx can take a domain (a:mail.example.com) and a prefix length. Without one, they use the current domain.
Qualifiers
Each mechanism can carry a qualifier that sets the result when it matches:
| Qualifier | Result | Meaning |
|---|---|---|
+ (default) | pass | Authorized |
- | fail | Not authorized |
~ | softfail | Probably not authorized |
? | neutral | No assertion either way |
The qualifier defaults to +, so include:example.net and +include:example.net are the same thing. In practice, you only ever see a qualifier on all.
Modifiers
redirect=example.nethands the whole evaluation to another domain's record. It only applies if nothing else matched. Useful when several domains share one policy.exp=points to an explanation string returned with a fail. Rarely used.
The possible SPF results
RFC 7208 defines seven:
- pass: the IP is authorized.
- fail: the domain says the IP is not authorized (matched
-allor another-mechanism). - softfail: the domain says the IP is probably not authorized (
~all). - neutral: the domain makes no assertion (
?all, or no mechanism matched and there's noall). - none: no SPF record was found, or no domain to check.
- temperror: a transient error, usually a DNS timeout.
- permerror: the record couldn't be interpreted, for example two SPF records, a syntax error, or more than 10 DNS lookups.
What each one does to your mail, and how to fix the error states, is covered in SPF fail, softfail, permerror and temperror.
-all vs ~all
This is the question everyone asks, and the honest answer is that it matters less than it used to, because DMARC now does most of the enforcement.
What the spec says. RFC 7208 says receivers SHOULD NOT reject a message based solely on a softfail, though they may scrutinize it more closely. A fail is a clear statement that the sender isn't authorized, and a receiver rejecting during the SMTP conversation uses a 550 code. What a receiver actually does with either result is its own policy decision.
What happens with DMARC. Under DMARC, softfail and fail are both just "SPF didn't pass." Neither one counts toward DMARC, and the message is judged on DKIM and your DMARC policy. So for a domain with DKIM and an enforced DMARC policy, the difference mostly disappears.
Microsoft's recommendation. Microsoft recommends -all for Microsoft 365 domains, on the grounds that DKIM and DMARC should be in place anyway. It also notes that the DMARC policy is effectively ignored for ~all failures when a message has no DKIM signature, and recommends -all so DMARC can act on those messages.
The case for ~all. Some receivers do reject outright on -all before DMARC is considered. Gmail's 5.7.26 bounce has a version specifically for SPF hard fails (see 550 5.7.26). If your record might be missing a legitimate sender, or your mail is commonly forwarded, -all turns that gap into bounces.
A reasonable default: use ~all while you're still discovering all your sending sources, and move to -all once DMARC reports show every legitimate source passing. Never use +all, which authorizes the entire internet to send as you. Microsoft says ?all is for testing and shouldn't be used in production.
Rules that trip people up
- One SPF record per domain. Two TXT records starting with
v=spf1on the same name is a permerror. Merge them. - 10 DNS lookups, maximum. Every
include,a,mx,ptr,existsandredirectcounts, including the ones nested inside includes. Go over and SPF returns permerror for everything. See the SPF 10 DNS lookup limit, and count yours with the SPF analyzer. - Subdomains don't inherit. The record on
example.comdoesn't covernews.example.com. Each name that appears in a Return-Path needs its own record. - SPF breaks on forwarding. When a mailbox forwards your message, it arrives from the forwarder's IP, which isn't in your record. That's expected. DKIM is what survives forwarding.
How to write one
- List every service that sends mail using your domain in the Return-Path. Your mailbox provider, your ESP if it uses a custom bounce domain, your CRM, helpdesk, billing system and any servers you run.
- Get each vendor's documented SPF include or IP ranges.
- Put it together:
v=spf1, then IPs and includes, then~allor-all. - Count the lookups before you publish.
- Publish it as a single TXT record on the domain, then check it with the SPF, DKIM and DMARC checker.
- Confirm with a real message. Send a test and look for
spf=passand the domain you expect in theAuthentication-Resultsheader. The header analyzer shows this clearly.
For domains that never send mail, publish v=spf1 -all. That tells receivers no server is authorized, which makes the domain less useful to spoofers. Pair it with a DMARC record at p=reject.
When to get help
If your SPF record has grown past 10 lookups and you're not sure which includes are safe to remove, or you can't tell which services actually use your domain in the Return-Path, a quick review beats breaking authentication for the whole domain.
FAQ
Is SPF required?
Effectively, yes. Google requires every sender to authenticate with SPF or DKIM, and bulk senders to Gmail need both. Most other major providers expect it too.
Can I have two SPF records?
No. Two SPF records on the same domain is a permerror, which means SPF fails. Combine them into one record.
Do I need SPF if I have DKIM?
Yes. DMARC passes with either one, but SPF is still a requirement at Gmail for bulk senders and gives you a second aligned pass when DKIM breaks.
Does SPF protect my From address from spoofing?
Not on its own. SPF checks the Return-Path domain, which recipients don't see. DMARC is what ties authentication to the visible From address.
Sources
In this section
- Multiple SPF Records: Why Two Records Break SPF and How to Merge ThemA domain can have only one SPF record. Publish two and receivers return permerror, so SPF fails for all your mail. Here's how to merge them into one record.
- SPF 10 DNS Lookup Limit, Void Lookups and SPF FlatteningSPF allows 10 DNS lookups per check. Go over and receivers return permerror, so SPF fails. Here's what counts, how void lookups work, and how to fix it.
- SPF Fail, Softfail, Permerror and Temperror: What Each MeansSPF fail means the sending IP isn't authorized, softfail means probably not, permerror means your record is broken, and temperror means DNS hiccupped.
Related guides
- Authenticating Every Tool That Sends as Your Domain (Sender Inventory)List every service that sends mail as your domain, then give each one SPF coverage and DKIM signing on your domain so all of them pass DMARC.
- BIMI Logo Not Showing: Troubleshooting ChecklistA BIMI logo usually fails to show because DMARC isn't at enforcement, the SVG or certificate is wrong, or the provider has chosen not to display it.
- DKIM Fail: Body Hash Did Not Verify, Signature Failed and Other CausesDKIM fails when the message changed after signing (body hash did not verify), the signed headers changed, or the receiver can't find a matching public key.
- DMARC Fail: Why DMARC Fails and How to Fix ItDMARC fails when neither SPF nor DKIM passes for a domain aligned with your From address. Usually a sender lacks custom DKIM. Here's how to find and fix it.
- DMARC Policy: p=none vs quarantine vs reject (and Getting to Enforcement)p=none only monitors, p=quarantine asks receivers to junk failing mail, p=reject asks them to refuse it. Start at none, fix your senders, then tighten.
- DMARC Record Syntax and Tags ExplainedA DMARC record is a TXT record at _dmarc.yourdomain with tags for policy, reporting and alignment. Here's what each tag does and what's changed under DMARCbis.
Still stuck?
Some deliverability problems take an experienced eye to untangle. Tell me what you're seeing and I'll tell you what I'd check first. The first 30-minute call is free.