What Is SPF and How Do You Set It Up?
SPF is a DNS record that lists which servers may send email for your domain. Learn how to write it, test it and avoid the mistakes that break it.
10 min readUpdated Nov 22, 2026By XPASS Editorial Team

Every message sent over the internet passes through servers that anyone can configure. SPF, short for Sender Policy Framework, is one of the simplest tools for telling the world which servers are allowed to send mail for your domain. It is a single line in DNS, but getting that line right takes some care, and a small mistake can quietly hurt your deliverability.
This guide explains what SPF does, how to write and publish a record, how to test it, and which mistakes cause the most trouble. It also shows how SPF fits with DKIM and DMARC, because SPF alone is only part of the picture.
What SPF does
SPF is defined in RFC 7208. A domain owner publishes a TXT record listing the sources that may send mail on behalf of the domain. When a receiving server accepts a message, it checks the sending server's IP address against that list.
The important detail is which domain SPF checks. It checks the domain used in the SMTP envelope, called the envelope sender or Return-Path, or the domain given in the HELO greeting when the envelope sender is empty. That domain is often different from the From address that people see in their mail program. This is why SPF alone does not protect the visible From address, and why DMARC adds an alignment requirement on top. You can read more in our guide to what DMARC is and why businesses need it.
SPF answers one question: "Was this message sent by a server that the envelope domain's owner authorized?" It does not look at the message content, and it does not prove that the message is wanted.

How an SPF record is built
An SPF record is a TXT record that begins with v=spf1. After that come mechanisms, each of which may match the sending IP address, and finally a default result.
A plain example looks like this.
v=spf1 ip4:203.0.113.25 include:_spf.mailprovider.example mx -all
Reading from left to right:
v=spf1marks the record as SPF version 1.ip4:203.0.113.25authorizes one IPv4 address. There is alsoip6:for IPv6 addresses and ranges.include:_spf.mailprovider.examplepulls in the authorized sources published by another domain, typically your mail or marketing provider.mxauthorizes the servers listed in the domain's MX records.-allsays that anything not matched should fail.
The documentation addresses 203.0.113.25 and the domain names above are placeholders for illustration. Your provider will give you the exact include value to use.
Common mechanisms
| Mechanism | Meaning |
|---|---|
| ip4 / ip6 | A specific address or range |
| a | The addresses in the domain's A or AAAA records |
| mx | The servers named in the domain's MX records |
| include | Everything authorized by another domain's SPF record |
| redirect | Use another domain's SPF record as this domain's policy |
| all | Matches everything; used last as the default result |
Qualifiers
Each mechanism may carry a prefix that sets the result when it matches.
+means pass. It is the default and is usually left out.-means fail. The receiver is told that the source is not authorized.~means soft fail. The source is probably not authorized, but receivers are encouraged not to reject on this alone.?means neutral. The record makes no statement.
For the closing all, most domains choose ~all or -all. Avoid +all, which authorizes the entire internet and defeats the purpose of SPF.
Step-by-step: setting up SPF
Step 1: List everything that sends your mail
Write down each system that sends email with your domain: your mailbox provider, your website's contact form or shop platform, any marketing or newsletter tool, your invoicing system, and any server of your own. Ask colleagues too, since forgotten tools are a common cause of failures later.
Step 2: Get the SPF details from each provider
Most providers publish an include value or a list of addresses in their documentation. Use what the provider tells you rather than guessing, and check it again from time to time because providers can change their infrastructure.
Step 3: Check whether a record already exists
Look up the TXT records for your domain with a DNS lookup tool or a command such as dig TXT example.com. If you see a record that starts with v=spf1, you need to edit that record, not add another. Having two SPF records on the same name is an error.
Step 4: Write a single combined record
Combine the sources into one line. For example, a domain that uses a mailbox provider and a newsletter tool might publish:
v=spf1 include:_spf.mailprovider.example include:_spf.newsletter.example ~all
Step 5: Publish it in DNS
In your DNS provider's control panel, create or edit a TXT record at the root of the domain (often shown as @ or left blank). Paste the record exactly. Some interfaces add quotation marks automatically, so do not add them twice. Changes may take time to spread, depending on the TTL of the old record.
Step 6: Test
Send test messages to a mailbox at a few different providers, open the full message headers, and look for the Authentication-Results line. You want to see spf=pass. Online SPF checkers can also warn about syntax errors and count your DNS lookups.
Step 7: Tighten when ready
Many domains begin with ~all and review results for a couple of weeks. If every legitimate sender passes, you may move to -all. When you also publish DMARC, a soft fail in SPF is still evaluated through the DMARC policy, so you do not necessarily need the strictest ending to get benefit.
The ten-lookup limit
SPF evaluation may trigger at most ten DNS lookups caused by the mechanisms include, a, mx, ptr, exists and the redirect modifier. The ip4, ip6 and all mechanisms do not cost a lookup. Included records count too, including the lookups they trigger themselves.
If you go over ten, evaluation ends with a permanent error, and receivers may treat your mail as failing SPF. This limit is the most frequent hidden problem in business domains that use many cloud services.
Ways to stay under the limit:
- Remove services you no longer use.
- Prefer
ip4andip6entries when an address range is stable and documented by the provider. - Avoid
ptr, which the standard discourages. - Use separate subdomains for different services, for example one for marketing mail, so each subdomain has its own record and its own count.
- Ask your provider whether it offers a dedicated sending domain.
Also be aware that a record may not exceed what fits in a DNS response. Very long records are best split using includes carefully rather than by publishing multiple records.
A plain example
Suppose a small consultancy uses example.com. Staff mail is hosted by a mailbox provider, appointment reminders come from a booking tool, and invoices are sent by an accounting platform.
The consultant checks each provider's documentation and finds three include values. She searches DNS and discovers an old SPF record from a previous hosting company, which lists a server that no longer exists. She edits that record instead of adding a new one, removes the old entry, and adds the three includes. She ends with ~all.
She sends test messages to two different mailbox providers and finds spf=pass for staff mail and invoices, but the booking tool shows a failure. The tool sends with its own bounce domain, so the envelope domain is not hers and SPF passes for that other domain, not for example.com. She learns that the tool supports DKIM signing with her own domain, which is the right way to fix alignment for that sender. That is a good illustration of why SPF alone is not enough and why DKIM verification matters.
Limits and what to watch for
SPF is useful, but it has well-known limitations.
- Forwarding breaks it. When a message is forwarded, the forwarding server's address is not in the original domain's SPF record, so SPF can fail at the final destination. DKIM usually survives forwarding better.
- It checks the envelope, not the visible From. On its own, SPF does not stop someone from showing your domain in the From line. That is why DMARC alignment exists.
- It does not inspect content. A message can pass SPF and still be spam or phishing, especially if it was sent from a legitimate service that someone abused.
- Shared infrastructure. If you authorize a large provider through an include, other customers of that provider use the same ranges. SPF alone cannot tell your mail from theirs, which is another reason to rely on DKIM and DMARC as well.
- Receivers vary. Some receivers treat a soft fail and a hard fail differently, and policy decisions are theirs.
- Maintenance. Records age. Providers change, staff add tools, and old entries stay behind. Review the record whenever you add or remove a mail service.
For protecting your inbox from incoming threats, you will need filtering rather than SPF; our overview of choosing email filtering for a small business explains the options.
Common mistakes
- Publishing two or more SPF records on the same name.
- Using
+allor leaving out the finalall, which weakens or removes protection. - Exceeding the ten-lookup limit through nested includes.
- Typing the record with straight quotes pasted incorrectly, extra spaces or a broken line, so the record no longer parses.
- Forgetting subdomains that send mail. Each subdomain that sends needs its own record, and subdomains that never send mail can publish a record that authorizes nothing.
- Forgetting to update the record when you change mail provider.
- Assuming SPF protects the From address people see.
SPF, DKIM and DMARC together
SPF checks the sending server against a list. DKIM checks a signature in the message. DMARC requires that at least one of the two passes in alignment with the visible From domain, and it tells receivers what to do otherwise. Use all three. If you use a hosted business email service, ask what it sets up for you; and if you want help watching authentication results over time, an email security service can be part of the picture.
Reading the result in message headers
When you test, the header line you want to find is Authentication-Results. It is added by the receiving server and summarizes what it checked. A line such as spf=pass followed by the envelope domain tells you the sending address matched your record. If you see spf=softfail, the source was not authorized but your record ended with ~all. If you see spf=fail, the source was not authorized and the record ended with -all. A result of spf=none means the receiver found no SPF record at all, and spf=permerror often points to a syntax problem or to going over the ten-lookup limit. Reading these values after every change gives you quick, concrete feedback and saves hours of guessing.
Summary
SPF is a single TXT record, beginning with v=spf1, that lists the servers allowed to send mail for your domain's envelope address. To set it up, list every sender, collect the correct include values from each provider, check for an existing record, publish one combined record, test with real messages, and tighten from ~all to -all when you are confident. Remember the ten-lookup limit, the fact that forwarding can break SPF, and that SPF does not protect the visible From address by itself. Pair it with DKIM and DMARC for a complete setup. When you are ready to compare services that help manage this, the email security page is a good place to start.
Frequently asked questions
What is an SPF record?
An SPF record is a TXT record in your domain's DNS that lists the servers and services allowed to send email using your domain in the envelope sender. Receiving servers check it to decide whether a message came from an authorized source.
Can I have more than one SPF record?
No. A domain must publish only one SPF record. If you need several services, merge them into a single record using multiple include mechanisms.
What is the ten-lookup limit?
SPF allows at most ten DNS-querying mechanisms such as include, a, mx and redirect during one evaluation. Exceeding the limit causes a permanent error, which can make SPF fail for all of your mail.
Should I end my record with -all or ~all?
Both are valid. The ~all ending is a soft fail and is common while you are still checking your senders. The -all ending is a hard fail and is stricter. Many domains start with soft fail and tighten once reports look clean.
References
About the author

Bob Kanokphon Thongdee
- Founder of XPASS VPN
- Co-founder of eSIMonline.asia
- More than 7 years in online marketing
- Founder of Cojourney Visa and Cojourney Travel
Protect your email and stop spoofing
Spam filtering and DMARC monitoring for your domain.
See email securityKeep reading

Business Email Guides
What Is DMARC and Why Every Business Should Know It
DMARC tells receiving mail servers what to do when a message claiming to be from your domain fails authentication. Learn how it works and how to roll it out step by step.
10 min read

Business Email Guides
What Is DKIM and How Does It Help Verify Email?
DKIM adds a digital signature to every outgoing message so receivers can check it was not altered and that your domain approved it. Learn how it works and how to set it up.
10 min read

Business Email Guides
How to Choose Email Filtering for a Small Business
Picking email filtering is easier with a checklist. Define your needs, compare the features that matter, test with real mail and plan the DNS changes.
10 min read