Email authentication
SPF too many DNS lookups
An SPF record that exceeds 10 DNS-querying terms returns permerror. The record can look short and still fail because every include can contain more includes. The fix is to count, simplify and monitor.
The 10-lookup limit
RFC 7208 limits SPF to 10 DNS-querying terms per check. The limit exists to protect receivers from expensive or abusive records. When it is exceeded, the result is permerror, which many receivers treat as a failure.
The count is per check, not per record. A single include can add several lookups if it contains more includes, a, mx, ptr or exists mechanisms.
What counts
include, a, mx, ptr, exists and redirect count as DNS-querying terms. ip4 and ip6 do not. all does not. A nested include counts for the parent include and for every DNS-querying term inside it.
That is why a record with three marketing platforms can exceed the limit even though it only has three include mechanisms. Each platform may include its own subdomains and services.
How to fix it
Remove includes for services you no longer use. Ask each provider for the minimum set of IPs or includes. Replace small includes with explicit ip4 and ip6 mechanisms when the provider publishes stable ranges.
If a large sender cannot be reduced, consider moving that sender to a subdomain with its own SPF record, or use an SPF flattening service. Flattening replaces includes with IPs, which reduces lookups but needs maintenance when the provider changes ranges.
Flattening caveat
Flattened records go stale. If the provider adds or removes IPs, your record can authorise the wrong infrastructure. Run a regular check and refresh the flattened record when the provider publishes changes.
Do not use ptr in a modern SPF record. It is slow, unreliable and deprecated in practice. Use includes or explicit IPs instead.
Frequently asked questions
What causes SPF permerror?
Too many DNS lookups, a syntax error, a missing include target, or multiple v=spf1 records are the usual causes.
How many lookups does SPF allow?
Ten DNS-querying terms per check. Includes inside includes count toward the total.
Does include count as a lookup?
Yes. include, a, mx, ptr, exists and redirect all count. Nested terms count too.
Can I flatten my SPF record?
Yes, but flattening needs maintenance. It replaces includes with IPs, so refresh it when your providers change their ranges.