New guide: how to warm up a dedicated IP without hurting your reputation. Read now →
Log in
MigoSMTP
Domains and DNSUpdated 4 Nov 2026

SPF record syntax: mechanisms, qualifiers, examples and the 10 lookup limit

A precise reference to SPF record syntax: every mechanism and modifier, the four qualifiers, how evaluation works, worked examples for common setups, and the DNS lookup limit that breaks records that grow too large.

KW
Written by Kenji Watanabe
HTML Email Developer
Reviewed by Valentina Reyes
  • Published25 Jun 2024
  • Read time7 min
  • Length1,462 words
Share this guide

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.

Record formatOne TXT record per domain, beginning v=spf1 and ending in all or redirect
Qualifiers+ pass (default), - fail, ~ softfail, ? neutral
Lookup limit10 terms that cause DNS queries: include, a, mx, ptr, exists and redirect
Void lookupsMore than 2 lookups returning no data also produce a permanent error

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

QualifierMeaningResult when the term matches
+ (or none)PassSender is authorised. Written without a symbol in most records
-FailSender is not authorised; the receiver may reject
~SoftfailProbably not authorised; accept but treat with suspicion
?NeutralNo 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

MechanismWhat it matchesCounts toward the 10 limit
allAlways matches; used last as the defaultNo
ip4:address or ip4:range/prefixThe connecting IPv4 address is in the given address or CIDR rangeNo
ip6:address/prefixThe same for IPv6No
a, a:domain, a/24The connecting IP equals an A or AAAA record of the domain, optionally with a CIDR lengthYes
mx, mx:domainThe IP equals the address of one of the domain's MX hostsYes, plus address lookups for each MX host
include:domainEvaluates the SPF record of another domain; matches only if that evaluation returns passYes, plus everything inside the included record
exists:domainMatches if an A lookup of the (usually macro-expanded) name returns any addressYes
ptrReverse lookup of the IP, then forward confirmation. RFC 7208 says not to use itYes

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) let exists and others build dynamic names. See SPF macros. Unknown modifiers must be ignored by receivers.

How evaluation works

  1. The receiver takes the domain from the MAIL FROM address (or the HELO name when MAIL FROM is empty) and fetches its TXT records.
  2. It keeps records that begin with v=spf1. Zero records give a result of none; more than one gives a permanent error.
  3. It evaluates the terms in order. For each mechanism it tests whether the connecting IP matches.
  4. The first match returns the term's qualifier as the result. Later terms are never examined.
  5. If nothing matches, redirect is 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

SituationRecord
Domain sends only from its own MX hostsv=spf1 mx -all
Sends only through one providerv=spf1 include:_spf.provider.example -all
Own server plus a provider, testingv=spf1 ip4:198.51.100.25 include:_spf.provider.example ~all
Two providers and an IPv6 hostv=spf1 ip6:2001:db8::/48 include:_spf.one.example include:_spf.two.example -all
Subdomain that shares the main policyv=spf1 redirect=_spf.example.com
Domain that never sends emailv=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 www or 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

SymptomLikely causeFix
PermError: multiple SPF recordsTwo TXT records start with v=spf1Merge them into one record
PermError: too many lookupsMore than 10 DNS-querying termsRemove unused includes, use ip4/ip6, split senders across subdomains
Everything fails after editingTypo such as a missing colon in include or a stray spaceRe-read each term; test with dig
Provider mail still failsProvider sends with its own bounce domain, so your SPF is not the domain checkedUse the provider's custom return-path setup. See custom return path
Pass in SPF but DMARC failsEnvelope domain differs from the From domainAlign the Return-Path or rely on aligned DKIM
Record ignoredPublished on the wrong name or as an SPF-type RRPublish 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.

Open the SPF checker

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.

Topics#spf#dns#syntax#authentication#lookup limit
Was this guide helpful?Your answer helps us improve our documentation.

Start sending in minutes.

Create an account, add your domain and send your first email.

Get started Talk to sales