SPF record: syntax, limits and the errors that break it
An SPF record tells receiving mail servers which servers may send mail for your domain. It is one line of text in your DNS, and one syntax error in it makes SPF return permerror for every message you send [1].
The short answer
An SPF record is a single TXT record on your domain that starts with v=spf1 and lists the servers allowed to send mail with your domain as the envelope sender. Receivers compare the sending server’s IP address with that list. The record may take at most 10 DNS lookups, and each name holds only one [1].
Where the SPF record lives
SPF lives in a TXT record on the exact name it covers: example.com for mail from example.com, bounce.example.com for mail from bounce.example.com [1]. DNS record type “SPF” was dropped, and receivers look up TXT records only [1].
SPF checks the domain in the envelope sender, the MAIL FROM address [1]. Bounces go to that address, and the server that delivers the message records it in the Return-Path header [5]. The From address your recipients see is outside SPF. DMARC connects the two: it counts an SPF pass only when the envelope sender’s domain is in alignment with the From domain [2]. Bounces and other notices from mail servers go out with an empty envelope sender [1]. For those, SPF checks postmaster@ followed by the name the sending server gave in its HELO greeting, and DMARC uses that check [1][2].
What does an SPF record look like?
example.com. TXT "v=spf1 ip4:192.0.2.0/24 ip6:2001:db8::/32 a mx include:_spf.google.com ~all"
Receivers read it left to right and stop at the first term that matches the sending IP [1].
| Term | What it does | Costs a DNS lookup? |
|---|---|---|
v= |
Marks the TXT record as an SPF record. It must come first. | No |
ip4: |
Allows the IPv4 addresses in that range. | No |
ip6: |
Allows the IPv6 addresses in that range. | No |
a |
Allows the addresses example.com resolves to. |
Yes, 1 |
mx |
Allows the addresses of the domain’s MX hosts. | Yes, 1 |
include: |
Allows whatever the SPF record at _spf.google.com allows. |
Yes, 1, plus the lookups inside that record |
~all |
Matches every IP that got this far, with a softfail result. Mechanisms after all are ignored. |
No |
exists: |
Allows the IP if a DNS name built from it exists. | Yes, 1 |
ptr |
Checks the sender’s reverse DNS. RFC 7208 says it SHOULD NOT be published. | Yes, 1 |
redirect= |
Uses another domain’s SPF record when nothing else matched. Ignored if the record has all. |
Yes, 1 |
exp= |
Points to an explanation text for rejected mail. | No (looked up only after a fail) |
Sources: RFC 7208, sections 4.5, 4.6.4, 5 and 6 [1]. Google’s setup guide uses the include _spf.google.com for Google Workspace [3].
An ip4: term without a prefix length covers one address, as /32 does, and an ip6: term without one stands for /128 [1]. Term names are case-insensitive, so INCLUDE: works like include: [1].
What do ~all, -all and +all mean?
Each mechanism can carry a qualifier in front. Without one, it is + [1].
| Qualifier | Result when the term matches | Meaning |
|---|---|---|
+ |
pass | The server is allowed. |
- |
fail | The server is not allowed. |
~ |
softfail | The server is probably not allowed, a weaker statement than fail. |
? |
neutral | The domain makes no statement about the server. |
Source: RFC 7208, sections 2.6 and 4.6.2 [1].
The qualifier on all decides what happens to mail from every server you did not list. -all says those servers are not allowed. ~all says they probably are not, and RFC 7208 asks receivers not to reject mail on a softfail alone [1]. Google recommends ~all [3]. Microsoft recommends -all for Microsoft 365 domains, because it also recommends DKIM and DMARC for them [4]. RFC 9989 warns that -all can get a message rejected on SPF alone, before DMARC sees a valid DKIM signature [2]. +all lets every server on the internet pass SPF as your domain [1].
A record without all and without redirect= is still valid. When no term matches, the result is neutral, as if the record ended in ?all, and receivers must treat neutral exactly like having no SPF record [1]. RFC 7208 advises ending the record with one of the two [1], and the checker flags a record that leaves them out.
The two SPF limits
- 10 DNS lookups. The terms
include,a,mx,ptr,existsandredirecteach cost one, including those inside the records you include. Lookup 11 makes the result permerror [1]. - 2 void lookups. A term whose DNS query returns no answer, or a name that does not exist, is a void lookup. RFC 7208 says receivers SHOULD allow two, and a third makes the result permerror [1].
Microsoft’s SPF guide for Microsoft 365 gives the 10-lookup limit too, along with the rule of one SPF record per name [4].
Problems and fixes
SPF permerror: too many DNS lookups
Your record needs more than 10 DNS lookups, so mail from the services at the end of it gets permerror. Find the costly includes and cut them.
Two SPF records on one domain
dig +short TXT example.com shows two lines that start with v=spf1, and SPF returns permerror for every message. Merge them into one record.
A domain that sends no email
A parked domain, or one that only serves a website, can be forged in phishing mail too. It needs v=spf1 -all and three more records. Lock down a domain that sends no email.
Check your SPF record
The SPF checker reads your SPF record and every include behind it in your browser, counts the DNS lookups and flags the terms that break it.
Runs in your browser. Your domain is not sent to this site or stored.
Guides in this topic
SPF permerror: too many DNS lookups, and how to get back to 10 or fewer
Your SPF record gets 10 DNS lookups. The eleventh turns the result into permerror. Count yours, find the costly includes and cut them without breaking mail.
Two SPF records on one domain: why both stop working, and how to merge them
Two SPF records on one domain make SPF fail for both providers. Receivers return permerror. Find the duplicate and merge them into one valid TXT record.
