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:

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.

Parts of an SPF record
PartMeaningDNS lookup?
v=spf1Marks the record as SPF. It must come first.No
ip4:192.0.2.10Allows one IPv4 address. ip4:192.0.2.0/24 allows a range; ip6: works the same way for IPv6.No
include:_spf.google.comAllows every server in another domain's SPF record, usually a mail provider's.Yes
aAllows the IP addresses in the domain's A and AAAA records.Yes
mxAllows the servers in the domain's MX records.Yes
exists:Passes if a given name exists in DNS. Rarely needed.Yes
ptrMatches on reverse DNS. Deprecated: RFC 7208 says not to use it.Yes
redirect=Uses another domain's SPF record instead of this one.Yes
-allThe 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:

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:

  1. Remove services you no longer use. Old marketing tools and retired helpdesks are the usual culprits.
  2. Replace a and mx with ip4 when they point at servers you control and whose addresses rarely change. If your MX is a cloud provider, you usually don't need mx at all: inbound servers aren't necessarily the ones that send.
  3. Move bulk senders to a subdomain. Send newsletters from news.example.com, which has its own SPF record and its own 10-lookup budget.
  4. 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

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.