Skip to main content

Part of the email security and deliverability guide

SPF, DKIM and DMARC Explained, with Real Examples

What SPF, DKIM and DMARC each check, how alignment ties them to the From address, how to read pass/fail results, and a safe order to roll them out.

By Farhan Bashir7 min read
  • #email
  • #security
  • #dns
  • #deliverability
Illustration for “SPF, DKIM and DMARC Explained, with Real Examples”

Three checks, three different questions

SPF, DKIM and DMARC are often listed together as if they were one setting. They are three separate checks, published as three separate DNS records, and each answers a different question about a message. Most confusion comes from mixing up which domain each one looks at.

SPF asks whether the server that delivered the message is allowed to send for the domain in the envelope sender (the Return-Path). DKIM asks whether the message carries a valid cryptographic signature from some domain and was not altered after signing. DMARC asks whether either of those passes was for the same domain the reader sees in the From line, and tells the receiver what to do when neither was.

That last step, called alignment, is the part that actually protects your visible address. SPF and DKIM on their own can pass for any domain, including one the sender owns and you have never heard of.

SPF: which servers may use the envelope sender

An SPF record is a TXT record on the domain used in the envelope sender. A typical one reads v=spf1 include:_spf.google.com include:sendgrid.net -all. Each include: pulls in another provider's list of sending addresses, and the final -all tells receivers to fail anything not listed. ~all (softfail) asks them to treat unlisted servers as suspicious rather than failing them outright, which is the usual setting while you are still finding every service that sends for you.

SPF has two limits that cause most real failures. A domain may have only one SPF record; publishing two produces a permanent error, and receivers treat the result as if SPF were broken. And evaluating the record may trigger at most 10 DNS lookups, counting every include:, a, mx, exists and redirect, including the ones nested inside providers' records. Adding a fifth or sixth email service is the usual way a domain quietly goes over that limit.

SPF also breaks on plain forwarding. When a university or an old address forwards your message on, the forwarder's server delivers it, and that server is not in your SPF record. This is expected, and it is the main reason DKIM matters.

DKIM: a signature that survives the trip

With DKIM, the sending service signs selected headers and the body with a private key and adds a DKIM-Signature header. Two tags in that header matter when you read it: d= is the signing domain and s= is the selector. The receiver fetches the public key from a TXT record at selector._domainkey.domain, for example s1._domainkey.example.com, and checks the signature.

Because the signature travels with the message, DKIM usually survives forwarding. It fails when something changes the signed parts in transit, such as a mailing list adding a footer or rewriting the subject, or when the key in DNS does not match the one the sender used, which often happens after a provider rotates keys and the old selector is removed too early.

There is no way to list a domain's selectors from DNS. You find one by opening a message the domain sent, reading the s= value in its DKIM-Signature header, and looking up that selector. Each sending service normally uses its own.

DMARC: alignment and policy

DMARC is a TXT record at _dmarc.example.com, for example v=DMARC1; p=quarantine; rua=mailto:dmarc@example.com. A message passes DMARC when SPF passes and the envelope domain aligns with the From domain, or when DKIM passes and the d= domain aligns with the From domain. One aligned pass is enough.

Alignment is relaxed by default, which means the organizational domains must match: mail.example.com aligns with example.com. Setting aspf=s or adkim=s requires an exact match. Relaxed is the right choice for most domains.

The p= tag is the policy for messages that fail: none (deliver normally and just report), quarantine (treat as suspicious, usually the spam folder), or reject (refuse it). The rua= address receives daily aggregate reports from receivers listing which servers sent mail using your domain and whether each passed. Those reports are how you find senders you forgot about before you tighten the policy.

Example 1: everything passes and aligns

This is what a correctly configured newsletter sent through a third-party service looks like in the Authentication-Results header a receiver adds (line breaks shortened):

  • From: news@example.com
  • spf=pass smtp.mailfrom=bounces.example.com
  • dkim=pass header.d=example.com header.s=s1
  • dmarc=pass (p=REJECT) header.from=example.com

What example 1 shows

The envelope sender is a subdomain, bounces.example.com, which the sending service controls through a CNAME so it can process bounces. Under relaxed alignment it still aligns with example.com, and the DKIM signature is made with the customer's own domain rather than the service's. Either alone would have been enough for DMARC to pass. Having both means the message still passes if it is forwarded and SPF fails.

Example 2: both pass, DMARC fails

This is the most common result for a small business that signed up for a mailing service but never finished its domain setup:

  • From: hello@shop.example
  • spf=pass smtp.mailfrom=bounce.mailer-service.example
  • dkim=pass header.d=mailer-service.example
  • dmarc=fail (p=NONE) header.from=shop.example

What example 2 shows

SPF and DKIM both pass, but for the mailing service's domain, not for shop.example. Nothing aligns, so DMARC fails. Because the policy is p=none, the message is still delivered, but it now counts against the sender with large mailbox providers. The fix is in the service's settings: authenticate the sending domain, publish the DKIM records it gives you, and optionally set a custom return-path on your own subdomain.

Example 3: forwarded, SPF fails, DMARC still passes

A message from example.com, sent to an old address that forwards to a personal mailbox, arrives looking like this:

  • From: alerts@example.com
  • spf=softfail smtp.mailfrom=example.com (forwarding server not listed)
  • dkim=pass header.d=example.com header.s=s1
  • dmarc=pass header.from=example.com

What example 3 shows

The forwarding server is not in example.com's SPF record, so SPF fails. The signature survived the trip and aligns, so DMARC passes anyway. A domain that relied on SPF alone would have had this message fail DMARC. This is why every service that sends for you should sign with DKIM on your domain before you move the policy past p=none.

What a pass does not prove

DMARC protects the exact domain in the From line. It says nothing about a lookalike. An attacker who registers examp1e-support.com can publish perfect SPF, DKIM and DMARC records for it, and their phishing message will show three passes. A pass also does not help when a real account at the real domain has been taken over, since that mail is genuinely sent by the domain.

So when you check a suspicious message, read the domain in header.from character by character before you trust the results next to it. Our guide to reading email headers for phishing covers the other lines worth checking, such as Reply-To and the Received chain.

A safe order to roll them out

Moving straight to p=reject is the usual way a domain ends up blocking its own invoices or password-reset emails. This order avoids that:

  • List every service that sends as your domain: your mailbox provider, newsletter tool, help desk, billing system, website forms and any app that sends notifications.
  • Publish one SPF record that includes the services that use your domain as the envelope sender, ending in ~all, and count the DNS lookups.
  • Turn on DKIM signing with your own domain in each service and publish the selector records each one gives you.
  • Publish DMARC with p=none and a rua= address, then read the aggregate reports for two to four weeks.
  • Fix every legitimate source that fails alignment. Only then move to p=quarantine, optionally with pct=25 to apply it to a share of failing mail first.
  • When the reports show only unknown or abusive sources failing, move to p=reject. Keep reading reports, since new services get added over time.

What Gmail and Yahoo require from bulk senders

Since February 2024, Gmail and Yahoo require senders who send close to 5,000 or more messages a day to their users to authenticate with both SPF and DKIM, publish a DMARC record (p=none is enough), have the From domain align with SPF or DKIM, and offer one-click unsubscribe for marketing mail. Smaller senders still need SPF or DKIM. Following the rollout above meets the authentication part.

Mistakes we see most often

  • Two SPF records on the same domain after adding a new provider, instead of merging them into one.
  • More than 10 DNS lookups in SPF once nested includes are counted.
  • The DMARC record published at the root domain instead of at _dmarc.
  • A DKIM key published under the wrong selector name, or a host field that repeats the domain, producing s1._domainkey.example.com.example.com.
  • Using +all in SPF, which authorizes every server on the internet.
  • Sending rua= reports to a mailbox on another domain without that domain publishing the authorization record receivers check for.

Check a real domain in a few minutes

You can check all three records with the DNS lookup tool. Look up TXT on the domain to find the SPF record (the one starting v=spf1), choose DMARC to read the record at _dmarc, and choose DKIM with the selector from a message's s= tag to see the signing key. The lookup is sent to Cloudflare's public DNS-over-HTTPS resolver, so only the domain name leaves your browser.

Then paste the full headers of a message from that domain into the email header analyzer to see the results a receiver actually recorded. If a record type is unfamiliar, the DNS record types guide explains MX, TXT, CNAME and the rest, and the email security and deliverability guide shows how these checks fit with headers, phishing and inbox placement.