0Pricing
Cyber Security Academy · Lesson

SPF Records

Authorizing sending mail servers.

SPF Records is a free Cyber Security Academy lesson on CoddyKit — lesson 2 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Cyber Security Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

What SPF Solves

SPF (Sender Policy Framework) lets a domain owner publish a list of mail servers authorized to send email on the domain's behalf. Receiving servers check this list to detect forged senders.

SPF answers one question: Is the server that delivered this message allowed to send mail for this domain? If not, the message is suspicious.

Published as a DNS TXT Record

An SPF policy is published as a TXT record in your domain's DNS. There must be exactly one SPF record per domain.

A basic example:

; DNS TXT record for company.com
company.com.  IN  TXT  "v=spf1 ip4:198.51.100.4 include:_spf.google.com -all"

How Receivers Check SPF

When a receiving server gets a message, it performs the SPF check:

  • Read the envelope MAIL FROM domain (the Return-Path)
  • Look up that domain's SPF TXT record in DNS
  • Compare the connecting server's IP against the authorized list
  • Return a result: pass, fail, softfail, neutral, or none

Note SPF checks the envelope sender, not the visible From header, an important limitation covered later.

SPF Mechanisms

An SPF record is built from mechanisms that describe authorized senders:

ip4:198.51.100.4      authorize a single IPv4 address
ip4:198.51.100.0/24   authorize an IPv4 range
ip6:2001:db8::/32     authorize an IPv6 range
a                     authorize the domain's A record IP
mx                    authorize the domain's MX servers
include:_spf.vendor   include another domain's SPF (vendors)
all                   matches everything (use with a qualifier)

Qualifiers and the all Mechanism

Each mechanism can have a qualifier that sets the result when it matches:

+   Pass     (default if omitted)
-   Fail     (hard fail - reject)
~   SoftFail (mark suspicious, usually accept)
?   Neutral  (no policy stated)

Endings:
-all   reject anything not listed   (strict, recommended)
~all   soft-fail unlisted senders   (monitoring / rollout)
+all   allow everyone               (NEVER use - defeats SPF)

The include Mechanism for Vendors

Most organizations send mail through third-party services: Google Workspace, Microsoft 365, marketing platforms, ticketing systems. The include mechanism delegates to those vendors' own SPF records.

For example, include:_spf.google.com pulls in Google's authorized ranges. This keeps your record maintainable, the vendor updates its ranges and you do not have to.

Every legitimate sending service must be included, or its mail will fail SPF.

The 10 DNS Lookup Limit

SPF imposes a hard limit: evaluating a record may trigger at most 10 DNS lookups. Mechanisms like include, a, and mx each consume lookups, and nested includes add up fast.

Exceeding the limit produces a permerror, and the SPF check effectively fails. Mitigations:

  • Remove unused includes
  • Use SPF flattening to replace includes with raw IP ranges
  • Consolidate sending services

SPF and Forwarding Break

SPF has a well-known weakness: forwarding breaks it. When a message is auto-forwarded, the forwarding server becomes the new connecting IP, which is not in the original domain's SPF record.

The result is an SPF failure for a perfectly legitimate message. This is a key reason SPF alone is insufficient and why DKIM (which survives forwarding) and DMARC alignment are needed alongside it.

SPF Only Checks the Envelope

A critical limitation: SPF validates the envelope MAIL FROM domain, not the visible From header the user sees.

An attacker can pass SPF for their own domain in the envelope while still displaying your domain in the From header. SPF alone would say 'pass' even though the message is spoofed to the reader.

DMARC closes this gap by requiring the envelope or DKIM domain to align with the visible From.

Deploying SPF Safely

Roll SPF out carefully to avoid blocking legitimate mail:

  • Inventory every service that sends mail as your domain
  • Build the record with all required includes
  • Start with ~all (softfail) and monitor for missed senders
  • Once confident, tighten to -all (hardfail)
  • Stay under the 10-lookup limit

Test with a mail tester before and after each change. A wrong SPF record can silently send your own mail to spam.

A Realistic SPF Record

Here is a record for an organization using Google Workspace plus a marketing and a support vendor:

company.com.  IN  TXT  "v=spf1 \
  include:_spf.google.com \
  include:sendgrid.net \
  include:_spf.supportvendor.com \
  ip4:198.51.100.4 \
  -all"

; Listed senders pass; everything else hard-fails.

Quick Check

Test your understanding of SPF.

Recap

You learned how SPF works:

  • SPF publishes a DNS TXT record listing servers authorized to send for a domain
  • Receivers check the envelope MAIL FROM domain against the connecting IP
  • Built from mechanisms (ip4, a, mx, include) and qualifiers, ending in -all or ~all
  • Beware the 10-lookup limit, forwarding breakage, and that SPF only checks the envelope, not the visible From
  • Roll out with softfail, monitor, then tighten to hardfail

Next, you will learn how DKIM cryptographically signs messages.

Frequently asked questions

Is the “SPF Records” lesson free?

Yes — the full text of “SPF Records” is free to read here on the web, and the Cyber Security Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Cyber Security Academy course, upgrade to CoddyKit PRO.

What will I learn in “SPF Records”?

Authorizing sending mail servers. You practise Cyber Security Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Cyber Security Academy?

No prior experience is required. Cyber Security Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 2 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “SPF Records” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Cyber Security Academy lesson?

Yes. Every Cyber Security Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. How Email Spoofing Works
  2. SPF Records
  3. DKIM Signing
  4. DMARC Policy and Reporting
← Back to Cyber Security Academy