SPF Syntax: The Complete Reference

An SPF record is one TXT string, evaluated left to right, first match wins. Every term is a qualifier glued to a mechanism, plus a couple of modifiers. This is every piece of that grammar.

SPF qualifiers

QualifierMeaning
+Pass (default)
-Hardfail
~Softfail
?Neutral
TermKindLookup?Meaning
v=spf1versionnoRequired first token.
ip4:1.2.3.4mechanismnoMatches that IPv4 (CIDR ranges allowed).
ip6:...mechanismnoMatches an IPv6 address or range.
a / a:domainmechanism1Matches the domain's A/AAAA records.
mx / mx:domainmechanism1Matches the domain's MX hosts' addresses.
include:domainmechanism1Evaluates another domain's SPF; a pass there is a pass here.
exists:domainmechanism1Matches if the name resolves at all (rare, macro use).
ptr / ptr:domainmechanism0Deprecated reverse-DNS match; remove it.
allmechanismnoMatches everything; its qualifier sets the default verdict.
redirect=domainmodifier1Replace evaluation with another domain's record.
exp=textmodifiernoExplanation string for failures; rarely used.

The ip4 and ip6 mechanisms take CIDR ranges, and the CIDR Calculator converts an address range into the exact notation an SPF record expects.

The qualifiers

  • + pass (default when no qualifier is written)
  • - hard fail: receivers should reject
  • ~ soft fail: accept but penalize; the common safe default on ~all
  • ? neutral: no assertion either way

Evaluation in one paragraph

The receiver walks terms left to right against the connecting IP. First mechanism that matches returns its qualifier's verdict and evaluation stops. If nothing matches, all catches the remainder, which is why your terminal qualifier defines your posture. Every include/a/mx/exists/redirect costs one of the 10 permitted lookups; exceeding them returns permerror, a broken record. Test any change with the SPF checker.

Frequently asked questions

What does ~all mean in SPF?+

Softfail: senders failing SPF are marked suspicious but not rejected. -all hardfails them. ~all is the safe choice while tuning; -all is the enforcement choice.

Is +all ever correct?+

No. Plus-pass on everything means any server on earth may send as your domain. It is always a misconfiguration.

What is the difference between a mechanism and a modifier?+

Mechanisms match the sending IP and decide the result; modifiers like redirect= and exp= change evaluation or provide explanations without matching.

Related

Last verified: 2026-11-08