Suped

Does SPF allow for comments within the record string?

The short answer is no, the Sender Policy Framework (SPF) specification does not allow for comments within the record itself. An SPF record must be a single, continuous string of text that adheres to a strict syntax. Any deviation, including adding comments, can lead to validation problems and negatively impact your email deliverability.

I often see this question come up from people trying to document why a certain IP address or third-party service is included in their record. While the intention is good, it's unfortunately not supported. Let's break down why.

Suped DMARC monitor
Free forever, no credit card required
Get started for free
Trusted by teams securing millions of inboxes
Company logoCompany logoCompany logoCompany logoCompany logoCompany logoCompany logoCompany logoCompany logoCompany logoCompany logoCompany logoCompany logoCompany logoCompany logoCompany logoCompany logoCompany logoCompany logoCompany logoCompany logoCompany logoCompany logoCompany logoCompany logoCompany logoCompany logoCompany logoCompany logoCompany logoCompany logoCompany logoCompany logoCompany logoCompany logoCompany logoCompany logoCompany logoCompany logoCompany logoCompany logoCompany logoCompany logoCompany logoCompany logoCompany logoCompany logoCompany logoCompany logoCompany logoCompany logoCompany logoCompany logoCompany logoCompany logoCompany logoCompany logoCompany logoCompany logoCompany logoCompany logoCompany logoCompany logoCompany logoCompany logoCompany logoCompany logoCompany logoCompany logoCompany logo

The strict syntax of an SPF record

SPF is an email authentication protocol that lives inside a DNS TXT record. The specification that defines how SPF works, RFC 7208, is very clear about the format. It's designed to be parsed quickly and efficiently by mail servers, leaving no room for ambiguity.

datatracker.ietf.org logo
IETF Datatracker says:
Visit website
The SPF record is expressed as a single string of text found in the RDATA of a single DNS TXT resource record; multiple SPF records are not permitted for...

The record always starts with v=spf1 followed by a series of "mechanisms" (like ip4, a, or include) and ends with a qualifier, usually -all or ~all. Any character or string that doesn't fit this structure is likely to cause a validation failure, specifically a permerror (permanent error).

What about multiple strings in a TXT record?

This is a common point of confusion. DNS itself allows a single TXT record to be composed of multiple quoted strings. This feature is often used to work around the 255-character limit that many DNS providers impose on a single string within a TXT record. However, this is a function of the DNS protocol, not the SPF protocol.

repost.aws logo
Amazon Web Services, Inc. says:
Visit website
If a published record contains multiple strings, then the record MUST be treated as if those strings are concatenated together without adding spaces.

When a mail server fetches your SPF record, the DNS resolver automatically concatenates these separate strings into one single string before evaluation. For example, a DNS administrator might write a record like this:

"v=spf1 include:_spf.google.com " "include:sendgrid.net -all"

To an SPF validator, this looks identical to:

"v=spf1 include:_spf.google.com include:sendgrid.net -all"

As you can see, the separate parts are joined together, not treated as comments. Attempting to insert a comment like /* for marketing emails */ would break the syntax and invalidate the record.

So, how should you document your SPF record?

Since you can't put comments inside the record, you need to rely on external documentation. This is a good practice anyway for managing your DNS and email infrastructure. Here are a few ways I recommend handling it:

  • Use your DNS provider's notes field. Most modern DNS hosting providers have a comment or notes field for each record. This is the perfect place to explain what each part of your SPF record is for.
  • Keep internal documentation. Maintain a wiki, a shared document, or use an infrastructure-as-code solution (like Terraform) where you can add comments freely to describe your DNS setup.
  • Keep it simple. An overly complex SPF record is a sign of other problems. Try to keep your record clean and easy to read. This reduces the need for extensive comments in the first place.

Avoid other common SPF mistakes

While we're on the topic of correct syntax, the single most common SPF error I see is having multiple SPF records on a single domain. The specification explicitly forbids this.

threatcop.com logo
Threatcop says:
Visit website
In case you are wondering how many SPF records you can have on a single domain, the only correct answer is 'ONE'. If your domain has more than ...

If you have multiple records, receiving mail servers will immediately invalidate your SPF setup. You must merge all your mechanisms into a single TXT record to ensure it works correctly. In short, keep your SPF record clean, singular, and free of any comments to ensure your emails get delivered.

Start improving your email deliverability today

Get started