An SPF record is one DNS TXT record at your root domain that lists which servers may send email for you and ends with a policy for everything else. The safe default is v=spf1 include:<your provider> -all, but only after you have listed every legitimate sender. Miss one and you will break mail when you tighten the policy.
This guide is the practical version. It covers the syntax you actually need, the 10-lookup limit, duplicate records and a test plan.
The record, part by part
v=spf1 include:_spf.google.com include:servers.mcsv.net ip4:203.0.113.10 ~all
v=spf1must be first. There is no version 2; anything else is not SPF.include:authorises another domain's SPF record. The included domain's own SPF must resolve within the lookup budget.ip4:andip6:authorise single addresses or CIDR ranges. Use them for your own mail server.aauthorises the domain's A record;mxauthorises its MX hosts. Both cost a lookup.exists:andredirect=are advanced mechanisms that also cost lookups.allis the catch-all. Put it last.
The qualifier in front of all decides the result for everything not listed:
| Qualifier | Result | When to use |
|---|---|---|
-all | Fail | You have listed every sender and want strict enforcement |
~all | SoftFail | You are still finding senders; receivers may still accept |
?all | Neutral | You are explicitly saying "no policy"; not useful |
+all | Pass | Never use this; it authorises the entire internet |
Rule one: exactly one record
A domain must have a single SPF record. Two TXT records starting v=spf1 cause a permanent error, and some receivers will treat the domain as having no valid SPF at all. This is common after a domain migration, when an old record is left behind.
Check your DNS zone and delete the duplicate. If two teams own different parts of the record, merge the mechanisms into one.
Rule two: stay under 10 lookups
RFC 7208 limits the DNS lookups needed to evaluate a record to 10. Every include, a, mx, ptr, exists and redirect counts. The includes nest, so one include: can spend several lookups inside the provider's record.
The practical consequences:
- Do not stack five ESPs "just in case". Each one costs lookups and widens your attack surface.
- Do not use
ptr. It is deprecated, slow and costs lookups. - Flattening (replacing an include with the provider's IP ranges) reduces lookups but creates maintenance work, because the ranges change.
- A record that returns
permerrorfor too many lookups will fail, even if every mechanism is correct.
Count the terms as a first pass, then use a checker that resolves the tree. The SPF, DKIM and DMARC checker gives a rough count and shows the raw record; it does not replace a full recursive test.
Rule three: include every legitimate sender
List every service that sends with your domain in the From: header or envelope:
- Your mailbox provider (Google Workspace, Microsoft 365, Zoho, Fastmail).
- Your cold email or marketing platform.
- Your transactional email provider (receipts, password resets).
- Your website's contact form.
- Any agency or freelancer sending on your behalf.
If you are unsure, send a test message from each system and read the Received-SPF and Authentication-Results headers. The domain that appears in the envelope sender is the one to authorise.
A safe change process
- Export the current record and note every sender you know about.
- Publish the new record with
~all, not-all. - Send test messages from every sender to a Gmail and an Outlook mailbox you own.
- Read the headers. Look for
spf=passand check which domain was authenticated. - Wait a week. Check DMARC aggregate reports if you have them.
- Only then change
~allto-all.
If you do not have DMARC reports yet, set up _dmarc at p=none first. It is the cheapest way to find senders you forgot.
Common mistakes
Putting the record on a subdomain. SPF is looked up at the domain in the envelope sender. If you send from mail.example.com, the record must be there too, unless the envelope domain is the root.
Mixing SPF and DMARC syntax. p=none belongs in the DMARC record, not SPF. An SPF record with p= is invalid.
Using +all "temporarily". It authorises every server on the internet to send as you. There is no safe temporary version of this.
Forgetting the dot. A TXT record value must be a single string. Some DNS UIs split long strings; check that the published value is what you intended.
Assuming SPF authenticates the visible From. It does not. That is DMARC's job.
How SPF fits with DKIM and DMARC
SPF alone can pass while the visible From: domain is someone else's. DMARC closes that gap by requiring alignment. If you have not read the overview, start with SPF, DKIM and DMARC in plain English, then set up DKIM before you tighten DMARC.
FAQ
How long does an SPF change take to propagate?
DNS caching means changes can take from minutes to a few hours, depending on the TTL. Lower the TTL before a planned change and raise it afterwards.
Can I have more than one SPF record?
No. Multiple records cause a permanent error. Merge them into one.
Does SPF stop spoofing?
It reduces it, but it authenticates the envelope sender, not the visible From: header. DMARC is the policy that tells receivers to reject failures.
What does ~all mean?
SoftFail. Receivers are told the message is suspicious but may still deliver it. It is a safer setting while you are still discovering legitimate senders.