An SPF record is a DNS TXT record with the shape v=spf1 [mechanisms] [qualifier]all. Mechanisms identify authorized sending sources; qualifiers (+, -, ~, ?) define what happens when a source matches or misses. Evaluation proceeds left to right and stops at the first match. The all mechanism, always last, catches everything that did not match earlier. Getting the syntax right matters: a malformed or over-budget record produces a permerror, which can cause authentication failures that push mail to spam regardless of your content or sending reputation. The full specification is RFC 7208.
For the bigger picture on how SPF fits alongside DKIM and DMARC, see What Is Email Authentication? SPF, DKIM, and DMARC Explained.
The Anatomy of an SPF Record
Every valid SPF record follows this structure:
v=spf1 [mechanism ...] [qualifier]all
Here is a realistic record for a domain that sends via Google Workspace and one additional ESP, annotated token by token:
v=spf1 include:_spf.google.com include:mail.example-esp.com ip4:203.0.113.5 -all
│ │ │ │ │
│ └── mechanism: authorize └── mechanism: authorize └── mechanism: └── default:
│ Google's sending IPs the ESP's sending IPs single IP reject all
│ address others
└── version tag (required, always "spf1")
| Token | Role |
|---|---|
v=spf1 | Version tag. Required. Must be first. Only spf1 is defined. |
include:_spf.google.com | Mechanism: recursively checks Google’s own SPF record |
include:mail.example-esp.com | Mechanism: recursively checks ESP’s SPF record |
ip4:203.0.113.5 | Mechanism: authorizes one specific IPv4 address |
-all | Qualifier + mechanism: hard-fail anything not matched above |
Only one SPF TXT record is allowed per domain or subdomain. Per RFC 7208, Section 3.2, a domain “MUST NOT have multiple records that would cause an authorization check to select more than one record.” Two SPF records on the same domain returns permerror immediately.
SPF Mechanisms: What Each One Does
Mechanisms test whether the sending IP matches a given condition. RFC 7208, Section 5 defines eight mechanisms.
| Mechanism | What it matches | Counts toward 10-lookup limit? |
|---|---|---|
ip4: | A specific IPv4 address or CIDR range (e.g., ip4:192.0.2.0/24) | No |
ip6: | A specific IPv6 address or CIDR range | No |
a | The A/AAAA records of a domain (defaults to the sending domain) | Yes |
mx | The A records of the domain’s MX hosts | Yes |
include:domain | Recursively evaluates domain‘s SPF record | Yes |
exists:domain | Performs an A lookup on a constructed domain name | Yes |
ptr | Reverse-DNS hostname of the sending IP | Yes (avoid) |
all | Always matches; catches everything | No |
ip4 and ip6
The simplest mechanisms: list an IP address or CIDR block. They do not trigger DNS lookups and do not count toward the 10-lookup limit, making them the most efficient way to authorize dedicated sending IPs you control.
v=spf1 ip4:192.0.2.10 ip4:198.51.100.0/24 ip6:2001:db8::/32 -all
include
include:domain tells the evaluating server to fetch and evaluate domain‘s SPF record. If that check returns pass, the mechanism matches. This is how ESPs and cloud mail providers authorize senders: they publish their IP ranges under their own domain, and you add one include: pointing to it. Each include: costs one DNS lookup, and nested include: chains add more.
a and mx
a matches if the sending IP equals any A or AAAA record of the specified domain (or the current domain if no domain is given). mx matches if the sending IP belongs to any of the domain’s mail exchange hosts. Both trigger DNS lookups. Avoid mx if your MX records point to hosts that are separate from your sending infrastructure. Per RFC 7208, Section 4.6.4, each mx mechanism may also not result in “querying more than 10 address records”.
exists
exists:domain performs an A lookup on a domain name built from a macro, which is a placeholder such as %{i} that the receiving server replaces with the connecting IP address at evaluation time. For example, exists:%{i}._spf.example.com matches only if a record exists for that IP under _spf.example.com. It is mainly useful for macro-based SPF records at scale. One lookup per use.
ptr (avoid)
ptr performs a reverse-DNS lookup on the sending IP, then a forward lookup to verify the hostname ends in the specified domain. RFC 7208, Section 5.5 is explicit: “This mechanism SHOULD NOT be published.” The reason given: “This mechanism is slow, it is not as reliable as other mechanisms in cases of DNS errors, and it places a large burden on the .arpa name servers.” Use ip4:, ip6:, or include: instead. The mechanism is unrelated to publishing reverse DNS for your sending IPs, which is covered in PTR records for email.
Modifiers: redirect= and exp=
Modifiers look like mechanisms but use an equals sign and are not tested against the sending IP. Two are defined. redirect=domain hands evaluation to another domain’s SPF record and costs one DNS lookup. Per RFC 7208, Section 6.1, “Any “redirect” modifier MUST be ignored if there is an “all” mechanism anywhere in the record,” so use it in place of all, for example to share one policy across several domains. exp=domain points to a TXT record holding an explanation string that receivers can show when a message fails.
Per RFC 7208, Section 6, “Unrecognized modifiers MUST be ignored no matter where, or how often, they appear in a record.” That is why a typo like include=domain does not raise an error: it is read as an unknown modifier, silently ignored, and the sender it was meant to authorize fails SPF.
If a record has no all mechanism and no redirect, RFC 7208, Section 4.7 says the result is “neutral, just as if “?all” were specified as the last directive.”
Qualifiers: Controlling What Happens on a Match
Every mechanism can be prefixed with a qualifier. The qualifier controls the result returned when that mechanism matches. Per RFC 7208, Section 4.6.2, + is the default when no qualifier is written.
| Qualifier | Result | What receiving servers do | Typical use |
|---|---|---|---|
+ | Pass | Accept the message | Default; rarely written explicitly |
- | Fail | Reject the message | Hard enforcement (-all) |
~ | SoftFail | Accept but flag (spam folder likely) | Testing; cautious enforcement (~all) |
? | Neutral | No specific action | Testing only; never use in production |
A record with no qualifier on a mechanism is identical to one with +:
# These two are equivalent:
v=spf1 include:_spf.google.com -all
v=spf1 +include:_spf.google.com -all
-all vs ~all: The Decision That Matters Most
The all mechanism always matches. Placing it last means it catches every sending source not authorized by an earlier mechanism. The qualifier you pair with all determines how aggressively unauthorized sources are treated.
-all (hard fail): The sending IP is not authorized. Receiving servers should reject the message outright. Microsoft Defender for Office 365 documentation recommends -all when you also deploy DKIM and DMARC, because DMARC can then act on SPF failures to enforce your policy.
~all (soft fail): The sending IP is probably not authorized. Receiving servers typically accept the message but route it to the spam or junk folder. This is the default recommendation from Google Workspace’s SPF setup guide. It leaves room for mailing lists, forwarding, and misconfigured legacy servers to get through during a transition.
?all (neutral): No action is specified. Receiving servers can do anything. This is suitable only for testing, not for production records.
Which should you choose? Start with ~all while you audit your sending sources and verify DMARC alignment. Once you are confident every legitimate sender is covered, switching to -all provides stronger enforcement. With DMARC in place, the practical difference narrows: DMARC applies the domain owner’s published policy (p=reject or p=quarantine) regardless of whether SPF returned fail or softfail. Without DMARC, -all is the only mechanism that can trigger a hard rejection at the SPF layer.
+all (pass all) is never appropriate in production. It authorizes every server on the internet to send mail as your domain.
The 10 DNS Lookup Limit
RFC 7208, Section 4.6.4 states: “SPF implementations MUST limit the total number of those terms to 10 during SPF evaluation, to avoid unreasonable load on the DNS.” Exceeding 10 lookups produces a permerror, which receiving servers treat as an authentication failure, not a temporary one.
The same section adds: “SPF implementations SHOULD limit ‘void lookups’ to two.” A void lookup is a DNS query that returns zero records (RCODE 0 with no answers) or an NXDOMAIN. The limit is two, and the same section says “Exceeding the limit produces a “permerror” result,” so the first two void lookups are tolerated and the third fails the evaluation.
What is an SPF void lookup?
An SPF void lookup is a DNS query made during SPF evaluation that returns no records or NXDOMAIN. RFC 7208 allows two. A third produces a permerror, so the whole SPF check fails even if every other mechanism is correct.
Common causes:
- An
include:pointing at a decommissioned vendor domain - A typo in an
include:target aormxon a host with no A/AAAA or MX recordsexists:on a name that never resolves
What counts toward the 10-lookup limit
As Microsoft’s SPF documentation confirms, the following mechanisms each cost one lookup:
include:amxexistsredirect(a modifier, not a mechanism, but it counts)ptr(another reason to avoid it)
These do NOT count:
ip4:andip6:values- The
allmechanism
Nested include: chains multiply quickly. An include:_spf.google.com lookup resolves to a record that may itself contain additional include: statements, each adding to your total. The number of DNS lookups is not the same as the number of include: lines in your record.
What common senders cost in lookups
The number of lookups depends on how each provider publishes its record, and it changes. We checked each include target with dig TXT in November 2026 (checked November 27, 2026) and counted the include: term itself plus everything nested under it:
| Service | Include value | Total lookups | Record flat? |
|---|---|---|---|
| Google Workspace | include:_spf.google.com | 1 | Yes |
| Microsoft 365 | include:spf.protection.outlook.com | 1 | Yes |
| Amazon SES | include:amazonses.com | 1 | Yes |
| Mailchimp | include:servers.mcsv.net | 1 | Yes |
| Zendesk | include:mail.zendesk.com | 1 | Yes |
| SendGrid | include:sendgrid.net | 2 | No (nests ab.sendgrid.net) |
| Salesforce | include:_spf.salesforce.com | 2 | No (the record uses exists:%{i}._spf.mta.salesforce.com) |
| Mailgun | include:mailgun.org | 5 | No (nests four more includes) |
Google’s include is a flat list of IP ranges today, which contradicts the older figure of several lookups that many guides still repeat. Treat the table as a snapshot: re-run dig before relying on it.
A real over-budget scenario
Take a domain that authorizes Google Workspace (1), Salesforce (2), Mailgun (5), Mailchimp (1) and Zendesk (1). That adds up to exactly 10, which is still within the limit. Add Microsoft 365 as a sixth source (1 more) and the total is 11. The evaluating server stops, returns permerror, and SPF no longer authorizes any message from that domain. DMARC can then only pass through DKIM, so mail survives only if it carries a valid DKIM signature aligned with the From domain.
SPF flattening: the workaround and its tradeoffs
Flattening replaces include: mechanisms with the actual IP addresses they resolve to, reducing DNS lookups to zero (since ip4: and ip6: never count). The result is a long record with dozens of IP addresses instead of a short record with a few include: lines.
The tradeoff: cloud mail providers change their sending IP ranges without notice. A flattened record that was correct in January may fail in March when the provider rotates subnets. Microsoft’s own documentation explicitly warns against flattening include:spf.protection.outlook.com because “Microsoft’s sending infrastructure uses dynamic IP addresses that change frequently.” The same applies to any large cloud provider.
If you must flatten, document which include: entries you replaced, monitor the provider’s changelog, and review the record at least quarterly.
Long records and multiple strings
A single DNS TXT string holds at most 255 octets, and flattened records outgrow that quickly. RFC 7208, Section 3.3 allows a record to be split into several quoted strings, and receivers treat them “as if those strings are concatenated together without adding spaces.” So the space between terms must sit inside one of the strings, not between them:
"v=spf1 ip4:192.0.2.0/24 ip4:198.51.100.0/24 " "ip4:203.0.113.0/24 -all"
Here the space after 198.51.100.0/24 is the last character of the first string. Drop it and the two terms fuse into an invalid token. Per Section 3.4, records should also remain small enough that a query’s results “fit within 512 octets.” Most DNS panels split long strings for you, so check how yours stores them.
A cleaner alternative to flattening: move non-essential sending sources to subdomains. Each subdomain gets its own SPF record with its own 10-lookup budget.
Common Syntax Errors
Two SPF records on one domain. The most common mistake. Any domain with two TXT records that both start with v=spf1 returns permerror. Delete or merge them.
Exceeding 10 lookups. Usually caused by adding an ESP include: without auditing the total. Count them before deploying changes, using the steps below.
+all or ?all in production. Either authorizes or ignores sources that should be rejected. Always use -all or ~all.
Missing include: for a sending service. SPF is checked against the MAIL FROM domain, also called the Return-Path, not the visible From address. An ESP’s include: therefore belongs in the SPF record of whichever domain the ESP uses as MAIL FROM. Many ESPs set that to a bounce subdomain, or to a domain they host themselves, and in that case your root record never needs their include. If the service does send with your root domain as MAIL FROM and you do not include its SPF domain, its messages fail SPF and likely fail DMARC alignment too. Check with each sending service for the correct include: value. For example, ESPs like Coldletter provide an include: value in their documentation that you add to your record.
Doubled domain names from DNS panels. A trailing dot after a domain, as in include:spf.protection.outlook.com., is valid: the grammar in RFC 7208, Section 7.1 defines domain-end = ( "." toplabel [ "." ] ). The real risk is a DNS panel that auto-appends your zone name, which turns a name into spf.protection.outlook.com.example.com. Check what the panel actually saved.
Equal sign instead of colon. include=domain is wrong. include:domain is correct. Because unknown modifiers are ignored, the record stays valid and the include simply never happens.
How to check your SPF record
- Run
dig +short TXT yourdomain.comand find the single record starting withv=spf1. - Run
dig +short TXTon eachinclude:target and anyredirect=target, then on every include nested inside those. Add one for eachinclude,a,mx,ptr,existsandredirectterm. The total must be 10 or fewer. If you manage DNS in Cloudflare, publishing DNS TXT records there follows the same steps as DKIM. - Send a test message to a mailbox you control and look for
spf=passin theAuthentication-Resultsheader. For the other half of the picture, see how to read DMARC reports.
Real-World Example Records
Google Workspace only
v=spf1 include:_spf.google.com -all
Per Google’s SPF setup documentation, _spf.google.com is the include value for Google Workspace. The -all is added here; Google’s own guide defaults to ~all.
Microsoft 365 only
v=spf1 include:spf.protection.outlook.com -all
Per Microsoft Defender for Office 365 documentation, this is the correct record for a custom domain using Microsoft 365 for all outbound mail.
Mixed environment: Microsoft 365, an ESP, and a dedicated IP
v=spf1 ip4:203.0.113.42 include:spf.protection.outlook.com include:mail.esp-domain.com ~all
This record uses three mechanisms: a dedicated IP for transactional mail, Microsoft 365 for employee email, and a third-party ESP for marketing campaigns. Lookup count: 2, assuming the ESP’s record is flat (the two include: entries; ip4: is free).
Domain that sends no mail (parked domain)
v=spf1 -all
No mechanisms, just a hard fail. This tells every receiving server that no source is authorized to send email for this domain. Every parked or unused domain should have this record to prevent spoofing.
How SPF Feeds DMARC Alignment
SPF checks the MAIL FROM (also called the envelope sender or Return-Path) domain, not the From header your recipient sees. For SPF to contribute to DMARC alignment, the domain in the MAIL FROM must match the organizational domain in the visible From header. When it does, DMARC treats the SPF result as “aligned.” When it does not (common with forwarding or mailing lists), DMARC falls back to DKIM alignment.
Many ESPs set the MAIL FROM to their own domain by default, so SPF passes but does not align with your From domain until you configure a custom return-path. Understanding this relationship is covered in detail in How to Set Up DMARC (Step-by-Step Guide). The short version: SPF alone does not protect the From address your recipients see. SPF plus DMARC does. For how authentication problems affect deliverability and sender reputation, SPF correctness is table stakes.
Frequently Asked Questions
What does -all vs ~all mean in an SPF record?
-all is a hard fail: unlisted sources should be rejected. ~all is a soft fail: unlisted sources are accepted but typically flagged as spam. With DMARC in place the difference narrows, because DMARC applies your published policy either way. Start with ~all while auditing your senders, then switch to -all once the record is complete.
How many DNS lookups can an SPF record have?
Ten. RFC 7208, Section 4.6.4 counts include:, a, mx, ptr, exists and redirect; ip4:, ip6: and all are free. The same section limits void lookups (queries returning no records) to two. An 11th lookup or a third void lookup produces a permerror.
Can I have two SPF records on one domain?
No. RFC 7208, Section 3.2 states that a domain “MUST NOT have multiple records that would cause an authorization check to select more than one record.” If two TXT records starting with v=spf1 exist on the same domain, SPF evaluation immediately returns permerror. Merge all your mechanisms into a single record and delete the duplicate.
What does include: do in an SPF record?
include:domain runs an SPF check against domain‘s own record. If that check passes, the mechanism matches and the sending IP is authorized. ESPs publish their IP ranges under their own domain, and you reference them with one include:. Each include: costs one lookup, plus any lookups nested inside the referenced record.
Why should I avoid the ptr mechanism?
RFC 7208, Section 5.5 states: “This mechanism SHOULD NOT be published.” The spec explains it is “slow, it is not as reliable as other mechanisms in cases of DNS errors, and it places a large burden on the .arpa name servers.” Use ip4:, ip6:, or include: instead to reliably authorize your sending sources.
What is SPF flattening and when should I use it?
Flattening replaces include: mechanisms with the resolved IP addresses, so lookups drop to zero. It is a workaround for the 10-lookup limit, but providers change IPs without notice and a flattened record can silently break. Never flatten include:spf.protection.outlook.com. Safer options: move non-critical senders to subdomains, each with its own 10-lookup budget, or authorize fewer services.
I’ve spent my career building software at scale with a soft spot for email: deliverability, lifecycle campaigns, and getting messages to actually land. I started Coldletter to fix what bugged me about transactional and marketing email tools. I’m based in Vancouver.
