The maximum length of an SPF record is a common source of confusion. Many people see a '255 character limit' warning and believe their entire SPF record must be shorter than that. While there is a limit, it doesn't work the way most people think. The short answer is that an individual string within a TXT record is limited to 255 characters, but you can use multiple strings to create a much longer SPF record.
This distinction is critical for creating a valid SPF record that doesn't cause validation issues for your emails.
The technical specification for DNS, which SPF is built upon, defines a limit for a single character string in a TXT record. According to RFC 7208, the protocol that defines SPF, an SPF record is stored within a TXT record. The TXT record type itself has a limitation where a single text string cannot be longer than 255 bytes (or characters).
However, the same rules allow a single TXT record to contain multiple character strings. When an email server looks up your SPF record, it's designed to fetch all these individual strings and concatenate them, or join them together, into a single line of text before evaluating it. This means you can create an SPF record that is much longer than 255 characters by simply splitting it into multiple quoted strings.
While you can split your record into multiple 255-character strings, there is still a practical limit on the total length of the TXT record. Most DNS providers will support a total length of several thousand characters. For example, Amazon Web Services states that they support a maximum value of 4,000 characters.
The more important limitation you will almost certainly encounter first is the SPF 10 DNS lookup limit. The SPF specification states that a record cannot require more than 10 DNS lookups to be fully resolved. Mechanisms like include, a, mx, and exists all count towards this limit. Long SPF records are often a symptom of having too many services, which leads to exceeding this lookup limit.
To format an SPF record longer than 255 characters, you must break it down into separate strings, each enclosed in double quotes ("). Your DNS provider's interface should allow you to enter these strings one after another in the value field for the TXT record.
For example, a long SPF record might look like this in your DNS zone file:
"v=spf1 include:_spf.google.com include:sendgrid.net include:servers.mcsv.net" " include:mail.zendesk.com ip4:192.168.0.1 ~all"
Thankfully, many modern DNS hosting providers have simplified this. They often provide a single large text box where you can paste your entire SPF record, and they will automatically split it into 255-character chunks for you behind the scenes. It's always a good idea to use an SPF checker tool after making changes to ensure it's being read correctly.
When managing SPF records, especially long ones, a few common mistakes can lead to major email deliverability problems.
In conclusion, the 255-character limit for SPF records is not as restrictive as it seems. By understanding that it applies to individual strings within a TXT record, you can create valid records that are much longer. However, always be mindful of the more critical 10-lookup limit, as this is the constraint that typically causes problems for growing businesses.
What is the maximum 'pct' value in a DMARC record?
What is the maximum number of characters allowed in a DMARC TXT record?
What is the maximum recommended key length for DKIM?
Does a DKIM record use the 'TXT' DNS record type?
What is the maximum number of DNS lookups allowed in an SPF record?
What DNS record type is used for SPF?