What is SPF and how to fix common SPF errors
SPF tells receiving mail servers which servers may send email for your domain. Here's how to read a record, and how to fix the mistakes that make it fail.
What SPF does
SPF (Sender Policy Framework, defined in RFC 7208) is a TXT record in your domain's DNS. It lists the servers that are allowed to send email using your domain. When a message arrives, the receiving server looks up that record and checks whether the server that connected to it is on the list.
SPF on its own has two important limits:
- It checks the envelope sender, not the From address you see. The envelope sender (also called the MAIL FROM or Return-Path address) is the address bounces go back to. A message can pass SPF for
bounces.example.netwhile the From line showsyou@example.com. DMARC closes that gap by requiring the two domains to match, which is called alignment. - It usually breaks when mail is forwarded. A forwarding server sends the message on from its own IP address, which isn't in your SPF record. That's one reason DKIM matters too: a DKIM signature normally survives forwarding.
How to read an SPF record
Here's a typical record for a domain that uses Google Workspace, Microsoft 365 and one server of its own:
v=spf1 ip4:192.0.2.10 include:_spf.google.com include:spf.protection.outlook.com -all
It's read from left to right, and the first part that matches the sending server decides the result.
| Part | Meaning | DNS lookup? |
|---|---|---|
| v=spf1 | Marks the record as SPF. It must come first. | No |
| ip4:192.0.2.10 | Allows one IPv4 address. ip4:192.0.2.0/24 allows a range; ip6: works the same way for IPv6. | No |
| include:_spf.google.com | Allows every server in another domain's SPF record, usually a mail provider's. | Yes |
| a | Allows the IP addresses in the domain's A and AAAA records. | Yes |
| mx | Allows the servers in the domain's MX records. | Yes |
| exists: | Passes if a given name exists in DNS. Rarely needed. | Yes |
| ptr | Matches on reverse DNS. Deprecated: RFC 7208 says not to use it. | Yes |
| redirect= | Uses another domain's SPF record instead of this one. | Yes |
| -all | The catch-all at the end: what happens to every server not listed. | No |
The symbol in front of all (its qualifier) sets the result for unlisted servers:
-all: fail. Unlisted servers aren't authorized.~all: soft fail. Unlisted servers aren't authorized, but the receiver should accept the message and treat it with suspicion.?all: neutral. The record makes no statement about unlisted servers, which makes it almost useless.+all: pass. Any server in the world may send as your domain.
Besides pass, fail, soft fail and neutral, a check can return none (no SPF record), temperror (a temporary DNS problem) or permerror (the record is broken). A permerror is the one to worry about, because receivers treat it as if SPF couldn't be evaluated at all.
Common SPF errors and how to fix them
1. More than one SPF record
A domain must have exactly one TXT record that starts with v=spf1. Two records cause a permerror, and SPF stops working for all your mail. This usually happens when a second service's setup guide says "add this TXT record" and nobody merges it with the existing one.
Before:
v=spf1 include:_spf.google.com ~all
v=spf1 include:sendgrid.net ~all
After: one record with both includes and a single all at the end.
v=spf1 include:_spf.google.com include:sendgrid.net ~all
Other TXT records on the same name, such as site-verification codes, are fine. Only records starting with v=spf1 count.
2. Too many DNS lookups
SPF allows at most 10 mechanisms that need a DNS lookup while the record is evaluated: include, a, mx, ptr, exists and redirect. The count is recursive, so the includes inside each provider's own record count against your limit too. One provider's include can use three or four lookups on its own. Going over 10 is a permerror.
ip4, ip6 and all don't use lookups. RFC 7208 also limits "void" lookups (ones that return no records) to two, so includes that point at names that no longer exist cause trouble even below 10.
Ways to get back under the limit, safest first:
- Remove services you no longer use. Old marketing tools and retired helpdesks are the usual culprits.
- Replace
aandmxwithip4when they point at servers you control and whose addresses rarely change. If your MX is a cloud provider, you usually don't needmxat all: inbound servers aren't necessarily the ones that send. - Move bulk senders to a subdomain. Send newsletters from
news.example.com, which has its own SPF record and its own 10-lookup budget. - Flatten with care. Replacing an include with the IP ranges it currently lists saves lookups, but providers change their ranges without telling you, and a stale list silently breaks delivery. Only do this with a tool that keeps the list updated.
3. +all or ?all at the end
+all authorizes every server on the internet, which defeats the purpose of SPF. ?all gives receivers nothing to act on. Replace either with ~all while you're still finding all your senders, or with -all once you're confident the list is complete.
v=spf1 include:spf.protection.outlook.com -all
With an enforcing DMARC policy in place, DMARC decides what happens to mail that fails, so many administrators keep ~all. One reason: a few receivers reject a message outright on an SPF -all fail before they look at DKIM, which can block forwarded mail that a valid DKIM signature would have saved. Either qualifier is a reasonable choice; the important thing is not to leave +all or ?all.
4. A legitimate sender is missing
If invoices, password resets or newsletters fail SPF, the service that sends them probably isn't in your record. Each service documents the exact include or IP range to add. Use what its own documentation says rather than guessing, because the names differ between providers and change over time. Then merge it into your one existing record.
DMARC aggregate reports are the most reliable way to find senders you didn't know about. See How to set up DMARC step by step.
5. Using ptr
The ptr mechanism matches senders by reverse DNS. It's slow, unreliable and deprecated, and some receivers ignore it. Replace it with the ip4 ranges or the include your provider documents.
6. Syntax mistakes
- A space after the colon:
include: _spf.google.comis invalid. It must beinclude:_spf.google.com. - Missing or misspelled version: the record must start with exactly
v=spf1. - Something after
all: anything afterallis never evaluated, so put every mechanism before it. - The old SPF record type: DNS once had a separate record type called SPF. It's no longer used. Publish SPF as a TXT record.
- Long records split badly: a single string in a TXT record holds at most 255 characters. DNS providers split longer records into several strings, and receivers join them back together without adding spaces. If a split falls between two mechanisms, make sure one side of it keeps the space.
Domains that don't send email
Parked domains and domains used only for a website are easy targets for spoofing, because nobody watches them. Publish an SPF record that allows no one:
v=spf1 -all
Pair it with a DMARC record of v=DMARC1; p=reject; at _dmarc.example.com, and, if the domain receives no mail either, a null MX record (0 .).
After you change the record
DNS changes take time to reach resolvers, up to the old record's TTL. Once you've saved the new record, check it again, and send a test message to a mailbox where you can view the headers. Look for spf=pass in the Authentication-Results line.
Check your SPF record now
The domain checker counts your DNS lookups recursively, flags duplicate records and risky all qualifiers, and suggests a corrected record you can copy.