What an SPF Record Is and Where It Goes in DNS
An SPF record is one DNS TXT record. Its syntax, its placement and the one-record rule are where people go wrong.
Someone has asked you to publish an SPF record. This guide explains what you are publishing, where it goes, and the rules that trip people up. An SPF record is a short string of text that names the mail servers allowed to send for your domain. It sits in your DNS zone as a TXT record, and receivers read it before they accept your mail.
What an SPF record is
The SPF record is one string of text in the RDATA of a single DNS TXT resource record. That is the whole thing. It is an ordinary DNS record with SPF text in it. It is a TXT record whose content starts with a version tag, followed by mechanisms that say which servers may send.
The character content of the SPF record is encoded as US-ASCII. Keep to plain characters. Fancy punctuation or non-ASCII letters have no place in the record.
Where the record lives in the DNS tree
Each SPF record is placed in the DNS tree at the owner name it belongs to, not in a subdomain under that owner name. If your domain is example.com, the record sits at example.com. It does not sit at spf.example.com or mail.example.com.
The confusion is common, because sending domains are often subdomains. If you send from news.example.com, the SPF record that matters is the one at news.example.com. A record at the parent does not cover the child.
One record per domain name
A domain name must not have multiple records that would make an authorization check select more than one record. In plain terms, you get one SPF record per owner name. Not two. You cannot keep separate records for different sending purposes.
If you publish two, the check cannot pick between them. The receiver sees two answers to one question and treats the result as an error. Your mail gets permerror instead of an SPF pass, even though each record alone would have passed.
The fix is to merge them. Put every sending source into the one record, then delete the spare. If you use a sending tool, its SPF include usually belongs in the same record as your own servers.
Multi-string TXT records
A single TXT record can contain several strings of characters. When a record is published in several strings, those strings count as one string, concatenated with nothing between them.
A record broken across two strings is therefore evaluated as a single, joined string. That is fine in theory. In practice, avoid it. A split record is harder to read and edit. Publish the record as one string if you can.
Why SPF is TXT-only now
SPF records must be published as a DNS TXT resource record only. Use of other DNS resource record types was supported in SPF's experimental phase but has been discontinued.
Older guides may mention a dedicated SPF record type, with record type 99. That type existed once. It is gone. If your DNS panel still offers it, do not use it. Publish the record as TXT.
Record size and DNS lookups
TXT records have many uses, so other TXT records published there for other purposes might cause problems with size limits. Your SPF record shares space and size limits with any other TXT records on the same name. A very long SPF record can push against those limits.
The other limit is work. Each SPF record is evaluated with DNS lookups, and mechanisms like include, a, mx, and ptr each cost one. Publishers of SPF records ought to keep the amount of DNS information needed to evaluate a record to a minimum.
Keep the record short. Drop mechanisms for servers you no longer use. Do not nest includes deeply. SPF's standard says if the DNS lookup limit is exceeded, the implementation must return permerror.
Wildcards
Publishing through a wildcard record is not recommended, and anyone who does it needs to be careful. A wildcard TXT record on *.example.com answers for names under example.com that have no records of their own.
That sounds tidy. It is risky. A wildcard also answers for names you never meant to use for mail. It can hide that a real subdomain has no record of its own. Publish records per sending domain instead.
How SPF fits with DMARC
SPF on its own says a server was allowed to send. It does not tell the receiver whose name the mail is sent under. That is where DMARC comes in.
DMARC relies only on SPF validation of the MAIL FROM identity, not the HELO identity. The HELO name a server greets with is not checked for DMARC alignment. Only the envelope sender, the address from the MAIL FROM command, matters.
DMARC requires Identifier Alignment for the SPF-Authenticated Identifier, because any domain owner can publish an SPF record and get a pass. With no alignment check, a spammer who publishes SPF on their own domain can send mail that looks like yours and still get a pass. Alignment connects the SPF pass to the From header domain shown to your reader.
DMARC's standard says SPF for DMARC requires mail with an RFC5321.MailFrom domain that produces an SPF-Authenticated Identifier aligned with the Author Domain. DMARC recommends that domain owners use both DKIM and SPF as the underlying authentication mechanisms. DMARC passes on either one, but its standard recommends both.
Relaxed vs strict alignment
The aspf tag in your DMARC record sets how strict this match must be. Google Workspace Help says the aspf tag sets the alignment policy for SPF, which specifies how strictly message information must match SPF signatures.
Relaxed alignment is the default. Google Workspace Help says relaxed SPF alignment is the default and accepts any valid subdomain of the domain name. It requires the From header domain to match or be a subdomain of the Envelope-Sender address domain. So mail from news.example.com with a From header of example.com aligns.
Strict alignment demands more. Google Workspace Help says strict SPF alignment requires an exact match between the Envelope-Sender address domain and the From header address domain. It requires the message From header to exactly match the domain name in the SMTP MAIL FROM command. With strict alignment, news.example.com fails to match example.com.
Most senders use relaxed. Choose strict only if every system that sends for you puts the exact parent domain in the envelope sender.
A dns spf record example, annotated
Here is a dns spf record example, piece by piece.
v=spf1 include:_spf.mailprovider.example ~all
v=spf1is the version tag. It must come first. Without it, the record is not an SPF record.include:_spf.mailprovider.examplesays to check the SPF record at _spf.mailprovider.example and match its servers too. Each include costs a DNS lookup.~allis the default result for servers not named anywhere in the record. The tilde means softfail, a weak statement that the host is probably not authorized, and SPF's standard says receiving software should not reject a message based solely on a softfail result.
Change the include to match your real mail provider. If you send from your own servers, use an ip4: mechanism with your server addresses instead. End with ~all or -all. -all returns fail for anything not listed, and SPF's standard says the action to take is determined by the local policies of the receiver.
One record, one string, at the owner name, as TXT. Get those four things right and the rest is detail. Your sending tool may ask for other DNS records too. Gmail wants the one-click unsubscribe headers. Skip any check against a list like SORBS, which no longer runs. SPF is only one piece, but it is the piece that says which servers may speak for your domain.
Sources
Filed