SPF record syntax: mechanisms and qualifiers
What SPF does
SPF (Sender Policy Framework) lets a receiving server ask whether a given IP may send mail for a domain. The domain owner lists authorised sending paths in a DNS TXT record, and the receiver compares the connecting IP with that list. The result is pass, fail, softfail, neutral, none, temperror or permerror.
SPF does not check the From header address. It works from the envelope sender (Return-Path) domain, so a spoofed display name in From is left to DMARC. That is why both records sit side by side.
The shape of a record
A record starts with the version token v=spf1, followed by space-separated terms. Each term is an optional qualifier, a mechanism name, and a colon-prefixed argument.
v=spf1 include:_spf.example.com ip4:192.0.2.10 ip4:198.51.100.0/24 -all
- v=spf1 — the version, which must be the first token.
- include:_spf.example.com — evaluate another domain's SPF and reuse its result; one lookup.
- ip4:192.0.2.10 — authorise a single IPv4 address.
- ip4:198.51.100.0/24 — authorise an IPv4 range; the prefix is 0 to 32.
- -all — fail every sender not matched above.
The eight mechanisms
| Mechanism | Meaning | Lookup |
|---|---|---|
| ip4 | An IPv4 address or range. Fastest and most certain. | none |
| ip6 | An IPv6 address or range; prefix 0 to 128. | none |
| a | Compare the connecting IP with the domain's A and AAAA records; a:example.com/24 is allowed. | one |
| mx | Compare with the domain's MX host addresses; mx:example.com/24 is allowed. | one |
| ptr | Reverse-resolve the connecting IP and compare with the domain. RFC 7208 discourages it. | one |
| exists | Check only that a name exists; often used with macros. | one |
| include | Evaluate another domain's SPF and pass if it passes. Its lookups are added. | one |
| all | Always matches. Place it last. | none |
The four qualifiers
A qualifier precedes a mechanism and sets the result when it matches. Without one, + applies.
| Qualifier | Result | Use |
|---|---|---|
| + | pass | Authorised; the default, so normally omitted. |
| - | fail | Rejected. -all rejects everything not matched. |
| ~ | softfail | Matched but not certain; the receiver may quarantine or accept. |
| ? | neutral | No judgement, effectively no policy. |
+all passes every sender. It is close to having no SPF at all, while looking like a record exists and complicating review. Remove it as soon as it is found.
Modifiers: redirect and exp
Modifiers take no qualifier and use an equals sign. redirect= hands evaluation to another domain's SPF when no all is present; with all present, redirect is ignored. exp= names a domain that explains a failure, and while it does not count toward the ten-lookup limit it does cause a separate DNS lookup.
Ordering and duplicates
- Put all last; terms after it are ignored.
- Use all once per record; twice is a syntax error.
- Order changes the outcome: evaluation stops at the first matching term.
- The same include twice doubles the lookup count for the same result.
255 bytes and string splitting
A single DNS TXT string cannot exceed 255 bytes. A long SPF record is stored as several strings that the receiver concatenates. Some DNS consoles split automatically; others require you to split the quoted strings yourself. The generator in this site calculates that split for you.
Where records usually break
- Writing v=spf 1, v=SPF1 or another spelling. The version token is exactly v=spf1.
- Exceeding ten lookups once the included domains are counted. The limit includes everything inside includes.
- A wrong prefix such as ip4:192.0.2.10/33; IPv4 accepts 0 to 32.
- Leaving a bare a: or mx: with nothing after the colon. It means the current domain but trips syntax checks.
- Splitting the policy across two records, which is permerror by the standard.
After fixing the syntax, confirm the real sending paths from your logs. A valid record still fails when mail leaves through a path it does not authorise. The next guide covers the lookup limit and void lookups in detail.
Questions
Where does the SPF record go?
On the domain's own TXT record. For example.com the value starting with v=spf1 sits on example.com TXT. A subdomain with its own sending policy needs its own record.
What happens with two SPF records on one domain?
RFC 7208 treats more than one TXT record starting with v=spf1 as permerror. Some receivers merge them, but the standard behaviour is an error. Keep exactly one.
Should I use -all or ~all?
If every sending path is known, -all is strongest. During migration, ~all is the safer start: watch the logs, then tighten to -all.
Paste a record into the tool to see how each term is read.
Open the toolThis guide follows RFC 7208 (SPF), RFC 6376 (DKIM), RFC 7489 (DMARC), the BIMI Group specifications and RFC 8617/8616 (ARC and DMARC aggregate reporting). Every example record is synthetic.