What is SPF? How Sender Policy Framework Works
Updated September 20, 2026
Technical review by Muhannad Binmiskeen, DNS Kit developer and operator. Review policy
Sender Policy Framework (SPF) is one of the three pillars of email authentication. It answers a simple question: is the server that just sent this email actually allowed to send on behalf of this domain?
Without SPF, anyone can forge the From address on an email. With SPF, receiving mail servers can verify that the sending server is on your approved list before they deliver the message.
How SPF Works
The process is straightforward:
- You publish a TXT record in your domain's DNS that lists your authorized mail servers.
- When someone receives an email from your domain, their mail server looks up your SPF record.
- The server checks whether the sending IP matches any mechanism in the record.
- Based on the result (pass, fail, soft fail, neutral), the receiver decides what to do with the message.
SPF checks the envelope sender (the MAIL FROM address used in the SMTP transaction), not the From header that users see. This distinction matters for DMARC alignment.
SPF Record Syntax
An SPF record is a DNS TXT record that starts with v=spf1 and contains one or more mechanisms. Here is a detailed example:
v=spf1 ip4:203.0.113.0/24 ip6:2001:db8::/32 include:_spf.google.com include:sendgrid.net a mx -all
Let's break down every part:
Version Tag
Every SPF record must begin with v=spf1. This identifies the TXT record as an SPF record. There is no v=spf2 — if you see one, it is not a valid SPF record.
Mechanisms
Mechanisms define which servers are authorized. The most common ones are:
| Mechanism | Purpose | Example | Counts as DNS Lookup? |
|---|---|---|---|
ip4 | Authorize an IPv4 address or range | ip4:203.0.113.25 | No |
ip6 | Authorize an IPv6 address or range | ip6:2001:db8::/32 | No |
include | Include another domain's SPF record | include:_spf.google.com | Yes |
a | Authorize the domain's A record IPs | a or a:mail.example.com | Yes |
mx | Authorize the domain's MX server IPs | mx | Yes |
redirect | Use another domain's SPF record entirely | redirect=_spf.example.com | Yes |
exists | Advanced: pass if a DNS A lookup succeeds | exists:%{i}.spf.example.com | Yes |
Qualifiers
Each mechanism can be prefixed with a qualifier that determines what happens when it matches:
| Qualifier | Meaning | Result |
|---|---|---|
+ (default) | Pass — the sender is authorized | SPF Pass |
- | Fail — the sender is explicitly not authorized | SPF Fail |
~ | Softfail — the sender is probably not authorized | SPF Softfail |
? | Neutral — no assertion about the sender | SPF Neutral |
The All Mechanism
The all mechanism at the end of the record is a catch-all. It determines what happens to any server that didn't match an earlier mechanism.
v=spf1 include:_spf.google.com -all
This means: Google's servers are authorized; everything else returns SPF Fail. The receiver still decides whether to reject, quarantine, or accept the message under its local policy.
v=spf1 include:_spf.google.com ~all
This means: Google's servers are authorized; everything else returns SPF Softfail. The receiver decides how that result affects delivery.
Choose ~all or -all as part of a tested email-authentication policy. Before changing to -all, confirm every legitimate envelope sender and verify DMARC alignment; SPF itself does not require a receiver to reject a message.
The 10-Lookup Limit
This is the single most common cause of SPF failures.
The SPF specification (RFC 7208) limits DNS lookups during evaluation to 10. Every include, a, mx, redirect, and exists mechanism counts as one lookup. The ip4 and ip6 mechanisms do not count because they don't require a DNS query.
The problem compounds because include mechanisms are recursive. If your record includes _spf.google.com, and that record itself includes two more domains, that counts as three lookups total.
Exceeding the 10-lookup limit causes SPF to return PermError. Receivers may treat that error differently under local policy, and DMARC evaluation can still pass through aligned DKIM. Use DNS Kit's Email Health Checker to count your current lookups.
How to Stay Under the Limit
- Replace
includewithip4/ip6when possible. If a service sends from a fixed set of IPs, use those directly. - Remove unused services. If you no longer use a mail provider, remove its
include. - Use SPF flattening tools that resolve
includechains into IP addresses. Be cautious — if the provider changes IPs, your record goes stale. - Move subdomains. Send marketing email from
marketing.yourdomain.comwith its own SPF record instead of adding senders to the root domain.
Common SPF Records by Provider
Here are SPF records for popular email providers:
# Google Workspace
v=spf1 include:_spf.google.com -all
# Microsoft 365
v=spf1 include:spf.protection.outlook.com -all
# Google Workspace + SendGrid
v=spf1 include:_spf.google.com include:sendgrid.net -all
# Google Workspace + Mailchimp + SendGrid
v=spf1 include:_spf.google.com include:servers.mcsv.net include:sendgrid.net -all
Common Mistakes
Multiple SPF Records
A domain must have exactly one SPF TXT record. If you add a second one, both are invalid. Merge all your mechanisms into a single record.
# WRONG - two separate SPF records
v=spf1 include:_spf.google.com -all
v=spf1 include:sendgrid.net -all
# CORRECT - one merged record
v=spf1 include:_spf.google.com include:sendgrid.net -all
Using +all
Never use +all. It tells the world that literally every server is authorized to send email as your domain, completely defeating the purpose of SPF.
Forgetting Third-Party Senders
If you use services like Mailchimp, SendGrid, HubSpot, or Zendesk to send email from your domain, their servers must be included in your SPF record. Missing any sender means those emails fail SPF checks.
PTR Mechanism
The ptr mechanism is deprecated and should not be used. It is slow, unreliable, and many receivers ignore it entirely.
Testing Your SPF Record
You can verify your SPF configuration in several ways:
- DNS Kit Email Health Checker — instantly validates your SPF record and counts DNS lookups
- Command line — use
digto inspect the raw record:
dig TXT example.com +short
Look for the entry starting with v=spf1.
- Send a test email and inspect the
Received-SPForAuthentication-Resultsheaders in the received message.
Check your SPF record and count DNS lookups instantly.
Free, instant, no login required.
SPF and DMARC Alignment
SPF alone is useful, but it becomes much more powerful with DMARC. DMARC adds a policy layer that tells receivers what to do when SPF fails, and it checks alignment — ensuring the domain in the From header matches the domain that passed SPF.
For a complete email authentication setup, you need SPF, DKIM, and DMARC working together. Check out our email authentication overview to understand how all three protocols fit together.
Primary sources
This guide was checked against the following standards. Receiver and provider behavior can still vary by implementation and local policy.