How do you create an SPF record?
To create an SPF record, list every service that sends mail with your domain in the envelope sender, collect each provider's documented include: or IP range, combine them into one TXT record that starts with v=spf1 and ends with ~all or -all, count the DNS lookups (10 maximum), publish it at the domain apex and verify it.
SPF (Sender Policy Framework) is defined in RFC 7208. The record is short; the work is getting the sender list right first, because a missing sender fails SPF and a broken record fails it for everyone. For background on how SPF works, start with the SPF guide and what SPF is and why it matters for DMARC. The SPF syntax reference covers every term.
Key takeaways
- Build the sender inventory first. The record is only as good as the list of services you found.
- Publish exactly one record per name. Two
v=spf1records at the same name make SPF returnpermerrorfor all mail. - Count lookups before publishing:
include,a,mx,ptr,existsandredirectcount, nested includes count, and the limit is 10. - Use
~allon sending domains while you are still discovering senders, andv=spf1 -allon domains that never send mail. - Every sending subdomain needs its own record. A record on the apex does not cover
mail.example.com.
What do you need before you start?
You need access to the domain's DNS host, a list of every system that sends mail as the domain, and each provider's own SPF documentation. You also need a way to query DNS (dig, nslookup or PowerShell) and, ideally, a DMARC record already collecting aggregate reports so you can see senders you missed.
Check first whether a record already exists: creating a second record next to an old one is the most common way a "new" SPF record breaks mail. If you find an existing v=spf1 record, you are editing it, not creating one, and multiple SPF records and how to merge them applies.
dig +short TXT example.com
If the output contains a string that starts with v=spf1, the domain already has SPF. If it contains two, fix that before anything else.
Step 1: Which services send email as your domain?
Every service that puts your domain in the SMTP envelope sender (the Return-Path, also called MAIL FROM) must be in the record. That usually means the mailbox platform plus a handful of third parties: marketing, CRM, ticketing, invoicing, HR, website forms, scanners and on-premises applications.
The UK National Cyber Security Centre (NCSC) advises asking every department, not just IT. Its create and iterate an SPF record guidance says to "consult all departments across your organisation and ask" about third-party mailing agents. In practice, finance and marketing are where the forgotten senders live.
Build the inventory from several sources, not one:
- The mailbox platform. Microsoft 365, Google Workspace or another hosted provider.
- Billing and SaaS lists. Anything the client pays for that sends mail: newsletters, CRM, helpdesk, e-signature, accounting.
- The network. Devices or servers that relay through the office IP, such as multifunction printers and line-of-business applications.
- Existing DMARC aggregate reports. If the domain already publishes DMARC at
p=none, the reports list every source that sent as the domain, including the ones nobody mentioned. See DMARC aggregate reports explained.
Also note whether each sender uses your domain in the envelope sender at all. Many platforms use their own bounce domain and authenticate your From address with DKIM; those do not need an include.
Step 2: How do you find each provider's SPF include?
Take the value from the provider's own documentation, not from another company's example. The NCSC warns that you "cannot just 'copy and paste'" values and "will need to check with your supplier to find the exact value in your case." Providers change hostnames, regions and recommended records.
Two common examples, verified on the providers' own pages:
| Provider | Include value | Source |
|---|---|---|
| Microsoft 365 (commercial and GCC) | include:spf.protection.outlook.com |
Microsoft Learn: Set up SPF |
| Microsoft 365 GCC High and DoD | include:spf.protection.office365.us |
Same page |
| Microsoft 365 operated by 21Vianet | include:spf.protection.partner.outlook.cn |
Same page |
| Google Workspace | include:_spf.google.com |
Google Workspace: Set up SPF |
For a fixed server, such as an on-premises relay, use ip4: or ip6: with its public address or range. Those cost no DNS lookups. Avoid a and mx unless you really mean "whatever those DNS records point to today", because each one costs a lookup and changes silently when someone edits DNS. Provider-specific detail is in the Microsoft 365 SPF record explained and the Google Workspace SPF record explained.
Step 3: How do you build the SPF record string?
Start with v=spf1, add one term per authorised source separated by single spaces, and finish with one all term. RFC 7208 Section 4.5 says receivers discard records that do not begin with exactly v=spf1, and Section 5.1 says terms after all are ignored, so the order is fixed at both ends.
The structure is always:
v=spf1 [ip4:/ip6: ranges] [include: providers] [~all or -all]
Put ip4 and ip6 terms early: receivers evaluate left to right and stop at the first match, and IP terms need no DNS query. Then list the includes, and end with a single all.
A worked example for a client using Microsoft 365, one email marketing platform, one helpdesk tool and an on-premises scanner relay:
v=spf1 ip4:203.0.113.25 include:spf.protection.outlook.com include:spf.marketing.example include:mail.helpdesk.example ~all
The two .example includes are placeholders. Replace them with the values from your providers' documentation. The IP address is from the documentation range in RFC 5737.
The NCSC notes that "SPF syntax is very sensitive to white space" and recommends a colleague checks the draft before it goes live. Watch for doubled spaces, smart quotes pasted from a word processor, a missing colon after include, and a stray second v=spf1 in the middle.
Step 4: How do you count DNS lookups before publishing?
Count every term that triggers a DNS query, including those inside each include, and keep the total at 10 or fewer. RFC 7208 Section 4.6.4 counts include, a, mx, ptr, exists and the redirect modifier. ip4, ip6, all and exp do not count. Exceeding 10 produces permerror.
Microsoft's guidance makes the trap explicit: "having fewer than 10 include: statements doesn't guarantee fewer than 10 DNS lookups", because nested includes count too. So expand each include and count what is inside it.
dig +short TXT spf.protection.outlook.com
dig +short TXT _spf.google.com
When we queried public resolvers on 20 November 2026, both records contained only ip4 and ip6 ranges and an all term, so each costs one lookup. The providers control those records and can restructure them, so recount at every audit rather than hard-coding the figure.
The lookup budget for the worked example:
| Term | Counts? | Lookups (illustrative) | Running total |
|---|---|---|---|
ip4:203.0.113.25 |
No | 0 | 0 |
include:spf.protection.outlook.com |
Yes | 1 (flat record, measured November 2026) | 1 |
include:spf.marketing.example |
Yes | 1 plus 2 nested includes = 3 | 4 |
include:mail.helpdesk.example |
Yes | 1 plus 1 nested include = 2 | 6 |
~all |
No | 0 | 6 |
Six of ten leaves room for the next SaaS tool a client buys. RFC 7208 Section 4.6.4 also says implementations "SHOULD limit 'void lookups' to two": a void lookup is a query that returns no records or a non-existent domain, so an include pointing at a retired provider hostname is both wasted budget and a potential error. If you are already over the limit, read SPF too many DNS lookups before reaching for SPF flattening.
Step 5: Should the record end in ~all or -all?
End sending domains in ~all (softfail) while you are still discovering senders, and use v=spf1 -all (hardfail) on domains that never send. Once DMARC is enforced, both endings mean "not pass" to DMARC; the difference is that some receivers reject on SPF fail before DMARC runs.
The providers disagree, which tells you both are defensible. Google says "Google recommends you use ~all in your SPF record." Microsoft recommends -all for Microsoft 365 domains "because we also recommend DKIM and DMARC for the domain." Microsoft also describes ?all as for testing and not recommended in production. Never use +all: it authorises every IP address on the internet.
| Domain situation | Ending | Reason |
|---|---|---|
Sending domain, new record, DMARC at p=none |
~all |
A sender you missed should not bounce while you find it in reports |
| Sending domain, DMARC enforced, aligned DKIM on all sources | ~all or -all |
DMARC does the enforcing; -all can cause early rejection of forwarded mail |
| Microsoft 365 tenant following Microsoft's guidance | -all |
Microsoft's stated recommendation; enable DKIM first |
| Parked or non-sending domain | v=spf1 -all |
Nothing is authorised, so say so plainly |
The full trade-off is in SPF softfail vs hardfail with DMARC.
Step 6: How do you publish the SPF record in DNS?
Create a single TXT record at the domain apex (shown as @ or left blank in most DNS panels) with the full string as the value. Do not create an SPF-type record: TXT is the record type receivers query. If a value already exists, edit it rather than adding a second record.
The fields in a typical DNS panel:
| Field | Value |
|---|---|
| Type | TXT |
| Host / Name | @ (or the domain itself, depending on the panel) |
| Value | v=spf1 ip4:203.0.113.25 include:spf.protection.outlook.com ... ~all |
| TTL | 3600 seconds (one hour) |
Microsoft recommends "a minimum TTL value of 3600 seconds (one hour) on SPF TXT records". During a change window you can lower the TTL a day ahead so a mistake is quick to correct, then raise it again. Google notes that "it can take up to 48 hours for SPF authentication to start working", so do not judge the result in the first few minutes.
Long records. A single TXT string is limited to 255 characters. If your record is longer, the DNS host splits it into several quoted strings inside one TXT record, and RFC 7208 Section 3.3 says receivers concatenate them "without adding spaces". That is one record, not two, but it means the space between terms must sit inside one of the strings. RFC 7208 Section 3.4 also advises keeping the DNS answer within 512 octets, and the NCSC sets a practical ceiling of 450 bytes.
Do subdomains and parked domains need their own record?
Yes. SPF is checked against the exact domain in the envelope sender, and a subdomain does not inherit the apex record. Microsoft states that "the SPF TXT record for contoso.com doesn't cover marketing.contoso.com"; Google says "you must add an SPF record for each subdomain." Domains that never send should publish v=spf1 -all.
Three cases come up in every client estate:
- Sending subdomains. A bulk mail platform sending from
news.example.comneeds a record atnews.example.comwith only that platform's include. This also keeps its lookups out of the apex budget, which is why the NCSC suggests subdomains to "overcome the 450 bytes and maximum of 10 DNS lookup restrictions." See subdomain or separate domain for bulk email. - Parked and defensive domains. Publish
v=spf1 -allat the apex. GOV.UK's protect domains that don't send email guidance gives that exact value, alongside a null MX and a reject DMARC policy. RFC 7208 calls this "a well-established best practice." Our guide on whether parked domains should have a DMARC record covers the full set. - Host names that send. RFC 7208 Section 2.3 recommends that receivers also check the HELO identity. A server that announces itself as
mail.example.combenefits from a record at that name authorising its own IP.
Step 7: How do you verify the published record?
Query the record from outside your network and confirm there is exactly one string starting with v=spf1, with the exact text you intended. Use whichever tool is to hand; all three below ask for TXT records at the apex.
dig +short TXT example.com
nslookup -type=TXT example.com
Resolve-DnsName -Name example.com -Type TXT
Check four things in the output:
- One, and only one, value starts with
v=spf1. - The text matches your draft character for character, including spaces.
- Each include resolves: run
dig +short TXTon every included hostname and confirm it returns a record. - The expanded lookup count is 10 or fewer. Our SPF analyzer expands nested includes and counts them for you.
For the full verification routine, including void lookups and reading results in Gmail and Outlook, see how to check your SPF record.
Step 8: How do you confirm SPF passes on real mail?
Send a test message from each source to a mailbox you control at an external provider, open the full headers and read the SPF result. You want spf=pass with smtp.mailfrom showing your domain, or a Received-SPF: pass line. Repeat for every sender in the inventory.
A passing result in an Authentication-Results header (illustrative values; the format is defined in RFC 8601 Section 2.7.2):
Authentication-Results: mx.receiver.example;
spf=pass (sender IP is 203.0.113.25) smtp.mailfrom=example.com;
dkim=pass header.d=example.com;
dmarc=pass header.from=example.com
Some receivers add a Received-SPF trace field instead or as well. RFC 7208 Section 9.1 defines it and limits the result to pass, fail, softfail, neutral, none, temperror or permerror. If you see permerror, the record is broken (two records, too many lookups or a syntax error). If you see softfail or fail for a legitimate source, that source is missing or is sending from an IP its include does not cover.
If smtp.mailfrom shows the provider's bounce domain rather than yours, SPF is passing for the provider, not for you, and DMARC alignment depends on DKIM.
How does the new SPF record interact with DMARC?
DMARC only counts SPF when it passes and the envelope sender domain aligns with the visible From domain. RFC 9989 Section 3.2.4 says "DMARC relies solely on SPF validation of the MAIL FROM identity", and alignment is relaxed by default (aspf=r), so a subdomain of the same organisational domain aligns.
That has two practical consequences for the record you just built. First, a third-party sender that uses its own bounce domain will pass SPF without helping DMARC; configure aligned DKIM for it instead, and you may not need its include at all. Second, softfail and fail are both "not pass" to DMARC, so the qualifier choice in Step 5 is mostly about receivers that act on SPF alone. Why DMARC fails when SPF passes walks through the alignment cases, and how SPF, DKIM and DMARC work together shows the full picture.
Step 9: How do you monitor the record after publishing?
Watch DMARC aggregate reports for at least a few weeks. They show every IP that sent as the domain, whether SPF passed and whether it aligned. A legitimate source failing SPF is a missing include; an unknown source failing is the spoofing DMARC is there to stop.
If the domain has no DMARC record yet, publish one at p=none with a reporting address now, following how to create a DMARC record step by step. Under RFC 9989, rollout then moves from p=none to p=quarantine to p=reject once every legitimate source passes with alignment. Aggregate report format is defined in RFC 9990.
DMARC AI is a multi-tenant DMARC platform for MSPs that processes aggregate reports and uses AI to classify sending sources, which makes the "is this a forgotten sender or an attacker?" question faster to answer across many domains.
What are the most common mistakes when creating an SPF record?
Most failures come from five mistakes: a second record, too many lookups, a copied include, a missed sender, and +all or no all. Each is easy to spot with a DNS query and a header check, and far cheaper to prevent before publishing than to diagnose from bounce messages.
| Mistake | Result | Fix |
|---|---|---|
| Adding a new record next to an existing one | permerror for all mail (RFC 7208 Section 4.5) |
Merge into one record |
| More than 10 DNS-querying terms, including nested ones | permerror |
Remove unused senders, move some to DKIM or a subdomain |
| Copying an include from a blog or another client | Wrong or retired hostname, void lookups | Take the value from the provider's documentation |
| Forgetting a sender (scanner, invoicing tool) | SPF fail for that source | Inventory first; read DMARC reports |
Using +all or omitting all |
Anyone authorised, or neutral for everything | End with ~all or -all |
| No record on a sending subdomain | SPF none for that subdomain |
Publish a record at the subdomain |
How should an MSP roll SPF out across a client portfolio?
Treat SPF as a repeatable runbook, not a one-off DNS edit. Use the same inventory template, lookup budget and verification checks for every client, record each sender and its owner, and schedule a recount whenever a client adds a SaaS tool or changes mail platform.
A routine that scales across dozens or hundreds of domains:
- Snapshot first. Export current TXT records for every client domain so every edit can be reversed.
- Classify each domain. Sending, sending subdomain, or parked. Parked domains get
v=spf1 -alland a reject DMARC policy in one pass. - Inventory per client, including anything the DMARC reports reveal.
- Budget lookups. Record the expanded count per domain and flag anything above eight for review.
- Change in a window. Lower TTL a day ahead, publish, verify with
dig, send test mail from each source, then restore the TTL. - Monitor and recount. Review aggregate reports weekly during rollout, and recount includes at each quarterly review, since providers restructure their records.
For the ongoing hygiene rules after creation, see SPF record best practices.
FAQ
Can I create an SPF record without knowing every sender?
You can, but end it with ~all and publish DMARC at p=none at the same time. The aggregate reports will show the senders you missed, and softfail means those senders are flagged rather than bounced while you add them. Do not move to -all or DMARC enforcement until the reports show every legitimate source passing.
Where do I add the SPF record in DNS?
Add it as a TXT record at the domain apex, usually written as @ in the DNS host's panel, with the full v=spf1 ... ~all string as the value. Use the panel of whoever hosts the domain's DNS, which may differ from the registrar or the mail provider. Do not add a second TXT record starting with v=spf1.
How long does a new SPF record take to work?
A new record is usually visible within minutes on resolvers that have not cached the name, but cached answers persist until their TTL expires. Google says it can take up to 48 hours for SPF authentication to start working. Verify with dig or Resolve-DnsName, then confirm with real test messages before relying on it.
Can I have more than one SPF record on a domain?
No. RFC 7208 says a domain must not have multiple SPF records, and if a receiver finds more than one it returns permerror, so SPF fails for every message. Combine all senders into one record. A subdomain is a different name, so a record at news.example.com is not a second record for example.com.
What SPF record should a domain that sends no email have?
Publish v=spf1 -all as a TXT record at the apex. It states that no server is authorised to send for the domain, so receivers can fail any message claiming to come from it. GOV.UK guidance pairs it with a null MX record and a DMARC record at p=reject for complete protection.