# Split Long SPF & DKIM TXT Records Over 255 Characters Without Whitespace Corruption

> How RFC 1035 255-octet character-strings concatenate WITHOUT spaces per RFC 7208 §3.3, fixing include:fooinclude:bar boundary fusion bugs in BIND, Route53, and Terraform.

- **Canonical URL**: https://opslint.dev/spf/spf-255-character-txt-string-splitting/
- **Category**: `SPF`
- **Interactive Workbench**: [Open in Live Workbench](https://opslint.dev/spf/#domain=salesforce.com)
- **Normative Specifications**: `RFC 1035 §3.3.14 (TXT RDATA 255-Octet <character-string> Limit)`, `RFC 7208 §3.3 (Multiple Strings in a Single DNS Record: Zero-Space Concatenation)`, `RFC 7208 §3.4 (450-Octet UDP Packet Size Guidance)`

## Incident Symptom & Root Cause

**Production Symptom**: Saving a 290-character SPF or 2048-bit DKIM TXT record in AWS Route53, BIND, or Terraform fails with CharacterStringTooLong (max 255 bytes)—or after splitting into two quoted strings "...include:a.com" "include:b.com...", SPF breaks with PermError: Unknown mechanism 'a.cominclude:b.com'!

**Protocol / Engine Root Cause**: DNS wire format encodes a single TXT resource record as one or more length-prefixed <character-string> chunks, each capped at 255 bytes (RFC 1035). Per RFC 7208 §3.3, receivers concatenate multiple strings inside a single TXT record directly WITH NO ADDED SPACES! Omitting a trailing space inside quote #1 or a leading space inside quote #2 fuses the two adjacent tokens together!

## Remediation Diff (Broken vs Verified Fix)

### Two Classic >255-Byte TXT Splitting Failures

```text
; FAILURE 1: Missing space at string boundary!
; Concatenates to "...ip4:198.51.100.0/24include:_spf.google.com..." -> PermError!
example.com. 3600 IN TXT "v=spf1 ip4:192.0.2.0/24 ip4:198.51.100.0/24" "include:_spf.google.com -all"

; FAILURE 2: Creating TWO separate TXT records instead of two strings in ONE record!
example.com. 3600 IN TXT "v=spf1 ip4:192.0.2.0/24 ip4:198.51.100.0/24"
example.com. 3600 IN TXT "include:_spf.google.com -all"
```

### RFC 7208 §3.3 Boundary-Space Multi-String Single TXT Record

```text
; BIND / Route53 Zone Syntax: ONE single TXT RR containing two <=255-byte quoted strings!
; Notice the explicit trailing space at the end of string #1 ("...100.0/24 ")!
example.com. 3600 IN TXT (
  "v=spf1 ip4:192.0.2.0/24 ip4:198.51.100.0/24 ip4:203.0.113.0/24 "
  "include:_spf.google.com include:spf.mtasv.net -all"
)

# Terraform aws_route53_record (single array element containing escaped quotes!):
# records = ["v=spf1 ip4:192.0.2.0/24 ... " "include:_spf.google.com -all"]
```

## Engineering Deep Dive

Distinguish carefully between 'two TXT records in an RRset' (which leaves the second fragment ignored or causes PermError!) versus 'one TXT record whose RDATA contains two <character-string> segments'! In BIND zone syntax and AWS Route53, two separate array items in Terraform aws_route53_record.records = ["chunk1", "chunk2"] create TWO separate TXT records! To create ONE multi-string TXT record in Route53 Terraform, pass a SINGLE element in records with inner escaped quotes separating chunks: records = ["chunk1 " \" \"chunk2"]. (By contrast, Porkbun and some web DNS dashboards automatically split >255-byte inputs at the wire layer for you.)

Always verify the exact wire reconstruction from an external resolver with dig +short TXT example.com! When dig prints "chunk1 " "chunk2" on the SAME output line, you have a single multi-string TXT record; when dig prints them on two separate lines, you accidentally created two distinct TXT records! Mentally delete the middle " " sequence in dig's single-line output: for SPF, there MUST be exactly one space between mechanisms (so end chunk 1 with a space); for 2048-bit DKIM base64 keys (p=MIIBIjANBgkq...), there MUST be ZERO spaces inside the base64 key (or split clean base64 directly without spaces)!

Even though EDNS0 allows DNS UDP responses larger than the historic 512-byte ceiling, RFC 7208 §3.4 still recommends keeping your total SPF TXT response packet under 450–512 bytes so legacy middleboxes that drop fragmented UDP or block TCP port 53 fallback do not cause TempError timeouts. If static ip4:/ip6: lists push your root SPF past 450 bytes, move those CIDR blocks into a child TXT record (_netblocks.example.com) and reference include:_netblocks.example.com (costing just 1 lookup).

## Multi-String >255-Byte TXT Rules Across SPF vs DKIM

| Case / Engine | Protocol Behavior | Production Remediation |
| :--- | :--- | :--- |
| **Long SPF TXT (>255 bytes)** (`#split-spf-space-required`) | Concatenated with zero added delimiter; splitting without a boundary space fuses mechanisms. | Split ONLY between tokens and keep a trailing space at the end of chunk 1: "...ip4:1.2.3.0/24 " "include:...". |
| **2048-bit DKIM public key (~400 bytes)** (`#split-dkim-2048-base64`) | Concatenates base64 segments directly: "v=DKIM1; k=rsa; p=MIIBI..." "...IDAQAB". | Split inside p= with zero extra spaces (though RFC 6376 §3.6.1 FWS ignores spaces in base64, zero-space splits are cleanest). |
| **AWS Route53 Terraform records = [...]** (`#split-route53-terraform`) | Multiple list elements create separate TXT records instead of multi-string RDATA! | Use a single list string with escaped inner quotes: records = ["part1 \" \"part2"]. |
| **Total TXT RRset > 450–512 bytes** (`#split-udp-512-size`) | Triggers EDNS0 / TCP DNS fallback; broken enterprise firewalls blocking TCP/53 cause SPF TempError. | Move long ip4:/ip6: lists into include:_ipblocks.example.com to keep apex TXT compact. |

## Frequently Asked Engineering Questions

### How can I test my live domain's concatenated SPF string from bash in one command?

Run dig +short TXT example.com | grep -i 'v=spf1' | sed 's/" "//g' — removing '" "' replicates exact RFC 7208 §3.3 concatenation so any fused token like '24include:' stands out immediately!

### Why does 255 characters fail at 250 characters when my TXT record contains non-ASCII or escaped quotes?

RFC 1035 caps each <character-string> at 255 octets (bytes), not Unicode code points—though SPF/DKIM records must strictly contain printable 7-bit US-ASCII anyway.

### Do Cloudflare DNS or Porkbun DNS require manual " " chunking in their UI?

Modern DNS control panels often auto-chunk strings exceeding 255 octets on save, whereas raw zone files (BIND, PowerDNS, Knot) and AWS Route53 API/Terraform enforce strict 255-octet <character-string> syntax directly.

## Related Problem-Cluster Guides

- [Fix Multiple SPF TXT Records PermError: How to Merge Two v=spf1 Records Safely](https://opslint.dev/spf/multiple-spf-txt-records-merge-guide/) — Why publishing two separate v=spf1 TXT records on the same hostname triggers immediate RFC 7208 §4.5 PermError, and the exact algorithm to merge them into one.
- [DKIM 2048-Bit RSA Key Rotation, Selector Naming, and CNAME Vendor Delegation](https://opslint.dev/dmarc/dkim-2048-bit-key-rotation-and-cname-delegation/) — Upgrade weak 1024-bit DKIM keys to 2048-bit RSA without mid-flight verification failures using dual-selector blue/green rotation and vendor CNAME delegation.
- [Why Manual Static SPF IP Flattening Breaks Production Email (And Safer Alternatives)](https://opslint.dev/spf/static-ip-flattening-stale-netblocks-risks/) — Understand how inlining ip4:/ip6: CIDRs from Google, Microsoft, or SendGrid causes silent delivery outages when cloud netblocks rotate, plus zero-maintenance alternatives.
- [Fix SPF PermError: Too Many DNS Lookups (Exceeding the RFC 7208 10-Lookup Limit)](https://opslint.dev/spf/permerror-too-many-dns-lookups-10-limit/) — Understand which SPF mechanisms count toward RFC 7208 §4.6.4's hard 10-lookup ceiling, why nested vendor includes blow the budget, and how to cut lookups safely.
