Skip to content
postanex

Domains & DNS

How to Write an SPF Record: Examples and Lookup Limit

Why does SPF break once a company uses several sending services? Syntax, the 10-lookup limit and the ~all versus -all decision, with worked examples.

Postanex Editorial Team · · 6 min read

An allow-list of sending servers with IP addresses, an approval stamp and a counter capped at 10

Most companies write their SPF record on setup day and never look at it again. Meanwhile the accounting tool arrives, then the newsletter platform, then the helpdesk. Each one asks you to "add this to SPF", and the record slowly turns into a long string nobody fully understands.

This article explains what an SPF record does, how to write one and why the 10-lookup limit causes most of the grief. Examples use example.com; swap in your own domain.

Short answer: SPF lets you list, in one DNS TXT record, the servers allowed to send mail for your domain. The record starts with v=spf1, lists sources with mechanisms such as ip4, mx and include, and ends with ~all or -all. A domain should publish exactly one SPF record, and evaluating it must not take more than 10 DNS lookups.

What SPF does and does not do

SPF checks whether the server connecting to the receiver is authorised to send for a domain. The receiving server looks at the connecting IP address, fetches the sender domain's SPF record from DNS and checks whether the IP is on the list.

One detail trips people up: SPF checks the envelope sender (the Return-Path, sometimes called MAIL FROM), not the From address the user sees. An SPF pass therefore does not prove that a message that looks genuine is genuine. Protecting the visible address takes DMARC, which we cover in DMARC setup.

SPF also says nothing about the content of a message or whether it was altered. The signing side is DKIM, explained in what is DKIM. And since forwarding changes the connecting IP, SPF breaking on forwarded mail is normal behaviour, not a fault in your record.

Syntax: v=spf1, ip4, include, all

An SPF record is a TXT record at the root of your domain. The simplest useful version looks like this:

example.com.  IN  TXT  "v=spf1 mx ~all"

That reads as "the servers in my MX records may send, treat everything else with suspicion". The building blocks:

Part Meaning
v=spf1 Marks the record as SPF; always first
ip4:203.0.113.10 Allows this IPv4 address (ip6: for IPv6)
mx Allows the domain's MX servers
a Allows the address in the domain's A record
include:spf.example-provider.example Pulls in another service's SPF permissions
~all / -all Verdict for sources that match nothing

You can prefix a mechanism with a qualifier: + pass (the default), - fail, ~ softfail, ? neutral.

Adding several sending services

If mail leaves your company from several places, each service needs an include. Say your mail platform, your newsletter tool and your invoicing software all send as you:

example.com.  IN  TXT  "v=spf1 mx include:spf.mail-provider.example include:spf.newsletter-tool.example include:spf.invoicing-app.example ~all"

Take the actual include: values from each service's documentation; the ones above are placeholders.

The mistake we meet most in the field is adding a separate SPF record for each service. A domain may have only one. With two v=spf1 records, evaluation returns a permanent error (permerror) and none of your services pass SPF. In your DNS panel, check for an existing record first; put the new service's include inside it rather than on a new line.

A second trap involves the panel itself. Some DNS panels wrap TXT values in quotes automatically. If you add quotes yourself, the record is published double-quoted and breaks. After saving, run:

dig TXT example.com +short

You should see "v=spf1 ..." with a single pair of quotes.

The 10-lookup limit and how to stay under it

SPF evaluation may trigger at most 10 DNS lookups. The limit comes from RFC 7208. The mechanisms include, a, mx, ptr and exists, plus the redirect modifier, each count as a lookup; ip4, ip6 and all do not. Go over and the result is a permerror, which receivers may treat as an SPF failure.

The catch is that an include can contain further includes. You think you added three services, but each brings its own chain, and the total quietly passes 10. The record looks fine until the day a fourth service is added and everything fails together.

This is the order we suggest for keeping under the limit:

  1. Remove services you no longer use. An old newsletter platform is often still listed.
  2. Prefer ip4 over a and mx when the addresses are fixed and known; ip4 costs no lookups.
  3. Split services onto subdomains (for example news.example.com) and give each subdomain its own SPF record.
  4. "Flattening" tools exist, but a flattened record goes stale when the provider changes its IPs. Without automatic updating, we do not recommend it.

An online SPF checker will show every link in the chain and the total.

~all or -all?

~all (softfail) means "a source not on the list is suspicious, but do not reject outright". -all (fail) means "a source not on the list is unauthorised".

Our view: start with ~all. If a legitimate sender is missing from the list, -all can cause its mail to bounce, and some receivers reject on -all without ever consulting DMARC. Run ~all, watch the DMARC reports, add every legitimate source, and move to -all when you are confident. In practice, once your DMARC policy is p=reject, the gap between ~all and -all narrows; DMARC makes the final call.

For domains that never send mail, such as parked domains, the safest record is:

parked-example.com.  IN  TXT  "v=spf1 -all"

Testing and troubleshooting

After publishing, check three things. First, confirm the record is live with dig TXT example.com +short; how long a change takes is explained in how long DNS changes take. Second, send a test message and open the headers at the receiving end: the Authentication-Results line should show spf=pass. Third, count the lookups with a checker.

If mail still lands in spam, SPF may not be the only cause. The diagnosis order is in why emails go to spam, and the difference between SPF and routing records is covered in what is an MX record.

Reference: the official specification is RFC 7208.

Frequently asked questions

Can a domain have more than one SPF record?

No. A domain should publish exactly one v=spf1 TXT record. With more than one, evaluation fails with an error. When you add a service, put its include inside the existing record.

What happens if I have no SPF record?

Your mail is usually still delivered, but receivers cannot verify you and the risk of landing in spam goes up. Bulk-sender rules at the large mailbox providers also require SPF and DKIM.

Does an SPF record cover subdomains?

No. An SPF record applies only to the name where it is published. If you send from a subdomain, that subdomain needs its own SPF record.

Does ~all versus -all change delivery?

It depends on the receiver. Some reject outright on -all, while ~all usually results in the message being marked as suspicious. Until you are certain your list is complete, we suggest ~all.

  • SPF
  • DNS
  • TXT record
  • deliverability
  • include

Domains & DNS

DMARC Setup in 2026: Step-by-Step Record Guide

A copy-ready walkthrough: start safely with one TXT record at p=none, read the reports, then tighten the policy as you learn who sends mail for you.

· 6 min read

Deliverability

Why Emails Go to Spam: Causes and Fixes for 2026

A symptom-to-diagnosis flow: authentication first, then reputation, then content, with checks a small team can run without a deliverability consultant.

· 6 min read