What is an SPF record? SPF explained for IT professionals
SPF (Sender Policy Framework) is a DNS-based email authentication mechanism that specifies which mail servers are authorised to send email on behalf of your domain. It helps receiving mail servers identify messages sent from servers not authorised by the domain owner.
How SPF works
When a receiving mail server accepts an email, it looks at the Return-Path domain (the envelope sender, not the From header) and checks for an SPF record at that domain. It then validates whether the sending server's IP address is listed as an authorised sender.
The result is one of:
- Pass: The IP is authorised.
- Fail: The IP is not authorised. The
-alldirective treats this as a fail. - SoftFail: The IP is not authorised, but the domain wants lenient treatment.
~allproduces a softfail. - Neutral: No policy defined (
?all). - None: No SPF record found.
SPF record syntax
An SPF record is a DNS TXT record at your root domain. Example:
v=spf1 include:_spf.google.com include:sendgrid.net ip4:203.0.113.5 ~all
| Mechanism | Meaning |
|-----------|---------|
| v=spf1 | Required. Identifies this as an SPF record. |
| include: | Authorise all IPs listed in another domain's SPF record. |
| ip4: | Authorise a specific IPv4 address or CIDR range. |
| ip6: | Authorise a specific IPv6 address or prefix. |
| a | Authorise the IP(s) in the domain's A record. |
| mx | Authorise the IP(s) in the domain's MX record. |
| -all | Hard fail: reject mail from any IP not listed. |
| ~all | Soft fail: accept but mark mail from any IP not listed. |
-all vs ~all
Use -all (hard fail) when you are confident you have listed every authorised sender and want unauthorised mail hard-rejected. This is the correct choice for enforcement.
Use ~all (soft fail) when you are still discovering senders or when DMARC is set to p=reject. Under DMARC reject policy, the SPF -all/~all distinction matters less since DMARC is handling the policy decision.
Most modern configurations use ~all combined with a strong DMARC p=reject policy.
The 10 DNS lookup limit
SPF has a hard limit of 10 DNS lookups per evaluation. Each include:, a, and mx mechanism triggers a lookup. Exceeding this limit causes SPF to return a PermError, which counts as a failure.
Common causes of exceeding the limit:
- Chaining too many
include:directives - Including third-party SPF records that themselves have many includes
- Using
mxandamechanisms unnecessarily
To stay under the limit: audit your sending sources, consolidate where possible, and use ip4: for static IPs instead of a: or mx:.
SPF and DMARC alignment
SPF alone is not sufficient to prevent spoofing of the From header. SPF validates the envelope sender (Return-Path domain), not the From address visible to recipients. A spoofed From header passes SPF if the attacker controls the Return-Path domain.
DMARC closes this gap by requiring alignment: the SPF-authenticated domain must match the From domain. With aspf=r (relaxed), a subdomain match is sufficient. With aspf=s (strict), it must be an exact match.
Practical consequence: An email can pass SPF but fail DMARC if the Return-Path domain does not align with the From domain. This is why SPF and DMARC must be configured together.
Common SPF mistakes
Multiple SPF records. A domain must have exactly one SPF TXT record. Multiple records cause a PermError and SPF will fail.
Forgetting a sending source. If you add a new SaaS tool that sends on your behalf and do not add it to SPF, those messages will fail SPF. Use DMARC reporting to discover new senders.
Using +all. This authorises every IP on the internet to send as your domain. Never use it.
Nested includes exceeding 10 lookups. Use a tool to count your current lookup depth before adding new includes.