Skip to content

Blog · · 6 min read

SPF's ten-lookup limit, and how to stay under it

By Y Naga Vamsi, creator of Mailtruss.

A common way for SPF to break is invisible: the record is valid, every include points at a real service, and one day SPF starts failing for everyone. The usual cause is the ten-lookup limit, which you hit by adding one more email service.

What the limit is

RFC 7208 section 4.6.4 says that evaluating an SPF record may cause at most ten DNS-querying terms. Past that, the receiver must return a permanent error (permerror), and SPF does not pass. The count includes terms inside every record you include.

What counts

  • include:, a, mx, ptr, exists: and redirect= each count as one lookup.
  • An include counts, and so does every counted term in the record it points at. One include: of a large provider can cost four or five.
  • ip4:, ip6: and all cost nothing, because they need no DNS query.

The standard also tells receivers to stop after two "void" lookups, which are lookups that return nothing, so an include pointing at a name with no SPF record is itself a problem.

Count yours

Doing this by hand means opening each include and each nested include. The domain checker follows them for you and shows how many of the ten you use, along with other common SPF mistakes such as two records on one name or a record that ends in +all.

Getting under the limit

  1. Remove what you no longer use. Old marketing tools and abandoned services stay in SPF records for years. This is the safest fix and often enough.
  2. Send each service from its own subdomain. mail.yourdomain.com and news.yourdomain.com each get their own SPF record with their own ten lookups. DMARC still aligns, because subdomains share the organisational domain.
  3. Use `ip4:` and `ip6:` for services whose addresses never change , such as your own servers.
  4. Be careful with flattening. Replacing an include with the list of IP addresses it resolves to removes the lookups, but providers change their addresses. A flattened record that is not regenerated automatically goes stale and starts failing mail.

Other things worth checking while you are there

  • Exactly one SPF record per name. Two make SPF fail, and merging them into one is the fix.
  • End with ~all or -all. ?all protects nothing, and +all allows anyone to send as you.
  • Avoid ptr. RFC 7208 says it should not be used: it is slow and unreliable.
  • SPF is one of three checks. Read how SPF, DKIM and DMARC fit together before tightening anything.