Email security

SPF Record Syntax Explained: Mechanisms, Qualifiers and Examples

One short TXT record decides whether receiving servers trust mail from your domain. Here is every SPF term, what it does, and how to write a record that works.

Cysoro Security TeamPublished · 9 min read
EMAIL SECURITY SPF Record Syntax Mechanisms, qualifiers and working examples v=spf1include:_spf.google.comip4:203.0.113.10-all
Quick answer

SPF record syntax is a single DNS TXT record that starts with v=spf1, followed by space-separated mechanisms such as ip4, include and a, each optionally prefixed by a qualifier such as + or -, and usually ending in -all. Receiving servers test the mechanisms left to right and stop at the first match, so order and the 10-DNS-lookup limit matter.

Key takeaways

  • Every SPF record starts with v=spf1, lists authorized senders as mechanisms, and usually ends with -all.
  • Qualifiers decide the result when a mechanism matches: + passes, - fails, ~ soft-fails and ? is neutral.
  • SPF is limited to 10 DNS lookups, so flatten includes and prefer ip4 and ip6 where you can.

An SPF record is one line of text in your DNS, yet a single wrong term can send your invoices to spam or let an attacker spoof your domain. Learn the grammar once, and you can read and fix any record in minutes.

What is SPF record syntax?

SPF record syntax is the grammar of a single DNS TXT record that starts with v=spf1, followed by space-separated terms that list the servers allowed to send mail for your domain.

SPF stands for Sender Policy Framework. It is defined in RFC 7208, published in April 2014, which replaced the earlier experimental RFC 4408. The record lives at the apex of your domain, as a TXT record, not as the old separate SPF record type, which RFC 7208 dropped.

A typical record looks like this:

v=spf1 include:_spf.google.com ip4:203.0.113.10 -all

Receiving servers test the terms from left to right and stop at the first mechanism that matches the sending IP address. The qualifier in front of that mechanism decides the result. If nothing matches, the final all term decides.

What are the parts of an SPF record?

Every SPF record has three kinds of parts: a version tag, mechanisms with optional qualifiers, and modifiers. The version tag always comes first, and modifiers never match an IP address.

Anatomy of an SPF recordv=spf1 include:_spf.google.com ip4:203.0.113.10 -allv=spf1version tagalways firstinclude: / ip4:mechanismsauthorized senders- before allqualifierfail if matched-allcatch-all termgoes lastTerms are separated by spaces. Evaluation runs left to right and stops at the first match.
An SPF record has a version tag, mechanisms, qualifiers and a final all term. Illustration by Cysoro.
PartFormRole
Version tagv=spf1Identifies the record as SPF version 1; must be first and exact
Mechanismname[:argument][/cidr]Tested against the sending IP; matches or does not match
Qualifier+, -, ~ or ?Result returned when its mechanism matches
Modifiername=valueExtra information; never matches an IP

Mechanism names are case-insensitive, and terms are separated by single spaces. A term with no =, : or / is a mechanism, while a term containing = is a modifier.

What are the SPF mechanisms?

RFC 7208 defines eight mechanisms. Each one either matches the connecting IP address or does not, and some cost a DNS lookup while others cost none.

MechanismExampleMatches when the sender IP…DNS lookups
all-allAlways matches; placed last as the catch-all0
ip4ip4:203.0.113.0/24Is in this IPv4 address or range0
ip6ip6:2001:db8::/32Is in this IPv6 address or range0
aa:mail.example.comIs an A or AAAA address of that domain1
mxmx:example.comIs an address of one of the domain's mail servers1 or more
includeinclude:_spf.google.comPasses the included domain's SPF record1 plus its lookups
existsexists:%{i}.spf.example.comThe constructed name resolves to any A record1
ptrptrReverse DNS validates into the domain; discouraged1

ip4 and ip6 are the cheapest and most predictable terms because they need no DNS lookup at all. Use them for your own mail servers and any fixed sending IP you control.

include is how you authorize a third-party sender such as Google Workspace or Microsoft 365. It imports that provider's SPF policy, but every lookup inside the included record counts toward your limit of ten.

a and mx accept an optional CIDR prefix, so a:mail.example.com/28 authorizes the whole /28 network around that host. ptr exists in the standard but RFC 7208 says it should not be published, because it is slow and unreliable.

What do the SPF qualifiers mean?

A qualifier is the single character in front of a mechanism. It decides the result when that mechanism matches, and the default qualifier, when you write none, is + for pass.

QualifierResult if matchedTypical use
+PassDefault; include:_spf.google.com means the same as +include:_spf.google.com
-Fail-all: unlisted senders are rejected
~Softfail~all: unlisted senders are suspect but usually accepted
?Neutral?all: no opinion; rarely justified

Choose -all when you are confident you have listed every legitimate sender. It is the only ending that tells receivers to reject spoofed mail outright, and it is what DMARC enforcement needs to work well.

Use ~all only while you are still discovering senders, for example during the first weeks after publishing SPF. It lets mail through while you watch DMARC reports for senders you missed, so you do not block real mail by mistake.

A qualifier on an early mechanism can also be useful. Writing -ip4:203.0.113.99 explicitly fails one known bad host, even though -all at the end would catch it anyway.

What are SPF modifiers?

Modifiers provide extra information but never match an IP address. RFC 7208 defines only two: redirect= and exp=, and each may appear at most once in a record.

redirect=_spf.example.com replaces the whole evaluation with the record of the named domain when nothing else in your record matched. It counts as one DNS lookup. It is useful when several domains should share one central policy.

exp=explain.example.com points to a TXT record containing an explanation string that receivers can show when they reject mail. It is rarely used in practice, because most receivers do not display it.

Do not confuse modifiers with mechanisms. A modifier never authorizes a sender, and placing redirect= in the middle of a record does not stop evaluation early; it only applies if no mechanism matched first.

What are common SPF record examples?

Real records are short, and each one follows the same pattern. Start from the closest example below, then swap in your own providers.

Google Workspace only

v=spf1 include:_spf.google.com -all

This authorizes Google's mail servers and fails everything else. It is the standard record for a domain that sends mail only through Google Workspace.

Microsoft 365 only

v=spf1 include:spf.protection.outlook.com -all

This authorizes Microsoft 365's mail servers. If you also send from your website or a CRM, add those senders before -all.

Office suite plus a website and a CRM

v=spf1 include:_spf.google.com include:mail.zendesk.com ip4:203.0.113.10 -all

This record authorizes Google, Zendesk and one application server. Notice the order: includes first, then the fixed IP, then the catch-all. Order does not change correctness here, but putting cheap ip4 terms early can save lookups in some setups.

Domain that sends no mail

v=spf1 -all

A domain that never sends mail should still publish this record. It tells the world that every message claiming to come from it is fake, which protects your brand and helps receivers reject spoofing.

After publishing, check the result with our free SPF checker, which shows your record, counts lookups and flags common errors.

What is the SPF 10-DNS-lookup limit?

SPF evaluation is limited to ten DNS lookups. If a record needs more, the receiver returns a permanent error, known as permerror, and the check fails.

The 10-lookup limit adds up fastYour record: 1 lookupinclude: provider AProvider A record: 3 lookupsits own includesProvider B record: 4 lookupsits own includesTotal so far: 8 of 10 usedonly 2 leftEach include brings its own lookups with it. Flatten includes you control.ip4 and ip6 terms cost zero lookups. Source: RFC 7208, section 10.1.
Nested includes count toward your ten lookups. Illustration by Cysoro.

Mechanisms that trigger lookups are include, a, mx, ptr and exists, plus the redirect modifier. ip4, ip6 and all trigger none. The limit is defined in section 10.1 of RFC 7208.

Large providers can be expensive. One include may itself contain several more includes, so two providers can easily consume eight or nine lookups between them. That is why records with five or six includes often break.

To stay under the limit, replace includes with their IP ranges where the provider publishes them, remove senders you no longer use, and use a flattening service or script that expands nested includes into ip4 and ip6 terms. Re-check after every change, because providers change their records without telling you.

One record onlyPublishing two SPF TXT records for the same domain causes a permanent error. Merge every sender into one record instead of adding a second one.

How do you write an SPF record step by step?

Writing a record takes ten minutes if you list your senders first. Guessing senders later is how records break, so do the inventory before you touch DNS.

  1. List every sender. Include your office suite, website, CRM, marketing tool, helpdesk, invoicing system and any server that sends mail directly.
  2. Get each provider's SPF value. Use the provider's own documentation, not a blog copy, because include names change.
  3. Draft the record. Start with v=spf1, add the mechanisms, and end with ~all while testing.
  4. Count the lookups. Add up the lookups for every include, a and mx, including nested ones. Stay well under ten.
  5. Publish one TXT record at the domain apex, with no extra SPF record type.
  6. Test it. Send test mail, check the headers, and run the SPF checker to confirm the record resolves and passes.
  7. Move to -all once DMARC reports show no legitimate sender is missing, usually after two to four weeks.

Keep the record under 255 characters per DNS string if your provider splits long TXT records, and avoid spaces inside mechanisms. A stray space after a colon breaks the term.

What are the most common SPF syntax mistakes?

Most SPF failures come from a short list of avoidable errors. Check for these before you blame your provider or the receiving server.

  • Multiple SPF records. Two TXT records starting with v=spf1 cause a permanent error.
  • Too many lookups. Six includes from big providers can exceed ten lookups once nested includes are counted.
  • Missing a sender. A new marketing tool or helpdesk sends mail that fails because nobody added its include.
  • Typo in an include. One wrong character means the include resolves to nothing, or to someone else's record.
  • ptr in the record. Slow, unreliable and discouraged by RFC 7208.
  • +all at the end. This passes every sender in the world and defeats the whole point of SPF.
  • Forgetting subdomains. SPF does not inherit from the parent domain, so mail.example.com needs its own record if it sends mail.

SPF also has a real limit you should know: it checks the envelope sender domain, not the From address shown in the inbox. That is why SPF alone cannot stop all spoofing. Our guide to what DMARC is explains how DMARC ties SPF and DKIM to the visible From domain.

Our DKIM guide covers the signing half of the pair, and the DMARC.com SPF reference walks through the same syntax with more provider examples.

How does SPF work with DKIM and DMARC?

SPF, DKIM and DMARC are three separate checks that work best together. SPF authorizes the sending server, DKIM proves the message was not altered, and DMARC decides what to do when either check fails.

For DMARC to pass, SPF or DKIM must pass and align with the From domain. Alignment means the domain SPF checked matches the domain in the From address. An SPF pass for a third-party return-path domain does not count for DMARC unless that domain aligns.

That is the practical reason to keep your SPF record clean: a broken SPF record can break DMARC alignment for legitimate mail, while a strict -all record makes DMARC enforcement far more effective. Check all three together with the email security score tool.

The bottom line

SPF record syntax is simple once you see the pattern: v=spf1, then your authorized senders, then -all. The hard part is keeping the sender list complete and the lookup count under ten.

List every sender, publish one record, test it, then tighten it to -all and add DKIM and DMARC. You can verify your record in seconds with the free SPF checker.

Frequently asked questions

What is SPF record syntax in simple terms?

SPF record syntax is the grammar of one DNS TXT record. It starts with v=spf1, then lists the servers allowed to send mail for your domain, and usually ends with -all to reject everything else.

What does v=spf1 mean?

It is the version tag that identifies the record as SPF version 1. It must be first and exact. A record starting with anything else, such as v=spf10, is ignored by receiving servers.

What is the difference between -all and ~all?

The -all ending tells receivers to fail mail from unlisted senders, which is the strict choice. The ~all ending only soft-fails it, so mail is usually accepted but flagged as suspicious.

How many DNS lookups can an SPF record use?

Ten. Mechanisms that need DNS lookups, such as include, a, mx and exists, count toward the limit. If a record needs more than ten, receiving servers return a permanent error.

Can I have more than one SPF record?

No. A domain must have exactly one SPF record. Multiple records cause a permanent error, so combine all your senders into a single TXT record.

Does SPF protect my domain on its own?

No. SPF only checks the envelope sender domain, not the From address people see. Pair it with DKIM and DMARC so the visible From domain is protected too.

Why is my SPF record failing?

Common causes are too many DNS lookups, more than one SPF record, a missing sender, a typo in an include, or a record longer than the DNS limit. Check each term against your providers list.

Should I use the ptr mechanism?

No. RFC 7208 says ptr should not be published because it is slow and unreliable. Use ip4, ip6, a or include instead.

Sources

  1. IETF — RFC 7208: Sender Policy Framework (SPF)
  2. DMARC.com — SPF record: the complete reference guide
  3. EmailValidation.io — SPF Record: Syntax, Examples and Setup
  4. TechTarget — How to create and add an SPF record
Written & fact-checked byCysoro Security Team

The engineers and analysts who build Cysoro's domain scanner, email-authentication checks and free security tools. We test what we write about every day — SPF, DKIM, DMARC, certificates, look-alike domains and phishing — and check each guide against the relevant standards, government guidance and vendor documentation.

  • Email authentication
  • Phishing & BEC
  • Domain & DNS security
  • Small-business security

Checked against RFC 7208 and SPF reference guides from DMARC.com and EmailValidation.io.

How we write and fact-check →

Free tools for this topic

No account needed.

See where your domain stands

Free for up to 3 domains. No card, no installs.

Start free