An SPF (Sender Policy Framework) record is a DNS TXT record that lists which mail servers are allowed to send email for your domain, and you create it to prevent spammers from forging your domain in the "From" address. This article explains the syntax, how to create and check your SPF record, and how to fix common problems.
What Is SPF and Why Does It Matter?
SPF is an email authentication standard defined in RFC 7208. When you send an email, the receiving mail server can look up your domain's SPF record to see if the sending server's IP address is authorized. If not, the email may be marked as spam or rejected outright. SPF works alongside DKIM (DomainKeys Identified Mail) and DMARC (Domain-based Message Authentication, Reporting, and Conformance) to prove your emails are legitimate. Without SPF, your domain is more vulnerable to spoofing, which damages your reputation and can trick recipients into opening malicious emails.
SPF Record Syntax: Breaking Down the Parts
An SPF record is a single line of text in DNS, starting with v=spf1. The basic syntax is:
v=spf1 [mechanisms] [modifiers]Mechanisms define who is allowed to send. Common ones include:
ip4:– allows a specific IPv4 address or range (e.g.,ip4:192.0.2.1orip4:192.0.2.0/24)ip6:– same for IPv6 addressesa– allows the domain's A record IP (e.g.,a:mail.example.com)mx– allows the domain's MX servers (e.g.,mx:example.com)include:– includes another domain's SPF record (e.g.,include:_spf.google.com)all– matches everything; usually at the end
Each mechanism can have a qualifier prefix: + (pass, default), - (fail), ~ (softfail), or ? (neutral). For example, -all means "no other servers are allowed," while ~all means "not allowed but accept anyway." Modifiers like redirect= and exp= are rare and appear at the end.
How to Create an SPF Record: Step-by-Step
Creating an SPF record involves three steps: gathering your sending sources, writing the record, and publishing it in DNS.
- List all legitimate sending IPs and services. Check your email provider's documentation for their SPF include (e.g., Google Workspace uses
include:_spf.google.com, Microsoft 365 usesinclude:spf.protection.outlook.com). Also note any on-premise mail servers or third-party marketing tools. - Write the record. Start with
v=spf1, then add each source. Example:v=spf1 ip4:203.0.113.10 include:_spf.google.com -all. Always end with-allor~all; never leave it open. - Publish it as a TXT record. In your DNS provider's control panel, add a TXT record for your domain (or subdomain) with the full SPF string. The host is usually
@for the root domain. Wait for DNS propagation (minutes to hours).
Important: You can only have one SPF record per domain. If you add a second, DNS servers will return both, and SPF fails with a "permerror." If you need to update, edit the existing record.
How to Check Your SPF Record
After publishing, verify your record with a DNS lookup tool or command line. Common methods:
- Online SPF checkers (e.g., MXToolbox, Kitterman's SPF validator) – enter your domain and they show the record and any syntax errors.
- Command line – use
nslookup -type=TXT yourdomain.comordig TXT yourdomain.comto see the raw record. - Email test – send a test email to a service like Gmail and view the full headers; look for
spf=passorspf=fail.
When checking, ensure the record starts with v=spf1 and has no extra spaces or line breaks. The checker will also flag if you have multiple SPF records or exceed the 10-DNS-lookup limit (see below).
Common SPF Problems and How to Fix Them
Here are frequent issues and their fixes:
- Multiple SPF records – If you accidentally added two TXT records that start with
v=spf1, merge them into one. For example, combinev=spf1 include:a -allandv=spf1 include:b -allintov=spf1 include:a include:b -all. - Too many DNS lookups – SPF allows a maximum of 10 DNS lookups (each
include:,a,mxcounts). If you exceed this, the record is invalid. Reduce lookups by using IP addresses instead of includes, or removing unused mechanisms. - Missing
-allor~all– Without a finalallmechanism, the record is incomplete and may be treated as neutral. Always append-all(strict) or~all(softfail) to close the record. - Syntax errors – Typos like
ip4without a colon, or spaces in the wrong place, cause a permerror. Use an online validator to spot errors. - Include chain too long – Some providers chain includes (e.g., your include calls another include). This can quickly hit the 10-lookup limit. Simplify by using direct IPs where possible.
SPF vs. DKIM vs. DMARC: How They Work Together
SPF alone is not enough. DKIM adds a digital signature to emails, and DMARC tells receivers what to do if SPF or DKIM fails. SPF verifies the envelope sender (the MAIL FROM), while DKIM verifies the message itself. DMARC uses SPF and DKIM results to enforce policy. For example, if your SPF fails but DKIM passes, DMARC can still pass if the domain aligns. Best practice is to implement all three, with SPF as the foundation.
Frequently Asked Questions
Can I have more than one SPF record?
No. You should have exactly one SPF record per domain. Multiple records cause a permanent error, and receivers will treat the domain as having no SPF. If you need to change it, edit the existing record.
What does "~all" vs "-all" mean?
~all is a softfail: it says "this server is not authorized, but please accept the email anyway" – useful during testing. -all is a hard fail: it says "reject any server not listed." For production, use -all to be strict, but only after you've confirmed all legitimate senders are included.
How do I fix "SPF permerror"?
A permerror means the SPF record is syntactically invalid. Common causes: multiple SPF records, missing v=spf1, or exceeding 10 DNS lookups. Use an online SPF checker to identify the exact error, then edit your DNS TXT record accordingly.
Does SPF affect email delivery if I use a subdomain?
Yes, but subdomains need their own SPF records. If you send from mail.example.com, you must create an SPF record for that subdomain, not just the root domain. Receivers check the domain in the envelope sender, which may be a subdomain.
How long does SPF take to update after I change it?
DNS propagation can take from a few minutes to 48 hours, depending on your DNS provider and TTL (Time to Live) settings. Lower the TTL before making changes to speed up updates. You can check if the new record is live using a global DNS checker.