schedule 6-min read

SPF (Sender Policy Framework)

A complete guide to Sender Policy Framework — what SPF is, how to publish an SPF record, every SPF mechanism explained, and how to avoid the 10-lookup DNS limit.

01

tips_and_updates
Key Takeaways

01

SPF lets a domain owner publish, in DNS, exactly which mail servers are authorized to send mail on the domain’s behalf.

02

Every include, a, mx, ptr, and exists mechanism counts toward a hard limit of 10 DNS lookups per SPF check.

03

SPF alone cannot guarantee rejection of spoofed mail — it must be paired with DKIM and a DMARC policy to actually block forgeries.

04

Audit your SPF record after every change to your sending stack; an outdated record silently breaks deliverability for new vendors.

02

What is SPF (Sender Policy Framework)?

Sender Policy Framework (SPF) is a DNS-based email authentication standard defined in RFC 7208. It lets the owner of a domain publish a list of IP addresses and hostnames that are allowed to send email using that domain in the MAIL FROM (envelope sender) address. When a receiving mail server gets an incoming message, it looks up the sender’s SPF record in DNS and checks whether the connecting IP appears on the authorized list. If it doesn’t, the SPF check fails and the message is treated according to the domain’s policy — typically marked as spam or rejected outright.

SPF is one of the three foundational email authentication protocols, alongside DKIM and DMARC. On its own SPF cannot stop a determined attacker — it doesn’t sign message content, doesn’t survive automatic forwarding, and only inspects the envelope sender — but it remains an essential first layer because it is cheap, fast, and supported by every receiving provider on the planet.

03

How an SPF check actually works

When a mail server on the receiving side processes an incoming SMTP connection, it inspects the envelope sender (the MAIL FROM address) and pulls the domain portion out of it. It then issues a DNS TXT query for that domain and looks for a record beginning with v=spf1. The mechanisms inside the record are evaluated left-to-right against the connecting IP, and the first match wins. If no mechanism matches, the trailing all qualifier decides the outcome.

04

Publishing your first SPF record

An SPF record is a single DNS TXT record at the apex of your domain. Most domains only need a few mechanisms — one to authorize your primary email provider, one or two to cover transactional or marketing senders, and a closing policy. A minimal record for a domain that sends through Google Workspace and SendGrid looks like this:

SPF record example

v=spf1 include:_spf.google.com include:sendgrid.net ~all

Publish the record, wait for DNS propagation, then validate it with the SPF analyzer before adding it to your live sending domain.

05

SPF mechanisms reference

SPF records are built from a small vocabulary of mechanisms. Each mechanism either matches the connecting IP (a “hit”) or doesn’t. The qualifiers + (pass, the default), - (fail), ~ (soft-fail), and ? (neutral) determine how a hit is treated. The mechanisms below are the complete set defined by RFC 7208:

ip4IPv4 address or CIDR range
Authorizes a literal IPv4 address (ip4:203.0.113.5) or CIDR block (ip4:203.0.113.0/24). Costs zero DNS lookups, so it is the most efficient way to list your own outbound mail servers.

ip6IPv6 address or CIDR range
The IPv6 equivalent of ip4. Use it for every mail server reachable over IPv6 — receivers will check the address family that they connected on.

aA / AAAA record match
Authorizes the IP addresses returned by an A or AAAA lookup of the named host (defaulting to the current domain). Counts as one DNS lookup against the 10-lookup limit.

mxInbound MX hosts
Authorizes any host listed in the domain’s MX records. Useful when your inbound and outbound infrastructure share the same servers; otherwise prefer a more precise mechanism.

includeDelegate to another domain
Imports the SPF policy of another domain — for example include:_spf.google.com. Each include consumes one DNS lookup and may trigger nested lookups inside it.

existsMacro-based existence check
Passes if the named host resolves to any IP. Almost always seen with macros (e.g. exists:%{i}.zen.spamhaus.org) for advanced policy logic.

ptrReverse-DNS match (deprecated)
Performs a reverse-DNS lookup of the connecting IP and matches if the result is the listed domain. RFC 7208 explicitly recommends not using ptr — it is slow, fragile, and many receivers ignore it.

~allSoft fail
The closing policy used while you are still observing traffic. Unauthorized senders are flagged but usually still delivered to the inbox.

-allHard fail
The strict closing policy. Receivers are expected to reject mail that doesn’t match an earlier mechanism. Use this once you are confident every legitimate sender is covered.

06

The four SPF problems we see most

Almost every broken SPF record we troubleshoot falls into one of the same four buckets. Watch for each of these whenever you make a change to your sending stack.

  • Too many DNS lookups. RFC 7208 caps an SPF evaluation at 10 DNS lookups. Each include, a, mx, ptr and exists mechanism costs one — and nested includes count too. Exceed it and the receiver returns permerror, which most providers treat as a hard fail.
  • The 255-character string limit. A single TXT string is capped at 255 characters. Records longer than that must be split into multiple concatenated strings inside the same TXT record. DNS providers handle this differently — verify with dig +short TXT.
  • Forgotten third-party senders. Adding a new vendor (HubSpot, Mailchimp, Zendesk, an ATS) without updating SPF is the most common cause of sudden deliverability drops. Add the vendor’s include mechanism the day you sign the contract.
  • Alignment confusion. SPF authenticates the envelope sender domain (Return-Path), not the visible From: header. DMARC requires the two to align. A vendor whose envelope sender is on their own domain (e.g. [email protected]) will pass SPF but fail DMARC alignment.
07

SPF best practices

  • Start with ~all, then graduate. Soft-fail mode lets you observe DMARC aggregate reports for a couple of weeks before you flip the switch to -all.
  • Audit quarterly. Every signed vendor contract, every new transactional service, and every retired tool should trigger a review of the SPF record.
  • Flatten only when forced to. SPF flattening tools resolve include chains into static IP lists. They reduce lookups but require monitoring — vendor IP ranges change without notice.
  • Layer SPF with DKIM and DMARC. SPF answers “is the connecting IP allowed?” — DKIM answers “was the body tampered with?” — DMARC answers “did either of those pass and align with the From: header?”. You need all three.
  • Validate before you ship. Use the SPF analyzer to lint your record, count your DNS lookups, and spot every common mistake before it hits production.
08

Next steps

With SPF in place, your domain has a published list of authorized senders. The next layers in the email-authentication stack are DKIM for message-content integrity, and DMARC for policy enforcement and reporting.

01 Insight

Are You Using Sender Policy Framework (SPF) to Mitigate Email Spoofing?

Since the late 1990s, commercial organizations have increasingly struggled with email impersonation. To combat spammers attempting to send emails on behalf of your domain, the Sender Policy Framework (SPF) was developed as a vital email authentication technique. If your organization sends emails from its own email domain, implementing SPF is highly advisable. Sender Policy Framework (SPF) is a protocol designed to restrict the unauthorized distribution of spam or other false content from your name. When your domain falls victim to spoofing, cybercriminals exploit it to send fraudulent emails, primarily targeting recipients with spam and phishing attempts to deceive and potentially harm your organization’s reputation. By enabling the Sender Policy Framework (SPF) protocol, you establish rules that verify whether an email genuinely originates from your authorized email systems. This verification process helps prevent malicious actors from using your domain to distribute harmful content. When combined with the standards DKIM (DomainKeys Identified Mail) and DMARC (Domain-based Message Authentication, Reporting & Conformance), SPF creates a robust defense mechanism that effectively stops spoofing attempts in your name. Implementing SPF not only enhances your email security by ensuring that only authorized servers can send emails on behalf of your domain but also improves your email deliverability and protects your brand reputation from being tarnished by fraudulent activities. Don’t let cybercriminals exploit your email domain—activate Sender Policy Framework (SPF) today to secure your email communications and safeguard your organization against spam, phishing, and other malicious email threats.

Are You Using Sender Policy Framework (SPF) to Mitigate Email Spoofing?
02 Insight

Enhance Your Email Security with Sender Policy Framework (SPF)

Implementing the Sender Policy Framework (SPF) protocol is essential for verifying that emails genuinely originate from your organization and preventing the misuse of your email address. By adding an SPF record to your DNS (Domain Name System), you specify which email systems, based on their IP addresses, are authorized to send emails on behalf of your domain. Emails sent from unauthorized servers will be flagged as suspicious and blocked by spam filters, ensuring that malicious attempts like phishing and spoofing are effectively mitigated. This is particularly important if your domain has previously been targeted by spoofing, as unauthorized use can lead to your domain being blocked by other companies and organizations, hindering the delivery of your legitimate emails. Your SPF record should include the IP addresses of all authorized email servers within your organization. When an email is received, the recipient’s mail server compares the “Envelope from” address (the Return-Path header) with the SPF record in your DNS before processing the entire message. If the sending server is not listed in your SPF record, the email is marked as suspicious and may be rejected, thereby protecting your domain’s integrity and ensuring the reliability of your email communications. Implementing SPF, alongside DKIM and DMARC, provides a robust defense against email-based threats, enhancing your overall email security and safeguarding your organization’s reputation.

Enhance Your Email Security with Sender Policy Framework (SPF)
03 Insight

DMARC AI Helps Your Email Comply with SPF Protocol

Implementing the Sender Policy Framework (SPF) protocol is now virtually standard practice for optimally protecting your mail servers. SPF aims to reduce email spoofing and spam by verifying whether the sender of an email is authorized to send on behalf of your domain. Since configuring such a protocol is a technical task that requires expertise, you can rely on the experts at DMARC AI to handle it for you. We go beyond simply setting up SPF for your domain; we address its limitations, such as the restriction that an SPF record should not contain more than ten IP addresses. With our advanced tools and extensive knowledge, we ensure your SPF record is properly configured in accordance with SPF standards. At DMARC AI, we view SPF as one crucial component of a comprehensive email security strategy, and to fully protect your organization, we also ensure that DKIM and DMARC are correctly implemented. Additionally, we offer to review the remaining settings of your mail domain to identify and eliminate any potential vulnerabilities, thereby optimizing your overall email security.

Secure Your Email Domain with DMARC AI’s Expert Solutions. Contact Us Today!

DMARC AI Helps Your Email Comply with SPF Protocol

Ready to Implement?

Get authenticated mail moving in minutes — start free, book a guided demo, or talk to the team about your stack.