DNS Lookup

What is an SPF record?

The record that decides which servers may send email on behalf of your domain.

The Sender Policy Framework (SPF) is an email authentication method that lists the servers allowed to send email on behalf of your domain.

SPF makes it harder to use your domain for spoofed mail and helps your messages get delivered properly. Receiving mail servers check your SPF record to see whether a message that appears to come from you really came from an authorised server.

A receiving server checking the SPF record before delivering or blocking a message

How does SPF work?

When a mail server receives a message, it looks at the IP address of the sending server and the domain of the envelope sender (Return-Path). It then reads that domain's SPF record from DNS and checks whether the sending IP is on the list. The result, pass, fail, softfail or neutral, is written to the message headers and used in the spam decision.

The domain SPF checks is the envelope address, not the "From" address the recipient sees. So SPF on its own can't stop forged From addresses; DMARC fills that gap.

What should an SPF record look like?

An SPF record is a single TXT record on your domain. An example:

v=spf1 a mx ip4:203.0.113.25 include:_spf.google.com ~all

An SPF record always starts with v=spf1. This marks the SPF version; it's the only version in use today. The mechanisms that follow are evaluated left to right and the first match wins.

MechanismMeaning
aThe server in the domain's A record may send.
mxThe servers in the MX records may send.
ip4The given IPv4 address or block may send (ip4:203.0.113.0/24).
ip6The given IPv6 address or block may send.
includeIncludes another domain's SPF rules. Used to authorise services you don't run yourself, such as Google Workspace or Microsoft 365.
existsMatches if the given name resolves. For advanced use.
redirect=Hands SPF evaluation over entirely to another domain. Used when several domains share the same rules.
allAll servers not matched above. Always comes last.
Illustration about email security

SPF for common services

Every service you send mail through has to be combined into one record. Common values:

ServicePart to add
Google Workspaceinclude:_spf.google.com
Microsoft 365include:spf.protection.outlook.com
Zoho Mailinclude:zoho.com (EU: include:zoho.eu)
Fastmailinclude:spf.messagingengine.com
Your own server / hostinga, mx or ip4:server-ip

For example, if you send mail both through Google Workspace and from your hosting server (a contact form on your website, say):

v=spf1 a mx include:_spf.google.com ~all

Newsletter services (Mailchimp, SendGrid, Brevo and the like) usually use their own domain as the envelope sender and ask you for DKIM or CNAME records rather than SPF. Check what the service's documentation asks for; adding needless includes wastes the 10-lookup limit.

-all or ~all?

The qualifier at the end of the record says what to do with mail from a server that isn't listed: -all means a hard fail, ~all a soft fail.

With -all, mail from a server not defined in the record is treated as unauthorised and not delivered.

With ~all, you're saying your record may not cover every sending server. When mail comes from another server, the receiving system decides whether to accept it; it's usually marked as spam.

Your SPF record should be strict enough that your domain can't be used for spoofed mail. If you're sure every sending service is in the record, we recommend -all. For a new setup, it's safer to start with ~all for a few weeks, see from your DMARC reports which servers send mail, and then move to -all.

?all (neutral) gives no protection at all, and +all lets every server in the world send mail as you. Don't use either.

The 10 DNS lookup limit

The SPF standard (RFC 7208) allows at most 10 DNS lookups while evaluating an SPF record. include, a, mx, exists and redirect each count as one; includes inside included records add to the total too. ip4, ip6 and all need no lookup.

When the limit is exceeded the result is permerror, and receiving servers treat your SPF as invalid. It's a common problem for companies using several services at once. Ways to fix it:

  • Remove the includes of services you no longer use.
  • Write your server's IP address with ip4: instead of a and mx.
  • Move newsletter and marketing mail to a subdomain like news.example.com, which gets its own SPF record.

Our lookup tool expands the include chain step by step and counts the total number of lookups.

Common mistakes

  • More than one SPF record. A domain may have only one v=spf1 record. If there are two, both are treated as invalid; merge the services into one record. Adding the record a new service suggests as a separate record is the most common cause of this mistake.
  • Mechanisms after all. Nothing after all is evaluated.
  • Using the old "SPF" record type. The separate SPF record type (type 99) was retired in 2014. Add the record as TXT.
  • Going over 255 characters. A single TXT string can be at most 255 characters. Panels usually split longer records automatically; if yours doesn't, shorten the record.
  • Forgetting subdomains. SPF isn't inherited by subdomains. If you send mail from info.example.com, that name needs its own SPF record.