After a domain's SPF record grows past 255 characters, how should its TXT value be split, and why keep the whole answer under 512 octets?
answer
- one record, many strings
- joined with nothing in between
- where the space must live
- 512 for the answer, 450 to plan
basics
~20 sSplit the value into quoted strings of at most 255 octets inside one TXT record; receivers join them with no added space. RFC 7208 says the answer SHOULD fit 512 octets, planning on 450 for the name plus all its TXT records.
solid answer
~50 sA single `TXT` record can hold several character-strings of up to 255 octets each, and RFC 7208 section 3.3 says they MUST be joined **without adding spaces**, so the space between two terms has to sit inside a string, at the end of one or the start of the next. Splitting across two separate TXT records instead is a different thing: two records beginning `v=spf1` give `permerror`, and a second record without the tag is discarded, silently dropping its terms. Section 3.4 says the answer SHOULD fit within 512 octets, so it travels in plain UDP without older resolvers falling back to TCP, and gives 450 octets as the guideline for the name plus the text of every record of that type, verification tokens included. Records too big for one UDP packet could be silently ignored by verifiers when firewalls interfere with TCP or EDNS0.
code
dns · 4 lines; one TXT record made of two character-strings;
; the space separating the terms sits at the end of the first string
example.com. 3600 IN TXT ( "v=spf1 ip4:192.0.2.0/24 ip4:198.51.100.0/24 "
"ip6:2001:db8:10::/48 include:spf.example.net -all" )go deeper
Recall that one TXT record can hold several strings of up to 255 octets each, joined with no space.
Explain the joining rule and why a missing space breaks the record, and why several strings in one record differ from several records.
Show you can keep an apex answer healthy: count every TXT record at the name against the 450-octet guideline, and shrink it without breaking the lookup budget.
Weigh the levers: removing stale senders, separate envelope subdomains and moving tokens off the apex each cost differently, and someone must own the measurement after changes.
## One record, several strings DNS limits a single **character-string** to 255 octets, but a `TXT` record may contain several of them, each written as its own quoted string. RFC 7208 section 3.3 uses that to let an SPF record grow beyond 255 octets: the record stays **one** `TXT` resource record, made of two or more strings. In a zone file the strings sit side by side, often wrapped in parentheses across lines: ```dns example.com. 3600 IN TXT ( "v=spf1 ip4:192.0.2.0/24 ip4:198.51.100.0/24 " "ip6:2001:db8:10::/48 include:spf.example.net -all" ) ``` ## The joining rule: nothing is added Section 3.3 says a record with several strings **MUST be treated as if those strings are concatenated together without adding spaces**. Its own example turns `"v=spf1 .... first" "second string..."` into `"v=spf1 .... firstsecond string..."`. So the space that separates two terms has to be inside one of the strings. | How the record is split | What the receiver reads | Outcome | |---|---|---| | `"v=spf1 ip4:192.0.2.0/24 "` `"mx -all"` (trailing space) | `v=spf1 ip4:192.0.2.0/24 mx -all` | Correct | | `"v=spf1 ip4:192.0.2.0/24"` `" mx -all"` (leading space) | `v=spf1 ip4:192.0.2.0/24 mx -all` | Correct | | `"v=spf1 ip4:192.0.2.0/24"` `"mx -all"` (no space) | `v=spf1 ip4:192.0.2.0/24mx -all` | A malformed term, so `permerror` | | Split in the middle of a term, `"...inclu"` `"de:spf.example.net..."` | The term rejoined intact | Correct, though hard to review | The third row matters because RFC 7208 section 4.6 validates the whole record first: a syntax error anywhere returns `permerror` without evaluating a single mechanism. The fourth row works but is a review trap; split at a space between terms whenever you can. ## Two strings is not two records The tempting shortcut is to publish the overflow as a second `TXT` record. That changes the meaning completely: - If both records begin `v=spf1`, the receiver selects two SPF records and returns **`permerror`** (section 4.5). - If only the first begins `v=spf1`, the second is discarded at selection, and every term in it **silently vanishes** from the policy. Mail from those senders then falls through to the record's `all`. Several strings inside one record are joined; several records are never joined. RFC 7208's own Appendix A.4 shows the habit worth copying: every string in its multi-string example ends with a space, starting with `"v=spf1 "`, so the strings can be read, reordered in review and rejoined without fusing two terms. ## The size guidance: 512 and 450 octets Section 3.4 asks publishers to keep the answer small: 1. The published SPF record **SHOULD** remain small enough that the results of a query for it fit within **512 octets**. That is the classic DNS-over-UDP limit; staying under it avoids older DNS implementations falling back to TCP and works where EDNS0, the extension that allows larger UDP answers, is missing. 2. Because the full answer depends on things outside SPF, the RFC gives a planning guideline: if the combined length of the DNS name and the text of **all the records of that type** is under **450 octets**, answers ought to fit in UDP. 3. Records too long for a single UDP packet **could be silently ignored** by SPF verifiers, because firewalls and similar problems interfere with DNS over TCP or with EDNS0. The phrase "all the records of that type" is the operational catch: every other `TXT` record at the same name, such as verification tokens for outside services, shares the answer and counts toward the 450. The SPF text alone can be modest while the answer is not. How UDP truncation and the fallback to TCP work belongs to DNS itself; the SPF lesson is to keep the answer small enough never to need it. ## When the record keeps growing - **Remove what is stale.** Senders the organisation no longer uses, duplicate ranges, overlapping terms. - **Move verification tokens** to their own names where the service that asked for them allows it, so they stop sharing the apex answer. - **Move a group of terms behind an `include`** of a name you control. That shortens the apex record, but every `include` spends one of SPF's 10 DNS lookups, so it trades size for lookup budget. - **Give an outside sender its own envelope subdomain**, so its policy lives at another name with its own answer. - **Measure after every change**: the total TXT answer at the name, not just the SPF string.
- Why might splitting the SPF value across two TXT records seem to work at first?If only the first record begins `v=spf1`, the receiver still finds one SPF record and evaluates it, so the domain gets no error. The second record is simply discarded, so the senders listed in it stop matching and fall through to `all`, which shows up as failures for those senders only.
- The SPF string is 300 octets but the TXT answer is over 600. How is that possible?RFC 7208's guidance counts the name plus the text of every record of that type at the name. Verification tokens and other TXT records at the apex share the answer, so they can push it past 512 octets even when the SPF record alone is well within the limit.
- Receivers join the character-strings of an SPF record with a space.
- A long SPF record should be split into several TXT records.
- A single TXT record can never exceed 255 octets in total.
- Only the SPF string counts toward the 512-octet answer guidance.
- Answers over 512 octets are always fetched over TCP, so size does not matter.