On this page
  1. What is an SPF record?
  2. SPF record syntax
  3. SPF mechanisms and qualifiers, and ~all vs -all
  4. SPF record examples
  5. SPF record for each sending service
  6. Multiple SPF records and how to merge them
  7. The SPF 10-lookup limit and SPF flattening
  8. Where to find, check and generate your SPF record
  9. SPF limits: forwarding and alignment
  10. FAQ

SPF Record: What It Is and How to Write One

An SPF (Sender Policy Framework) record is a TXT record in your domain's DNS that lists the servers and services allowed to send email for that domain, so receiving servers can check the sending IP against it and treat mail from anywhere else as suspect.

Written by Relay, the Email Stack Review teamPublished Updated No ads or affiliate links
Choosing a sending service? See the best transactional email services.

An SPF record is one line of DNS, and two rules cause common failures: you get one per domain, and it can trigger only ten DNS lookups. This page covers the syntax, what ~all and -all tell receivers, examples for example.com, what each sending service wants you to add, and how to merge records without breaking the limit.

Key takeaways

  • An SPF record is a TXT record that starts with v=spf1, lists who may send, and ends with an all mechanism. Receivers check the sending IP against it.
  • You get one SPF record per domain. Two records cause a permerror (RFC 7208). Merge them.
  • Evaluation is capped at 10 DNS-lookup terms: include, a, mx, ptr, exists and redirect count; ip4, ip6 and all don't. Go over and SPF returns a permerror.
  • ~all (softfail) and -all (fail) differ in how firmly you say "not me". With DMARC in place, -all can cause early rejection of mail that DKIM would have passed.
  • Several sending services handle SPF on a return-path subdomain and need no include in your root record. The per-service table shows which.

What is an SPF record?

An SPF (Sender Policy Framework) record is a TXT record in your domain's DNS that lists the servers and services allowed to send email for that domain, so receiving servers can check the sending IP against it and treat mail from anywhere else as suspect. The standard is RFC 7208.

The receiver compares the connecting IP address with the record of the domain in the envelope sender, the MAIL FROM or return-path address, not the visible From header. Alignment between the two is covered in SPF, DKIM and DMARC explained.

The check ends in one of seven results (RFC 7208 §2.6): none, neutral, pass, fail, softfail, temperror or permerror.

SPF on its own doesn't stop someone spoofing your visible From address. Pairing it with DMARC does that: see what DMARC is.

SPF record syntax

An SPF record is a single TXT string at the domain, starting with v=spf1, followed by mechanisms that name allowed senders, and ending with an all mechanism that says what to do with everyone else. Receivers read it left to right and stop at the first match.

Example for example.com, a generic shape with placeholder hostnames:

example.com.  IN TXT  "v=spf1 include:spf.sender.example ip4:203.0.113.25 ~all"
  • v=spf1 is the version tag and must come first. A version of spf10 doesn't match (RFC 7208 §4.5).
  • include:spf.sender.example says "whatever that domain's SPF record allows, allow too".
  • ip4:203.0.113.25 allows one IPv4 address (a documentation address here).
  • ~all matches everything else, so it goes last. Anything written after all is never tested (RFC 7208 §5.1).

The record lives at the root of the domain you send from (or at the return-path subdomain, as some services require). Size matters in two ways. A single DNS string holds at most 255 octets, and a record may be split into several strings that receivers join without adding spaces (RFC 7208 §3.3). The whole published record should also fit within 512 octets in a DNS answer, to avoid failing over to TCP (RFC 7208 §3.4).

SPF mechanisms and qualifiers, and ~all vs -all

An SPF mechanism says where mail may come from, and a qualifier in front of it says what result a match gives. The mechanism decides whether a DNS lookup is spent.

Mechanism What it matches Costs a DNS lookup?
ip4, ip6 A literal address or range No
all Everything; goes last No
include:domain Anything that domain's own SPF record would pass Yes
a The domain's A/AAAA addresses Yes
mx The addresses of the domain's mail servers Yes (and each MX name needs address lookups)
exists A domain you construct that resolves in DNS Yes
ptr Reverse DNS match; RFC 7208 §5.5 says it should not be published Yes

Source: RFC 7208 §4.6.4 and §5. The redirect= modifier, which points the check at another domain's record, also costs a lookup. It should be the last term, and it is ignored if the record has an all mechanism (RFC 7208 §6.1).

The qualifier is the sign in front of a mechanism, + by default (RFC 7208 §4.6.1):

Qualifier Result Meaning
+ pass The sender is authorized
- fail An explicit statement that the sender is not authorized
~ softfail Probably not authorized, but not a strong policy statement
? neutral No statement either way

~all vs -all. -all says "everything not listed is not authorized". ~all says "everything not listed is probably not authorized". RFC 7208 §8.5 says receivers should not reject on a softfail alone; for a fail, disposition is local policy (§8.4). Gmail does reject on a hard fail: its error text reads "The (E)MAIL FROM domain [domain-name] has an SPF record with a hard fail policy (-all) but it fails to pass SPF checks" (Google's SMTP error reference, checked November 2026).

Once you publish DMARC, the choice matters for another reason. RFC 9989 §7.1 warns that an SPF hard fail can get a message rejected early in the SMTP session, even if an aligned DKIM signature would have let it pass DMARC, and that such rejected messages never appear in your aggregate reports. Our view, not a rule in the RFC: ~all suits a domain that sends through several services, and -all suits one where you control every sending path or that sends nothing.

SPF record examples

A good SPF record is one record per domain, under the ten-lookup limit, ending in an all mechanism, and listing only services you actually use. Four examples for example.com, with placeholder include hostnames (real ones are in the per-service table):

; 1. One sending service
example.com.  IN TXT  "v=spf1 include:spf.service-a.example ~all"

; 2. Staff mailboxes plus one sending service
example.com.  IN TXT  "v=spf1 include:spf.staffmail.example include:spf.service-a.example ~all"

; 3. One service plus your own server
example.com.  IN TXT  "v=spf1 include:spf.service-a.example ip4:203.0.113.25 ~all"

; 4. A domain that sends no email
example.com.  IN TXT  "v=spf1 -all"

What each allows: the first lets one service send for you and marks everything else as probably unauthorized. The second adds your staff mail provider. The third also lets your own server at 203.0.113.25 send. The fourth says no server may send, which is what you want on parked domains. RFC 7208 uses the same shape in its own examples (for instance v=spf1 a mx -all and v=spf1 -all).

The checklist: one v=spf1 record, under ten lookups, a single all at the end, and nothing for services you stopped using.

SPF record for each sending service

Several services don't want an include in your root SPF record. They handle SPF on a return-path subdomain, and that subdomain also gives DMARC alignment. Others still ask for an include. The table is what each service's docs say you add.

Service SPF What you add Return path at your domain
SendGrid Covered by the return-path CNAME CNAME on em… subdomain; or TXT include:sendgrid.net if automated security is off Yes, by default
Amazon SES Implicit by default Custom MAIL FROM: MX + TXT v=spf1 include:amazonses.com ~all on that subdomain Opt-in
Mailgun Include include:mailgun.org in the sending domain's SPF record Not stated
Postmark Covered by the return-path CNAME CNAME to pm.mtasv.net Opt-in
Resend On the send. subdomain MX + TXT v=spf1 include:amazonses.com ~all on send. Yes, by default
Mailtrap Covered by the verification CNAME CNAME to smtp.mailtrap.live Yes, automatic
Brevo Not needed on shared IPs Nothing for SPF (branded CNAME optional) Opt-in
Mailjet Include include:spf.mailjet.com in the root SPF record Opt-in, paid plans
MailerSend Include include:_spf.mailersend.net merged into one record Yes, part of setup

From each service's own docs and product pages, checked November 2026. "Not documented" means we didn't find it in the vendor's docs. Mailtrap's automatic return path comes from its blog, not its docs. Docs: SendGrid, Amazon SES, Mailgun, Postmark, Resend, Mailtrap, Brevo, Mailjet, MailerSend.

Setup steps sit in our reviews of SendGrid, Amazon SES, Mailgun, Postmark, Resend and Mailtrap. Two details from the vendor docs: Postmark's custom return-path CNAME means the root include isn't needed for alignment, and Resend's newer domains (created after August 2026) may get CNAME records instead of the MX and TXT shown here (Resend's wording).

Multiple SPF records and how to merge them

You can't have two SPF records on one domain: RFC 7208 §3.2 says a name must not have multiple records that would cause an authorization check to select more than one, and receivers return a permerror when they find them. The fix is to merge them into one v=spf1 record with one all at the end.

Before, two records (this breaks SPF):

example.com.  IN TXT  "v=spf1 include:spf.service-a.example ~all"
example.com.  IN TXT  "v=spf1 include:spf.service-b.example ip4:203.0.113.25 ~all"

After, one record:

example.com.  IN TXT  "v=spf1 include:spf.service-a.example include:spf.service-b.example ip4:203.0.113.25 ~all"

Combine every include, ip4 and ip6 into the one record, keep a single all last, and delete the others. That also answers "multiple includes" and "multiple ip4": list as many as you need, but each include spends lookups from the cap below, while ip4 and ip6 are free. Mailgun's and MailerSend's docs both say to merge their include into your existing record rather than add a second one.

The SPF 10-lookup limit and SPF flattening

SPF evaluation may trigger at most 10 DNS lookups. RFC 7208 §4.6.4 counts the include, a, mx, ptr and exists mechanisms and the redirect modifier; all, ip4 and ip6 are free. Go over 10 and the receiver must return a permerror, which means SPF fails.

The limit applies to the whole evaluation, so an include that itself contains includes spends lookups for each one. Each mx also queries the MX records, and more than 10 address lookups for one mx is a permerror on its own. Separately, receivers should stop at two void lookups, queries that return nothing. Count by reading each included record, or by running the domain through a checker.

Ways to stay under the limit:

  • Drop services you no longer use. Old includes are the usual culprit.
  • Move a service to a return-path subdomain. Services listed above as covered by a return-path CNAME keep their SPF off your root record.
  • Flatten the record. Flattening replaces include: terms with the ip4 and ip6 ranges they resolve to, which avoids the include lookups. That is general practice, not something RFC 7208 covers: a flattened record is a snapshot, so if the service changes its IPs your copy is stale and its mail can start to fail. If you flatten, regenerate it on a schedule. We don't rank flattening tools.

The error text for exceeding the limit and its fix live on fix SPF, DKIM and DMARC failures.

Where to find, check and generate your SPF record

Your SPF record is a TXT record at your domain starting with v=spf1. Find it in your DNS host's record list, or query it: dig TXT example.com +short and look for the string starting v=spf1.

  • Check it. Open the full headers of a message you received and look for spf=pass in Authentication-Results (RFC 8601). In Gmail: next to Reply, click More, then Show original (Google's help page, checked November 2026). Or use a free third-party checker: Google's Admin Toolbox Check MX covers MX and SPF records. We don't run a checker of our own.
  • Generate it by hand. List every service and server that sends as your domain. Take each include from that service's docs. Add one all at the end. Publish it as a single TXT record, then check it as above.

Where to click to publish a TXT record at common DNS hosts is covered in how to set up DMARC.

SPF limits: forwarding and alignment

SPF has two weak spots: forwarding, and the fact that it doesn't check the address people see.

Forwarding sends your message from the forwarder's server, which isn't in your SPF record, so SPF often fails at the final receiver (RFC 7208 §10.3 and Appendix D discuss mediators). DKIM signatures usually survive if the message isn't changed: see what DKIM is.

And SPF checks the envelope sender, not the visible From. For DMARC to count an SPF pass, the return-path domain has to match the From domain, which is why the return-path subdomain in the table above matters. Details: SPF, DKIM and DMARC explained.

Ready to pick a service? Compare the best transactional email services.

SPF record: FAQ

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 for it. Receivers compare the sending IP with the list and treat mail from anywhere else as suspect. It is defined in RFC 7208. See what is an SPF record.

Where do I find my SPF record?

In your DNS host's record list, as a TXT record on your domain that starts with v=spf1. You can also query it with dig TXT example.com +short, replacing the domain with yours. If nothing starts with v=spf1, you don't have one. See where to find it.

How do I generate an SPF record?

List every service and server that sends mail as your domain, take each include from that service's docs, put them in one v=spf1 string, and end it with a single all. Publish it as one TXT record. We don't offer a generator. See SPF examples.

Can you have multiple SPF records?

No. A domain may have only one SPF record, and two cause a permerror under RFC 7208 §3.2 and §4.5. Merge the mechanisms into a single v=spf1 record with one all at the end. See how to merge them.

What is a good SPF record?

One record per domain, under the 10-lookup limit, ending in an all mechanism, and listing only services you still use. For a domain that sends no mail, v=spf1 -all is a complete, good record. See the examples.

What is the difference between ~all and -all?

~all is a softfail: the domain says mail from other sources is probably not authorized, and receivers shouldn't reject on that alone. -all is a hard fail: it says such mail is not authorized, and some receivers, Gmail included, reject it. See ~all vs -all.

What is the SPF 10-lookup limit?

RFC 7208 caps SPF evaluation at 10 DNS lookups caused by include, a, mx, ptr, exists and redirect. Exceed it and the receiver returns a permerror, so SPF fails. Merging includes, dropping unused ones or flattening keeps you under. See the limit.

Do SendGrid, Amazon SES and others need an include in my SPF record?

It varies. Per their docs (checked November 2026), SendGrid and Postmark cover SPF through a return-path CNAME, and Mailtrap through a verification CNAME. Mailgun, Mailjet and MailerSend ask for an include. Amazon SES is implicit by default, and Resend puts its SPF on a send. subdomain. See the per-service table.