Learn
SPF Record Syntax: Mechanisms, Qualifiers and Examples
SPF record syntax explained: v=spf1, mechanisms, qualifiers, the 10-lookup limit and TXT record examples you can copy and adapt.
Reference
SPF record syntax is one line of text in a DNS TXT record: v=spf1, then mechanisms separated by spaces, normally ending with all. SPF (Sender Policy Framework) lists the servers allowed to send mail for a domain. A mechanism is a test against the sending server. Receiving servers run the tests from left to right and stop at the first match.
v=spf1 ip4:192.0.2.10 include:_spf.google.com ~all
Here, ip4:192.0.2.10 allows one server, include:_spf.google.com allows Google Workspace, and ~all gives every other server a softfail result.
SPF record format
An SPF record is a version followed by terms, separated by spaces. A term is a mechanism or a modifier.
- The record must begin with exactly
v=spf1. - A mechanism can start with a qualifier:
+,-,~or?. With none, it means+. - Mechanism and modifier names are case-insensitive.
- A syntax error anywhere returns
permerror, the result for a record that could not be interpreted. - With no match and no
redirect, the result isneutral.
Where a DNS SPF record goes
Publish it as a TXT record (DNS type 16) at the exact name it covers. RFC 7208 discontinued the separate SPF record type. Each name takes one v=spf1 record, and every subdomain that sends mail needs its own.
Receivers check the domain in the MAIL FROM address, the envelope sender used during delivery. It can differ from the From address people see. They can also check the HELO name the sending server announces.
Mechanisms
| Mechanism | Matches | DNS lookup |
|---|---|---|
all |
Every server. Goes last. | No |
ip4:192.0.2.0/24 |
An IPv4 address or range. | No |
ip6: |
An IPv6 address or range. | No |
a, a:mail.example.com |
Addresses in the name's A or AAAA records. | Yes |
mx, mx:example.com |
Addresses of that domain's MX hosts. | Yes |
include:_spf.google.com |
Another domain's SPF check, when it returns pass. |
Yes, plus terms inside it |
exists: |
A name built with macros (message placeholders), when an A record exists for it. | Yes |
ptr |
Reverse DNS of the sender. RFC 7208 says not to publish it. | Yes |
Plain a or mx uses the domain being checked. Without a / length, ip4: and ip6: mean one address.
SPF record and A record: the a mechanism
An SPF record is always a TXT record. The a mechanism authorizes the addresses in a name's A (IPv4) or AAAA (IPv6) records. Plain a authorizes whatever address your domain resolves to, so avoid it when your website sits on shared hosting or a content delivery network.
Qualifiers and -all
| Qualifier | Result | Meaning |
|---|---|---|
+ |
pass |
Authorized. |
? |
neutral |
No statement. Treated exactly like none, the no-record result. |
~ |
softfail |
Probably not authorized. Receivers should not reject on this alone. |
- |
fail |
Not authorized. Local policy decides what happens. |
Google recommends ~all. Microsoft recommends -all for Microsoft 365 domains that also use DKIM (message signing) and DMARC (the policy built on SPF and DKIM). It suggests starting a new record with ~all until you know every source. See how SPF fail and softfail differ in delivery.
Caution: with -all, receivers may reject mail from any server you forgot to list. Move to it only after your DMARC aggregate reports show every real sender passing SPF.
Modifiers
redirect=_spf.example.com hands the check to another record, for domains under the same administration. It counts as a lookup, and receivers ignore it if the record has all. exp= names a TXT record explaining failed mail. Using either twice returns permerror.
Limits
- 10 DNS lookups per check.
include,a,mx,ptr,existsandredirectcount, as do terms inside included records. Past 10, the result ispermerror. - 2 void lookups. RFC 7208 says receivers should limit queries that return no data to two. Past that, the result is
permerror. - 255 octets (bytes) per string. A TXT record can hold several strings, joined with no added space.
Examples
Enter the record as the TXT value at your DNS host, using your own IP addresses. If the name already has a v=spf1 record, edit it instead of adding another. List all your senders before you publish, and read the -all caution above. The SPF generator builds one from your senders.
SPF TXT record example for one provider
Google Workspace alone:
v=spf1 include:_spf.google.com ~all
Microsoft 365 alone (Microsoft documents other values for GCC High, DoD and 21Vianet):
v=spf1 include:spf.protection.outlook.com -all
Several senders in one record
Google documents this form for Google Workspace plus Microsoft 365:
v=spf1 include:_spf.google.com include:spf.protection.outlook.com ~all
A server of your own goes in by its public IP address:
v=spf1 ip4:203.0.113.25 include:spf.protection.outlook.com -all
A domain that sends no mail
v=spf1 -all
Microsoft documents this for parked domains. Caution: on a domain that does send mail, it fails every message.
Splitting a long record
Keep the space inside the first string, because receivers join strings without adding spaces:
example.com. TXT "v=spf1 ip4:192.0.2.10 include:_spf.google.com " "include:spf.protection.outlook.com ~all"
This is the zone-file form. In a DNS panel, the name and type go in their own fields. Some panels want each string in quotes and others take one value and split it automatically, so check your DNS host's help.
Common mistakes
- Two
v=spf1records on one name. The check returnspermerror. Merge them into one and keep every sender. - Mechanisms after
all. They are never tested, sov=spf1 ~all include:_spf.google.comleaves Google out. - A misplaced space or equals sign. The space in
include: spf.protection.outlook.comis a syntax error.include=spf.protection.outlook.comreads as an unknown modifier, so receivers ignore it and the service loses its authorization. - An
include:with no record behind it. The check returnspermerror. Take each value from the provider's documentation. - Too many lookups. Nested includes count, so fewer than 10
include:terms does not guarantee you are under the limit. - Publishing
+all. Every IP address passes.