An SPF record is a single DNS TXT record that starts with v=spf1, followed by a list of terms read from left to right, and ends with an all mechanism or a redirect modifier. Each term is an optional qualifier (+, -, ~ or ?) plus a mechanism such as ip4, include, a or mx. The first term that matches the connecting IP address decides the result.
This page is a reference for the syntax defined in RFC 7208, with worked examples and the one limit that causes most real-world failures: no more than 10 DNS-querying terms per evaluation. If you want the broader picture of how SPF fits with DKIM and DMARC, start with email authentication explained.
Anatomy of an SPF record
example.com. 3600 IN TXT "v=spf1 ip4:203.0.113.0/24 include:_spf.provider.example mx -all"Reading it left to right: the version tag, an IPv4 range that is authorised directly, a delegation to another domain's SPF record, the domain's own MX hosts, and finally a rule that says everything else should fail. SPF checks the domain in the SMTP envelope sender (MAIL FROM, also called the Return-Path) and, if that is empty, the HELO name. It does not check the visible From address; that is DMARC's job, covered in DMARC alignment. The difference between the two addresses is explained in Return-Path versus From.
Terms are separated by spaces, matching is case-insensitive, and a domain may publish only one SPF record. Publishing two records makes evaluation return a permanent error, which most receivers treat as a failure.
Qualifiers
| Qualifier | Meaning | Result when the term matches |
|---|---|---|
| + (or none) | Pass | Sender is authorised. Written without a symbol in most records |
| - | Fail | Sender is not authorised; the receiver may reject |
| ~ | Softfail | Probably not authorised; accept but treat with suspicion |
| ? | Neutral | No assertion either way |
The qualifier on the final all is the policy statement of the whole record. For the practical difference between -all and ~all, see SPF softfail versus fail. If no term matches and there is no redirect, the result is neutral.
Mechanisms
| Mechanism | What it matches | Counts toward the 10 limit |
|---|---|---|
| all | Always matches; used last as the default | No |
| ip4:address or ip4:range/prefix | The connecting IPv4 address is in the given address or CIDR range | No |
| ip6:address/prefix | The same for IPv6 | No |
| a, a:domain, a/24 | The connecting IP equals an A or AAAA record of the domain, optionally with a CIDR length | Yes |
| mx, mx:domain | The IP equals the address of one of the domain's MX hosts | Yes, plus address lookups for each MX host |
| include:domain | Evaluates the SPF record of another domain; matches only if that evaluation returns pass | Yes, plus everything inside the included record |
| exists:domain | Matches if an A lookup of the (usually macro-expanded) name returns any address | Yes |
| ptr | Reverse lookup of the IP, then forward confirmation. RFC 7208 says not to use it | Yes |
Two points are easy to get wrong. First, include is not a union of records. If the included record returns anything other than pass (including a softfail from its own ~all), the include simply does not match and evaluation continues with the next term. Second, ip4 and ip6 cost nothing in lookups, which is why moving stable addresses into them is the standard way to save budget.
Modifiers
- redirect=domain: when no mechanism matches, replace the current record with the record of another domain and evaluate that instead. It is used instead of
all, never together with it, and it counts as a lookup. It suits many domains that share one policy. - exp=domain: names a TXT record containing an explanation string that can be returned with a fail. It is rarely used and optional.
- Macros: terms such as
%{i}(sending IP) or%{d}(domain) letexistsand others build dynamic names. See SPF macros. Unknown modifiers must be ignored by receivers.
How evaluation works
- The receiver takes the domain from the MAIL FROM address (or the HELO name when MAIL FROM is empty) and fetches its TXT records.
- It keeps records that begin with
v=spf1. Zero records give a result of none; more than one gives a permanent error. - It evaluates the terms in order. For each mechanism it tests whether the connecting IP matches.
- The first match returns the term's qualifier as the result. Later terms are never examined.
- If nothing matches,
redirectis followed if present, otherwise the result is neutral.
This is why all must come last: anything written after it is unreachable. It is also why order matters for performance, since putting cheap ip4 terms first avoids unnecessary lookups for most mail.
Worked examples
| Situation | Record |
|---|---|
| Domain sends only from its own MX hosts | v=spf1 mx -all |
| Sends only through one provider | v=spf1 include:_spf.provider.example -all |
| Own server plus a provider, testing | v=spf1 ip4:198.51.100.25 include:_spf.provider.example ~all |
| Two providers and an IPv6 host | v=spf1 ip6:2001:db8::/48 include:_spf.one.example include:_spf.two.example -all |
| Subdomain that shares the main policy | v=spf1 redirect=_spf.example.com |
| Domain that never sends email | v=spf1 -all |
The domains in the examples are reserved documentation names. Replace them with the exact include value your provider publishes; copy it from their documentation rather than guessing. If several vendors send for you, managing multiple senders covers how to keep one record valid. For domains that never send, see parked domain records.
The 10 lookup limit
RFC 7208 section 4.6.4 limits the terms that cause DNS queries (include, a, mx, ptr, exists and the redirect modifier) to 10 per evaluation, counted across nested includes. Exceeding it produces a permanent error (PermError), and most receivers then treat the message as unauthenticated. A separate rule allows at most two lookups that return no data (void lookups) before a PermError is raised, and each mx term may resolve at most 10 host names.
Count carefully: an include that points to a record with three more includes costs four. Large senders chain several levels. For the full counting method and repair options, read the PermError fix guide, and for the technique of replacing includes with literal addresses, SPF flattening.
Size and formatting rules
- A single DNS character-string is limited to 255 characters. Longer records are split into several quoted strings inside one TXT record, and receivers join them without adding spaces. Most DNS panels do this for you; see TXT length and registrar quirks.
- Keep the total response small enough to travel over UDP (commonly kept well under 512 bytes of answer data) where you can. Very large records risk truncation and TCP fallback.
- Use straight ASCII quotes and no line breaks in the value. Smart quotes pasted from a document break the record.
- Do not put the record on
wwwor other hosts unless they appear in an envelope sender; SPF is looked up on the exact domain used.
Test your record
# Fetch the record
dig +short TXT example.com
# Check that only one v=spf1 record exists
dig +short TXT example.com | grep -c "v=spf1"
# Follow an include to see what it contains
dig +short TXT _spf.provider.example
# Inspect the SPF result on a delivered message
# Look for: Received-SPF or Authentication-Results: spf=pass smtp.mailfrom=...For a full evaluation including lookup counts, use the SPF, DKIM and DMARC checker. More background on testing is in checking and fixing SPF errors.
Common errors
| Symptom | Likely cause | Fix |
|---|---|---|
| PermError: multiple SPF records | Two TXT records start with v=spf1 | Merge them into one record |
| PermError: too many lookups | More than 10 DNS-querying terms | Remove unused includes, use ip4/ip6, split senders across subdomains |
| Everything fails after editing | Typo such as a missing colon in include or a stray space | Re-read each term; test with dig |
| Provider mail still fails | Provider sends with its own bounce domain, so your SPF is not the domain checked | Use the provider's custom return-path setup. See custom return path |
| Pass in SPF but DMARC fails | Envelope domain differs from the From domain | Align the Return-Path or rely on aligned DKIM |
| Record ignored | Published on the wrong name or as an SPF-type RR | Publish as TXT on the exact domain; the old SPF RR type is obsolete |
When to use which mechanism
Prefer ip4 and ip6 for infrastructure you control, include for third-party senders who publish their own record, and avoid ptr entirely. Use mx and a only if your mail really leaves from those hosts, because they are lookups and they authorise more than you may intend. Finish with -all once you have confirmed every legitimate sender, or ~all while you are still discovering them.
If you send through a relay such as MigoSMTP, you publish the include value shown in your account's DNS setup instead of listing its addresses by hand.
Check your SPF record in seconds Run the free checker to see your record, the lookup count and any syntax errors.
References and further reading
Frequently asked questions
What is the basic syntax of an SPF record?
It is a TXT record that starts with v=spf1, followed by mechanisms such as ip4, include, a and mx, and ends with all or redirect. Each mechanism may have a qualifier (+, -, ~ or ?).
What is the difference between -all and ~all?
-all tells receivers that unlisted senders should fail, while ~all marks them as softfail, a weaker statement. Many domains use ~all during rollout and move to -all once every sender is listed.
What is the SPF 10 lookup limit?
A single evaluation may cause at most 10 DNS-querying terms (include, a, mx, ptr, exists, redirect), counted through nested includes. Exceeding it returns a PermError.
Can a domain have more than one SPF record?
No. Multiple v=spf1 TXT records cause a permanent error, so all senders must be merged into one record.
Do ip4 and ip6 count toward the lookup limit?
No. They are matched without any DNS query, so they are the cheapest way to authorise known addresses.