Sender Policy Framework (SPF) is an email authentication method that helps receiving mail servers determine whether a server is authorized to send email for a particular domain. SPF works by publishing a specially formatted TXT record in a domain's DNS.
Understanding SPF record syntax is important because even a small configuration mistake can cause authentication failures, increase the risk of spoofing, or affect email deliverability. SPF records use mechanisms, qualifiers, modifiers, IP addresses, domains, and other components to define which sending sources are authorized.
What Is SPF Record Syntax?
SPF record syntax is the structured format used to define an SPF policy in a domain's DNS TXT record. An SPF record normally begins with v=spf1, which identifies the record as an SPF version 1 policy.
A basic SPF record may look like this:
v=spf1 ip4:192.0.2.10 -all
In this example:
v=spf1 identifies the SPF version.
ip4:192.0.2.10 authorizes the specified IPv4 address.
-all tells receiving servers that other sending sources are not authorized.
An SPF record can contain multiple mechanisms and modifiers. Each mechanism determines whether a sending IP address matches a particular authorization rule.
What Are the Main Parts of an SPF Record?
An SPF record can contain several types of components. The most important are:
SPF version
Mechanisms
Qualifiers
Modifiers
IP addresses
Domain names
The final all mechanism
A typical record combines several of these elements:
v=spf1 ip4:192.0.2.10 include:example.com ~all
Here, the domain authorizes one IPv4 address, includes another domain's SPF policy, and uses a soft fail for all other sources.
What Are SPF Mechanisms?
SPF mechanisms are components that identify authorized or unauthorized sending sources. A receiving mail server evaluates these mechanisms against the IP address of the server sending the message.
The main SPF mechanisms include:
all
ip4
ip6
a
mx
include
exists
ptr
The ptr mechanism is obsolete and should not be used in new SPF records.
all Mechanism
The all mechanism matches every IP address that reaches it during SPF evaluation.
It is commonly placed at the end of an SPF record to establish the default result for sources that did not match an earlier mechanism.
Example:
v=spf1 ip4:192.0.2.10 -all
The first mechanism authorizes 192.0.2.10. The -all mechanism applies to other sources.
The qualifier attached to all determines the result:
-all
~all
?all
+all
Using +all effectively authorizes every IPv4 and IPv6 sender and is generally not appropriate for a restrictive SPF policy.
ip4 Mechanism
The ip4 mechanism authorizes an IPv4 address or IPv4 network.
Single IP example:
v=spf1 ip4:192.0.2.10 -all
CIDR range example:
v=spf1 ip4:192.0.2.0/24 -all
The /24 indicates an IPv4 network range.
Multiple IPv4 addresses can also be included:
v=spf1 ip4:192.0.2.10 ip4:198.51.100.25 -all
Only use IP addresses that actually belong to authorized email-sending infrastructure.
ip6 Mechanism
The ip6 mechanism works similarly but is used for IPv6 addresses and networks.
Example:
v=spf1 ip6:2001:db8::1 -all
An IPv6 CIDR range can also be specified:
v=spf1 ip6:2001:db8::/32 -all
If your organization sends email through IPv6 infrastructure, the relevant IPv6 addresses or ranges may need to be included.
a Mechanism
The a mechanism authorizes IP addresses associated with the domain's DNS A or AAAA records.
For example:
v=spf1 a -all
This means the IP addresses returned for the domain's relevant A or AAAA records can match the SPF mechanism.
A specific domain can also be referenced:
v=spf1 a:mail.example.com -all
The mechanism can also use a CIDR suffix to restrict the matching range.
mx Mechanism
The mx mechanism authorizes the IP addresses associated with the domain's MX records.
Example:
v=spf1 mx -all
This can be useful when the same mail-related infrastructure represented by the MX records also sends outbound email.
However, an MX record primarily identifies where a domain receives email. It does not automatically mean those servers send outbound email. Therefore, only use mx when the MX hosts are actually authorized senders.
include Mechanism
The include mechanism allows a domain to incorporate another domain's SPF policy.
Example:
v=spf1 include:spf.example.com -all
This is commonly used when a third-party email service sends messages on behalf of your domain.
For example, a simplified setup might look like:
v=spf1 include:emailprovider.example -all
The receiving server evaluates the referenced domain's SPF policy when processing the include.
A key point is that include does not simply copy the other domain's text into your record. It performs an SPF evaluation of the referenced policy and can produce a match when that evaluation returns the required result.
exists Mechanism
The exists mechanism performs a DNS lookup for a specified domain name.
Example:
v=spf1 exists:%{i}.spf.example.com -all
It can use SPF macros to construct a domain name based on information from the SMTP transaction.
exists is more advanced than common mechanisms such as ip4 and include and is usually unnecessary for basic SPF configurations.
ptr Mechanism
The ptr mechanism is part of older SPF syntax but has been deprecated because of reliability and DNS lookup concerns.
Example of legacy syntax:
v=spf1 ptr -all
New SPF records should not use ptr.
What Are SPF Qualifiers?
SPF qualifiers determine the result associated with a matching mechanism.
There are four primary qualifiers:
The default qualifier is + if no qualifier is explicitly written.
For example:
ip4:192.0.2.10
is equivalent to:
+ip4:192.0.2.10
What Does + Mean in SPF?
The + qualifier produces an SPF Pass when the associated mechanism matches.
Example:
v=spf1 +ip4:192.0.2.10 -all
The + is usually omitted because it is the default:
v=spf1 ip4:192.0.2.10 -all
What Does - Mean in SPF?
The - qualifier produces an SPF Fail when the mechanism matches.
The most common example is:
-all
This is often used as the final mechanism to state that sources not authorized by earlier mechanisms should fail SPF.
Example:
v=spf1 ip4:192.0.2.10 -all
What Does ~ Mean in SPF?
The ~ qualifier produces a SoftFail.
Example:
v=spf1 ip4:192.0.2.10 ~all
This indicates that other sources are not authorized, but the domain is not making the strongest possible SPF failure statement.
SoftFail is sometimes used while an SPF configuration is being tested or transitioned. However, the appropriate policy depends on the domain's email infrastructure and operational requirements.
What Does ? Mean in SPF?
The ? qualifier produces a Neutral result.
Example:
v=spf1 ip4:192.0.2.10 ?all
A Neutral result does not state that the sender is authorized or unauthorized.
It is generally less useful as a final enforcement policy because it provides little information about unauthorized sources.
What Are SPF Modifiers?
Modifiers provide additional instructions or information that are different from ordinary SPF mechanisms.
The two standardized SPF modifiers are:
redirect
exp
redirect Modifier
The redirect modifier can send SPF evaluation to another domain when no mechanism in the current record produces a result.
Example:
v=spf1 ip4:192.0.2.10 redirect=spf.example.com
If the preceding mechanisms do not determine an SPF result, evaluation can be redirected to the SPF record at the specified domain.
redirect is useful in certain centralized SPF configurations but should be used carefully because SPF policies can become difficult to understand when multiple domains and redirects are involved.
exp Modifier
The exp modifier specifies a domain containing an explanation string that can be associated with an SPF failure.
Example:
v=spf1 ip4:192.0.2.10 -all exp=explain.example.com
The exp modifier is uncommon in modern SPF configurations.
What Is a Complete SPF Record Example?
Consider this SPF record:
v=spf1 ip4:192.0.2.10 ip4:198.51.100.20 include:spf.mailservice.example -all
It contains several components:
v=spf1 identifies SPF version 1.
ip4:192.0.2.10 authorizes one IPv4 address.
ip4:198.51.100.20 authorizes another IPv4 address.
include:spf.mailservice.example allows the referenced SPF policy to authorize additional sending infrastructure.
-all produces SPF Fail for sources that do not match the preceding mechanisms.
The exact mechanisms should always reflect the domain's real sending infrastructure.
Common SPF Record Syntax Examples
Example 1: One IPv4 Address
v=spf1 ip4:192.0.2.10 -all
This authorizes one IPv4 address and fails other sources.
Example 2: Multiple IPv4 Addresses
v=spf1 ip4:192.0.2.10 ip4:198.51.100.20 -all
This authorizes two IPv4 addresses.
Example 3: IPv6 Sender
v=spf1 ip6:2001:db8::1 -all
This authorizes the specified IPv6 address.
Example 4: Third-Party Email Provider
v=spf1 include:spf.emailprovider.example -all
This delegates part of the authorization decision to the referenced SPF domain.
Example 5: Company Server and Third-Party Platform
v=spf1 ip4:192.0.2.10 include:spf.emailprovider.example -all
This authorizes both the specified server and the sending infrastructure represented by the included SPF policy.
Example 6: Using an MX Mechanism
v=spf1 mx -all
This authorizes IP addresses associated with the domain's MX records.
Example 7: Using an A Mechanism
v=spf1 a -all
This authorizes IP addresses returned by the relevant A or AAAA records.
Example 8: SoftFail Policy
v=spf1 ip4:192.0.2.10 ~all
This authorizes the specified IPv4 address and produces SoftFail for unmatched sources.
Example 9: IPv4 Network
v=spf1 ip4:192.0.2.0/24 -all
This authorizes the specified IPv4 network range.
Example 10: Multiple Authorization Methods
v=spf1 ip4:192.0.2.10 ip6:2001:db8::1 a mx include:spf.example.com -all
This demonstrates several SPF mechanisms in one record. In a real deployment, each mechanism should have a specific purpose and should only represent legitimate sending infrastructure.
How Does SPF Evaluate a Record?
SPF evaluation generally starts with the first mechanism after v=spf1 and proceeds from left to right.
Consider:
v=spf1 ip4:192.0.2.10 include:spf.example.com -all
A simplified evaluation process is:
The receiving server identifies the domain used for SPF evaluation.
It retrieves the domain's SPF record through DNS.
It checks the ip4 mechanism.
If the sender's IP matches, the evaluation produces the result associated with that mechanism.
If it does not match, evaluation continues.
The include mechanism is evaluated if necessary.
If no earlier mechanism matches, -all establishes the final result.
SPF evaluation therefore depends on both record syntax and the order of mechanisms.
What Are Common SPF Syntax Errors?
Several configuration mistakes can cause SPF problems.
Publishing Multiple SPF Records
Publishing multiple v=spf1 TXT records at the same DNS name can cause SPF PermError.
Use one consolidated SPF policy instead.
Missing v=spf1
An SPF record needs the appropriate version declaration:
v=spf1
Authorizing the Wrong IP Address
If the sending server's IP is not represented by an appropriate SPF mechanism, the message may fail SPF.
Incorrect include
The domain after include: must be a valid SPF policy domain.
Incorrect:
v=spf1 include:my-email-service -all
if my-email-service is not the SPF domain supplied by the provider.
Exceeding the DNS Lookup Limit
Complex chains of include, a, mx, exists, or redirect mechanisms can exceed the SPF lookup limit.
Using Obsolete ptr
The ptr mechanism should not be used in new SPF records.
Adding Unsupported Text
SPF records must follow SPF syntax. Random descriptions or comments should not be added to the policy.
How Do You Check SPF Record Syntax?
You can check an SPF record by querying the domain's DNS TXT records and then evaluating the policy.
A basic validation process should check:
Whether an SPF record exists.
Whether it starts with v=spf1.
Whether only one SPF record is published.
Whether authorized sending sources are correctly represented.
Whether included domains have valid SPF records.
Whether the policy exceeds the DNS lookup limit.
Whether mechanisms use valid syntax.
Whether the final policy matches the organization's intended email configuration.
A dedicated SPF checker can make these checks easier, especially for records containing several third-party services.
Why Choose EmailGuard for SPF Record Validation and Email Authentication?
EmailGuard helps businesses check whether their SPF configuration is set up correctly and identify issues that can affect email authentication. Its tools can check SPF records alongside other essential email authentication elements, including DKIM and DMARC, helping users detect configuration problems such as missing or invalid records. This makes it useful for reviewing SPF syntax, authorized sending sources, and authentication setup before they cause avoidable delivery problems.
EmailGuard also provides email security and deliverability monitoring features that help businesses keep track of their domain authentication and sending infrastructure. By regularly checking SPF and related authentication records, businesses can identify changes or configuration issues and take corrective action. This makes EmailGuard a practical option for teams that want a straightforward way to monitor core email authentication requirements.
Can an SPF record contain spaces?
Yes, SPF mechanisms are separated by spaces within the TXT record. For example:
v=spf1 ip4:192.0.2.10 include:spf.example.com -all
The spaces separate the individual SPF terms.
Can SPF records use CIDR notation?
Yes, the ip4 and ip6 mechanisms support CIDR notation for authorizing IP address ranges. For example, ip4:192.0.2.0/24 represents an IPv4 network range.
What happens when no SPF mechanism matches?
If no earlier mechanism matches, SPF evaluation can reach the all mechanism. Its qualifier determines the resulting SPF status, such as Pass, Fail, SoftFail, or Neutral.
Does the order of SPF mechanisms matter?
Yes, SPF mechanisms are evaluated in sequence. Once a mechanism matches, the associated qualifier determines the result and later mechanisms are generally not evaluated.
Can SPF authorize a whole IP range?
Yes, CIDR notation can be used with ip4 and ip6 to authorize a network range. The range should only contain IP addresses that are genuinely authorized to send email for the domain.
What is a soft fail in SPF?
A SoftFail occurs when an SPF mechanism with the ~ qualifier matches. The domain indicates that the sender is probably not authorized, but the result is less definitive than an SPF Fail.