How to write an SPF record
An SPF record is one DNS TXT record, published at the domain your mail uses as its envelope sender, that starts with v=spf1, lists the servers and services allowed to send, and ends with a single all term. Write it once, carefully, and edit that same record every time you add a sender. Typical causes of a broken record are a second record, a typo, a missing vendor, or too many nested includes, and each of those can turn a working record into an error for all your mail.
SPF record syntax
The SPF record format is short:
v=spf1 <term> <term> <term> ... <all>
v=spf1comes first, exactly. A record that starts with anything else, evenv=spf10, is discarded. It isn't treated as an SPF record.- Terms are separated by single spaces. They're either mechanisms (
ip4,ip6,a,mx,include,exists,ptr,all) or modifiers (redirect=,exp=). What each one does is in SPF mechanisms: include, a, mx, ip4, ip6, redirect. - A mechanism can carry a qualifier:
+pass (the default when you write nothing),-fail,~softfail,?neutral. - Receivers read left to right, and the first match wins. Anything after
allis never evaluated. - End with an explicit
all(or aredirect). Without one, unmatched mail gets an implicit neutral result. - One syntax error anywhere breaks the whole record. The result becomes
permerror, not "everything except the bad term."
A typical record for a business that sends from its own server and from Google Workspace:
v=spf1 ip4:192.0.2.10 include:_spf.google.com ~all
Read it as: "192.0.2.10 may send, whatever Google's record authorizes may send, and anything else is probably not authorized."
Where to publish it
Publish the record at the domain that appears in MAIL FROM (the Return-Path), and on any hostnames your servers use in HELO. Often that's your main domain. But if a platform asks you to set up a bounce subdomain such as bounce.example.com, that subdomain is what gets checked, and it needs its own record. Subdomains don't inherit the parent's SPF.
For DMARC, that MAIL FROM domain also has to be aligned with your visible From domain. If the difference between the two addresses is new to you, read Envelope From vs Header From first.
Domains that send no mail at all get a one-line record:
v=spf1 -all
That is the form we use. You'll see some guides suggest ~all for non-sending domains; we use -all on domains that send no mail.
How to create an SPF record, step by step
- List every system that sends with your domain in
MAIL FROM. Mailbox provider, marketing platform, CRM, helpdesk, billing, web forms, on-premises servers. Your DMARC aggregate reports are the best way to catch the ones nobody remembered (How to inventory sending sources, A field-by-field walk-through of a DMARC aggregate report). - Check whether a
v=spf1record already exists at that name. If it does, edit it. Don't add a second one; two records make SPF return a permanent error (Multiple SPF records (why that is invalid)). - Add each vendor's documented
include:, or its documented IP ranges. Useip4:andip6:for your own fixed servers. If a vendor hands you a completev=spf1 ...line, copy only theinclude:part into your record. - Prefer the cheap terms. For your own fixed servers,
ip4andip6are cheaper and exact.mxis more expensive because it needs extra DNS lookups. Don't useptr. - Count DNS lookups.
include,a,mx,ptr,exists, andredirecteach cost one, and so does every one of those inside an included record. Stay at 10 or fewer (The 10-lookup limit and SPF permerror). - Pick the ending. For domains that send mail, we recommend
~all.-allis also valid; the tradeoffs, including the risk of early rejection before DMARC runs, are in Softfail vs fail (~all vs -all). Never end with+allor a bareall: both authorize every server on the internet. - Publish it as a DNS TXT record. Use your DNS host's TXT form. Some hosts want the value in quotes, and most use
@for the domain itself (the zone apex). Don't create a record of the old "SPF" type; that type is discontinued. - Give it time. DNS changes can take up to 48 hours to show up everywhere; the real time depends on your TTLs. A TTL of at least 3600 seconds is a sensible default for SPF records. Keep the old policy valid for a while after a change, since mail already in transit may be checked against the new one.
- Verify. Send a test message and look for
spf=passin theAuthentication-Resultsheader, withsmtp.mailfrom=showing the domain you expected. Then watch the SPF results per source in your DMARC aggregate reports.
Long records
A single string inside a TXT record can hold at most 255 characters, but one record can contain several strings. Receivers join them without adding spaces, so put the space inside a string:
"v=spf1 ip4:192.0.2.1 ip4:192.0.2.129 " "include:_spf.google.com ~all"
That's still one record. Keep the whole DNS answer small, too, ideally under 512 octets.
SPF record examples
All of these use documentation IP ranges. The Microsoft 365 rows end in -all, which is the ending Microsoft 365 typically uses; the rest end in ~all, our default for sending domains.
| Situation | Record |
|---|---|
Your own two servers (a compact record using only ip4) |
v=spf1 ip4:192.0.2.1 ip4:192.0.2.129 ~all |
| SPF record for Google Workspace only | v=spf1 include:_spf.google.com ~all |
| SPF record for Microsoft 365 only | v=spf1 include:spf.protection.outlook.com -all |
| Google Workspace and Microsoft 365 | v=spf1 include:_spf.google.com include:spf.protection.outlook.com ~all |
| An on-premises server plus Microsoft 365 | v=spf1 ip4:203.0.113.10 include:spf.protection.outlook.com -all |
| A domain that sends no mail | v=spf1 -all |
For Microsoft 365 domains, Microsoft recommends -all because it also recommends DKIM and DMARC. That's platform guidance for Microsoft 365; our reasons for ~all on sending domains are in Softfail vs fail (~all vs -all). Platform detail is in DMARC for Microsoft 365 (Microsoft 365) and DMARC for Google Workspace (Google Workspace), and adding a marketing or CRM platform is covered in How to add a third-party sender without breaking DMARC.
Syntax errors that break the record
These syntax errors are common:
| Wrong | Problem | Right |
|---|---|---|
include:spf.protection.outlook.com. |
Trailing period | include:spf.protection.outlook.com |
include=spf.protection.outlook.com |
Equals sign instead of colon | include:spf.protection.outlook.com |
include: spf.protection.outlook.com |
Space after the colon | include:spf.protection.outlook.com |
Others to watch for:
allin the middle of the record, so everything after it is ignored.- Split strings that join without a space (
...129""include...). - Leftover
v=spf2.0(Sender ID) records or old SPF-type records. Delete them. - Very wide ranges such as a /16, or broad shared cloud ranges. Avoid those.
Typos, extra spaces, or the incorrect use of quotation marks can make the SPF record invalid. More in Common SPF mistakes.
Who should edit it
Treat the record as a shared asset with one owner. When several teams each "add SPF" for their tool, you end up with two records or a record nobody can explain. Who usually owns SPF, DKIM, and DMARC covers how to split that work.
Free DMARC account
Turn raw DMARC reports into a readable dashboard
Point your rua address to our platform and read the results by sender and source instead of opening XML files.
- Results grouped by sending source
- SPF, DKIM and alignment results per sender
- The original XML reports are still there to download
FAQ
Where exactly do I put the SPF record?
On the domain in the envelope MAIL FROM (Return-Path), as a TXT record. For your main domain, most DNS hosts use @.
My vendor gave me a full v=spf1 ... line. Do I paste it as a new record?
No. Copy only its include: (or its IPs) into your existing record, before your all.
Do subdomains need their own SPF record?
Yes, if they're used in MAIL FROM or HELO.
Quotes or no quotes?
It depends on your DNS host's form. What matters is that the result is one TXT record with one v=spf1 value.
Should I end with ~all or -all?
We recommend ~all for domains that send mail and v=spf1 -all for domains that don't. Never +all. The full comparison is in Softfail vs fail (~all vs -all).