Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

SPF Record Meaning & How It Stops Email Spoofing

· 7 min read · Home Tech

In this article
  1. What Exactly Is an SPF Record?
  2. How SPF Prevents Spoofing (Step by Step)
  3. SPF Record Syntax and Mechanisms
  4. Common Mistakes and How to Avoid Them
  5. SPF vs. DKIM vs. DMARC
  6. How to Create and Publish an SPF Record
  7. Limitations and What SPF Can’t Do
  8. Frequently Asked Questions

An SPF (Sender Policy Framework) record is a DNS (Domain Name System) text entry that lists which mail servers are allowed to send email for your domain. When you set up SPF, you publish a list of approved IP addresses or hostnames. Receiving mail servers check this list whenever a message claims to come from your domain, and if the sending server isn't on it, the message can be rejected or flagged as spam. This article explains what SPF records contain, how the check works step by step, and why it is only one part of a complete anti-spoofing strategy.

What Exactly Is an SPF Record?

SPF is defined in RFC 7208 (the current standard, updated from the earlier RFC 4408). It is a DNS record of type TXT that sits in your domain's DNS zone. A typical SPF record looks like this:

v=spf1 ip4:192.0.2.10 include:_spf.example.net -all

Breaking that down:

  • v=spf1 – identifies the version of SPF (there is only one in use).
  • ip4:192.0.2.10 – allows that specific IPv4 address to send mail.
  • include:_spf.example.net – tells the checker to also look at the SPF record of that other domain (often used for third-party senders like email marketing services).
  • -all – means “if the sender isn’t listed above, fail the check.” This is the strictest ending. A softer version is ~all (softfail, mark as suspicious but don’t reject).

The record is published as a plain TXT record, not a special SPF record type (the old SPF RR type was deprecated). You can have only one SPF record per domain – if you add a second, receiving servers may reject both or merge them unpredictably.

How SPF Prevents Spoofing (Step by Step)

SPF works by verifying the envelope sender – the address used in the SMTP transaction, which is usually the “Return-Path” or “MAIL FROM” address. This is not always the same as the “From” address you see in your email client. The check happens in four steps:

  1. You send an email from smtp.yourdomain.com with a Return-Path of bounce@yourdomain.com.
  2. The receiving mail server looks up the SPF record for yourdomain.com.
  3. It compares the IP address of the connecting server (e.g., 192.0.2.10) against the list in the SPF record.
  4. If the IP matches an allowed entry, SPF passes. If not, the result is a fail (or softfail, depending on the -all vs ~all).

This prevents a spammer from sending email that claims to be from your domain using their own server, because their IP won’t be in your SPF record. However, SPF alone cannot stop all spoofing – it only checks the envelope, not the visible “From” header. A spammer can still put your domain in the “From” line while using their own domain in the Return-Path, and SPF will pass for their domain, not yours. That’s why SPF is usually combined with DKIM and DMARC.

SPF Record Syntax and Mechanisms

An SPF record is built from mechanisms and qualifiers. Each mechanism tells the checker what to do if a match is found. The main mechanisms are:

  • ip4: – allows a specific IPv4 address or CIDR range (e.g., ip4:203.0.113.0/24).
  • ip6: – same for IPv6.
  • include: – pulls in another domain’s SPF record (useful for third-party senders).
  • a – allows the IP addresses of your domain’s A record (and optionally a hostname like a:mail.example.com).
  • mx – allows the IPs of your domain’s MX records (your mail servers).
  • ptr – deprecated, rarely used, and not recommended.
  • exists – allows if a given domain resolves (used for special cases).

Each mechanism can have a qualifier prefix: + (pass, default), - (fail), ~ (softfail), or ? (neutral). The -all at the end is the most common strict policy, but many organizations start with ~all to avoid breaking legitimate mail.

Common Mistakes and How to Avoid Them

SPF is easy to get wrong, and a mistake can cause legitimate email to be rejected. The most frequent issues are:

  • Multiple SPF records: You can only have one. If you have more than one, receiving servers may return a “permerror” and treat all mail as failing.
  • Too many DNS lookups: SPF allows a maximum of 10 DNS lookups (each include, a, mx, or ptr counts). If you exceed 10, the record is invalid and fails.
  • Using +all: This allows any server to send mail for your domain – effectively disabling SPF. You should never use +all unless you don’t care about spoofing.
  • Forgetting third-party senders: If you use a service like SendGrid or Mailchimp, you must include their SPF record via include:, or their mail will fail SPF.
  • Not updating after changing mail providers: If you move your email to a new provider, update the SPF record immediately, or your outgoing mail will be rejected.

To check your SPF record, you can use a DNS lookup tool like dig TXT yourdomain.com or an online SPF validator. Always test after making changes.

SPF vs. DKIM vs. DMARC

SPF is often confused with DKIM (DomainKeys Identified Mail) and DMARC (Domain-based Message Authentication, Reporting, and Conformance). They work together but do different things:

  • SPF verifies the envelope sender’s IP address.
  • DKIM uses a digital signature to verify that the message content wasn’t altered and that it came from the claimed domain (the “From” domain).
  • DMARC tells receiving servers what to do if both SPF and DKIM fail, and it also aligns the “From” domain with the authenticated domains.

SPF alone is insufficient because it doesn’t check the “From” header. DMARC requires that either SPF or DKIM passes and aligns with the domain in the “From” address. So the recommended setup is: publish SPF and DKIM, then add a DMARC policy that says “reject” (or at least “quarantine”) when both fail. This combination is the industry standard for preventing domain spoofing.

How to Create and Publish an SPF Record

Creating an SPF record is a matter of writing a single line of text and adding it to your DNS. Here’s a practical approach:

  1. List all the mail servers that legitimately send email for your domain. This includes your own SMTP server, your email hosting provider, and any third-party services (like a newsletter service).
  2. Write the record starting with v=spf1, then add each mechanism. For example: v=spf1 ip4:192.0.2.10 include:_spf.thirdparty.com -all.
  3. Log into your DNS provider (where you manage your domain’s DNS, e.g., your registrar or hosting company).
  4. Add a new TXT record with the hostname set to your domain (often left blank or @) and the value set to your SPF string.
  5. Wait for DNS propagation (usually up to 48 hours) and then test with an SPF checker.

If you’re not sure what to include, start with ~all (softfail) and monitor your email logs for a few weeks. Once you’re confident, switch to -all (hardfail).

Limitations and What SPF Can’t Do

SPF has several limitations that you should know:

  • It doesn’t protect against subdomain spoofing: SPF for example.com does not cover sub.example.com unless you publish a separate record for that subdomain.
  • It breaks with email forwarding: When a message is forwarded, the forwarding server may change the envelope sender, causing SPF to fail even if the original was legitimate. This is why some mailing lists and forwarders use SRS (Sender Rewriting Scheme).
  • It doesn’t encrypt or sign anything: SPF only checks IP addresses, not content.
  • It can be bypassed by using a different domain: A spammer can spoof a domain that has no SPF record, or use a lookalike domain.

Despite these limits, SPF remains a fundamental part of email authentication. It blocks the simplest and most common spoofing attacks, and it’s required for DMARC to work properly.

Frequently Asked Questions

What does “SPF” stand for?

SPF stands for Sender Policy Framework. It was originally proposed in 2003 and standardized in 2006 as RFC 4408, then updated in 2014 as RFC 7208.

Can I have more than one SPF record?

No. You should have exactly one SPF TXT record per domain. If you have multiple, receiving servers may return a permanent error (permerror) and treat all mail as failing SPF. If you need to add more allowed senders, edit the existing record.

What is the difference between -all and ~all?

-all means “hardfail” – if the sending server isn’t in the list, the email fails SPF and is typically rejected. ~all means “softfail” – the email is marked as suspicious but not rejected. Most experts recommend starting with ~all to avoid losing legitimate mail, then moving to -all after testing.

How do I check my SPF record?

You can use a command-line tool like dig TXT yourdomain.com (on Linux/macOS) or nslookup -type=TXT yourdomain.com (on Windows). There are also many free online SPF checkers that will validate the syntax and count DNS lookups.

Is SPF enough to stop email spoofing?

No. SPF only checks the envelope sender, not the “From” header that users see. To fully prevent spoofing, you need SPF plus DKIM and DMARC. DMARC ensures that the “From” domain matches the authenticated domains and tells receivers what to do if authentication fails.

What happens if my SPF record has more than 10 DNS lookups?

The record is considered invalid, and receiving servers will return a “permerror” – meaning SPF fails for all your mail. You can reduce lookups by consolidating includes, using IP addresses instead of hostnames, or removing unnecessary mechanisms.