SPF Explained: How Sender Policy Framework Protects Your Domain

TL;DR

  • SPF (Sender Policy Framework) is a DNS TXT record that lists which IP addresses are authorised to send email on behalf of your domain. Receiving servers check this record to verify that an email actually came from a permitted server.
  • SPF only checks the envelope sender (Return-Path), not the header “From” address that users see. This is a key limitation that makes SPF insufficient on its own without DKIM and DMARC.
  • SPF records have a hard 10 DNS lookup limit defined by RFC 7208. Exceeding this limit causes SPF to return a PermError, failing authentication for every message from your domain.
  • SPF adoption is high-research shows 86% to 96% of domains have SPF records published. However, only a fraction enforce strict email authentication with DMARC, leaving many domains vulnerable to impersonation.
  • SPF is the first line of defence but not a complete solution. It must be combined with DKIM and DMARC for comprehensive email authentication.

What Is Sender Policy Framework?

SPF is a DNS‑based protocol that specifies which mail servers are authorised to send emails for your domain. When a receiving mail server gets an email claiming to be from your domain, it looks up your SPF record and checks whether the sending server’s IP address is on the authorised list.

The problem SPF solves is fundamental: SMTP, the protocol that powers email, was designed without built‑in authentication. Anyone with a mail server can send an email claiming to be from your domain. SPF closes this gap by letting you publish a list of authorised senders in DNS.

How SPF verification works. The receiving server looks up the domain’s DNS TXT record, retrieves the SPF record, and checks whether the sending IP address is authorised.

How SPF Works Step by Step

  1. An email is sent from a server on behalf of your domain.
  2. The receiving mail server looks up the SPF record for the domain in the Return‑Path (envelope sender).
  3. The sending IP address is checked against the authorised IPs listed in the SPF record.
  4. A result is determined: pass, fail, softfail, neutral, or none.

Important limitation: SPF only checks the envelope sender (Return‑Path), not the header From address that users actually see. This means an email can pass SPF while still displaying a spoofed From address in the user’s email client. This is why SPF must be combined with DKIM and DMARC for complete protection.

SPF Record Syntax

Basic Structure

v=spf1 [mechanisms] [qualifier]all

Mechanisms

MechanismDescriptionExample
ip4Authorise an IPv4 address or rangeip4:192.0.2.0/24
ip6Authorise an IPv6 address or rangeip6:2001:db8::/32
aAuthorise the domain’s A record IPa:mail.example.com
mxAuthorise the domain’s MX record IPmx:example.com
includeInclude another domain’s SPF recordinclude:_spf.google.com
existsCheck if a domain existsexists:%{i}.example.com

Qualifiers

QualifierMeaningExample
+ (pass)Authorised+ip4:192.0.2.1
- (hard fail)Not authorised, reject-all
~ (soft fail)Not authorised, but accept~all
? (neutral)No statement?all

SPF Record Examples

Simple

v=spf1 ip4:192.0.2.1 -all

With Include

v=spf1 include:_spf.google.com -all

Complex

v=spf1 ip4:192.0.2.0/24 ip6:2001:db8::/32 include:_spf.google.com include:mailgun.org ~all

The 10 DNS Lookup Limit

The SPF specification (RFC 7208) imposes a hard limit of 10 DNS lookups during SPF record evaluation. Each include, a, mx, and exists mechanism counts as a lookup.

Why the limit exists: The limit prevents cascading DNS lookups that could create denial‑of‑service conditions on receiving mail servers.

What happens when you exceed the limit: Exceeding the 10‑lookup limit produces a PermError (permanent error), which causes SPF authentication to fail for every message from your domain-even legitimate ones.

How to avoid exceeding the limit:

  • Audit and remove unused include statements for services you no longer use.
  • Consolidate multiple include statements where possible.
  • Use an SPF flattening service to resolve include chains into direct IP addresses, eliminating lookup overhead entirely.
  • Budget for 7–8 lookups to leave headroom.

SPF Flattening

SPF flattening replaces include mechanisms with resolved IP addresses to reduce lookups. However, traditional manual flattening is a temporary fix-it becomes outdated quickly and exposes your infrastructure. Automated SPF flattening services continuously monitor your DNS records and make adjustments in real time, ensuring your SPF record stays under the 10‑lookup limit.

Common SPF Mistakes

MistakeWhy It’s a ProblemFix
Exceeding the 10-lookup limitSPF returns PermError, failing authentication for all emailsRemove unused includes, use flattening
Multiple SPF recordsOnly one SPF record is permitted per domainMerge into a single record
Missing sending sourcesNew platforms, CRMs, or tools added after the record was createdAudit all sending sources regularly
Using +allPermits any server to send email from your domainNever use +all
Syntax errorsA single misplaced space, missing colon, or duplicate record can silently break email for your entire domainValidate your record before publishing
Terminating with ~all indefinitelySoft fail does not fully block unauthorised sendersMove to -all after verification

SPF Best Practices

  1. Use only one SPF record per domain-multiple records cause a PermError.
  2. Keep it simple-stay well below the 10‑lookup limit. Budget for 7–8 lookups to leave headroom.
  3. Start with ~all (soft fail) during implementation to avoid blocking legitimate email while you verify all sending sources.
  4. Move to -all (hard fail) after you are confident your SPF record lists every legitimate sending service.
  5. Audit all sending sources-include all email marketing platforms, transactional email providers, CRMs, and cloud platforms.
  6. Document your SPF record-maintain a record of what each include statement represents.
  7. Test before deploying-use online tools and command‑line validation.
  8. Combine with DKIM and DMARC-SPF alone is insufficient.

Testing Your SPF Record

Online Tools

  • MXToolbox SPF Check
  • SPF Validation Tool
  • Google Admin Toolbox

Command Line

dig TXT example.com +short | grep spf

What a Passing SPF Check Looks Like

Authentication-Results: spf=pass smtp.mailfrom=example.com;

SPF Limitations

LimitationWhy It Matters
Does not check the header FromSPF only validates the envelope sender (Return‑Path), not the address users see
Breaks with email forwardingForwarding changes the Return‑Path, causing SPF to fail
10‑lookup limitComplex email infrastructure can easily exceed this
DNS changes take time to propagateUpdates to SPF records are not instantaneous

Key Takeaways

  • SPF authorises sending IPs through DNS TXT records, providing the first layer of email authentication.
  • SPF only checks the envelope sender, not the header From address. This is a key limitation that makes SPF insufficient on its own.
  • SPF records have a hard 10‑lookup limit defined by RFC 7208. Exceeding this causes permanent failure.
  • SPF adoption is high-86% to 96% of domains have SPF records. However, 67.9% of domains have clean SPF, meaning 1 in 3 have at least one issue.
  • Use ~all (soft fail) during implementation, then move to -all (hard fail) after verification.
  • SPF is not a complete solution. It must be combined with DKIM and DMARC for full protection.

Conclusion

SPF (Sender Policy Framework) is the first line of defence against email spoofing. By publishing a DNS TXT record that lists authorised sending IPs, you tell receiving mail servers which servers are permitted to send email on your behalf.

However, SPF has significant limitations. It only checks the envelope sender (Return‑Path), not the header From address that users see. It breaks with email forwarding and is capped at 10 DNS lookups, which complex email infrastructure can easily exceed.

SPF adoption is now widespread-research shows 86% to 96% of domains have SPF records. Yet many organisations still make critical mistakes: exceeding the lookup limit, publishing multiple records, missing sending sources, or using +all. These errors can silently damage deliverability.

To achieve comprehensive email authentication, SPF must be combined with DKIM (cryptographic signing) and DMARC (policy enforcement and reporting). Start with SPF, layer in DKIM, then deploy DMARC in monitoring mode. After verifying all legitimate sending sources, move to enforcement.

Resources

Need help setting up email authentication for your domain? Playful Sparkle has been engineering digital products since 2004, offering Web Development, App Development, and security consulting services. Our team can help you configure SPF, DKIM, DMARC, and BIMI for your domain. Contact us to discuss how we can help you secure your email.

Was this helpful - Post
Zsolt Oroszlány

Zsolt Oroszlány

Founder & Chief Creative Officer of Playful Sparkle since 2004, combining business leadership, digital strategy, design, and software engineering to help organizations build effective digital solutions. Regularly publishes insights on web development, SEO, design, and emerging technologies.