The SPF limit of 10 DNS lookups

Written by Micronet AS · Updated

Short answer

What is the SPF limit of 10 DNS lookups?

SPF allows at most 10 DNS lookups per check. Every include, a, mx, ptr, exists and redirect counts, including those inside the records you include. If the record goes over 10, the receiver returns the result permerror, and SPF fails for email from the domain. The fix is to remove services that are not used, move senders to subdomains or use hosted SPF.

The limit is in RFC 7208 and is there to keep an SPF check from becoming a burden on the receiver. It is easy to pass without noticing, because every service you add can use more lookups than it appears to.

What counts

Part of the recordCounts towards the limit?
include, a, mx, ptr, exists, redirectYes, one lookup each, also inside included records.
ip4, ip6, allNo.

If you include a service that itself includes three other records, you have used four lookups on one line. The SPF lookup counter walks the whole tree and shows where the lookups are spent.

Two more limits

  • Void lookups: the standard says the receiver should stop after two lookups that return no answer, for example an include to a domain that no longer exists. That gives permerror too.
  • mx: the mechanism must not lead to lookups of more than 10 addresses.

What happens when the record goes over?

The receiver returns permerror instead of pass. The email can then only pass DMARC through DKIM. If the service has no DKIM for your domain, the email fails DMARC, and with p=quarantine or p=reject it ends up in spam or is rejected.

Five ways to get below the limit

  1. Remove services you no longer use. Old newsletter tools and former email providers are often left behind.
  2. Remove a and mx if the servers they point to do not send email.
  3. Replace include with ip4 or ip6 only for your own servers with fixed addresses.
  4. Move services to subdomains. news.company.com has its own SPF record with its own 10 lookups.
  5. Use hosted SPF, where the record is kept below the limit for you and updated when the services change addresses.

What about SPF flattening?

Flattening means replacing include with the IP addresses it points to. That uses no lookups, but the addresses of large services change without notice. Microsoft advises against doing it with include:spf.protection.outlook.com. A flat record must therefore be updated automatically, or it stops being correct.

The SPF flattening tool shows what a flat record would look like for your domain.

Sources

Questions and answers

What does permerror mean?

Permerror is a permanent error result from the SPF check. It means the record cannot be evaluated, for example because it uses more than 10 lookups, has a syntax error or because the domain has two SPF records.

Does it help to split SPF into two TXT records?

No. A domain can only have one SPF record. Two records that both start with v=spf1 give permerror.

Do ip4 and ip6 count towards the limit?

No. They need no DNS lookup. But an SPF record with very many addresses becomes long, and a TXT record should stay below 512 bytes to fit in one ordinary DNS answer.