FortWatch.ai

DKIM Explained: How Email Signing Works

FortWatch

FortWatch Team

• 20 min read

DKIM Explained: How Email Signing Works

DKIM lets a domain claim some responsibility for a message by signing it. The sending server adds a signature to the message; the receiving server fetches the matching public key from the signer's own DNS and checks it. A valid signature names the domain that signed and shows that the signed parts still match what was signed, allowing for the small normalization DKIM applies to things like whitespace. You can check a domain's DKIM keys now with our free checker and read along with your own keys in front of you.

This guide covers what a signature covers and what it leaves out, selectors and the key record, how a receiver verifies, key types, sizes and rotation, why signatures break, what a pass does and does not prove, and how DKIM counts for DMARC. Every statement about how DKIM works links to its section of RFC 6376, the standard that defines it, or to the later standards that changed it.

The short version: turn DKIM signing on in every service that sends mail as your domain, and publish the key record each one gives you under its own selector. Sign with your own domain, so the signature counts for DMARC. Use RSA keys of 2048 bits and SHA-256, rotate keys by moving to a new selector, and remember that a valid signature says who signed and that the signed parts still match, not that the message is safe.

What a DKIM signature covers

The signature travels in the message itself, in a DKIM-Signature header. A typical one looks like this, shortened:

DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=example.com; s=mail2026;
  h=from:to:subject:date:message-id; bh=2jUSOH9N...; b=dzdVyOfAKC...

Its tags tell the receiver everything it needs:

TagWhat it holds
v=The version, always 1
a=The signing algorithm, such as rsa-sha256
d=The signing domain, the one taking responsibility
s=The selector, which says which of the domain's keys to fetch
h=The header fields that were signed, in order
bh=A hash of the message body
b=The signature itself
c=How the message was normalized before hashing; simple/simple when absent
i=Optionally, the user or agent the domain signed for; its domain is d= or a subdomain of it, unless the key's t=s flag rules subdomains out
l=Optionally, how much of the body was signed
t=, x=Optionally, when the signature was made and when it expires

Seven of these are required: v, a, b, bh, d, h and s.

What is signed

  • The header fields listed in h=. The From header must always be among them, and the standard highly advises signing Date, Subject, Reply-To, Sender and the MIME headers too. A signer can list a header that is not there, so that adding it later breaks the signature.
  • The body, through the hash in bh=: all of it, unless l= limits the signature to the first part.
  • The DKIM-Signature header itself, apart from the signature value in b=.

What is not

  • Other header fields left out of h=. Apart from the DKIM-Signature header, which is always signed, they can change or be added without breaking the signature, which is why the standard advises signing every header the reader sees.
  • Anything after the length in l=. Content added past that point is not validated.
  • Secrecy. DKIM makes no attempt to encrypt anything. Use separate encryption if the content needs to stay private.
  • The rest of the journey. A valid signature asserts that the hashed content has not changed since it was signed and, in the standard's words, "asserts nothing else".

Selectors and the key record

A domain can have many DKIM keys at once, and the selector is how it tells them apart. The standard created selectors to support several concurrent keys per domain: one per mail service, per office or per period. Each key lives in DNS at a name built from the selector and the signing domain. A signature with s=mail2026 and d=example.com sends the receiver to mail2026._domainkey.example.com.

The key is a TXT record with tags of its own:

mail2026._domainkey.example.com.  TXT  "v=DKIM1; k=rsa; p=MIIBIjANBgkqhkiG9w0BAQEFAAOC..."
TagWhat it does
v=DKIM1The version; optional, but if present it must come first
k=The key type: rsa, the default, or ed25519
p=The public key in base64; empty means the key is revoked
h=The hash algorithms this key may be used with; all when absent
s=The services the key is for: email, or * for any, the default
t=Flags: y for testing, s so that i= may not name a subdomain

Two rules about the record matter in practice. A key longer than one DNS string is split into several strings in one record, and receivers join them with nothing in between. And a selector should hold one record only: with several, the results are undefined.

The testing flag deserves a warning. With t=y, receivers must not treat your signed mail differently from unsigned mail, even when the signature fails, though they may track the results to help you test. Remove the flag once signing works.

Finding a domain's selectors

A receiver never has to guess the selector: it reads it from the signature's s= tag, and looks up the key by that name. Anyone else needs the name too: DKIM defines where to look up a selector, not a query that lists them all, so a checker can only try names. The standard also warns that selector names can give information away, such as one per user named after the user. Each provider names its own: Google's default selector is google, and Microsoft 365 uses selector1 and selector2, published as CNAME records that point to names Microsoft maintains. To find yours, open a message you sent and read the s= value in its DKIM-Signature header, as Google's guide also suggests.

How a receiver verifies a signature

For each signature it chooses to verify, the receiver works through three checks, stopping at the first that fails; it may work on them in parallel, as long as the result is the same as checking in order:

  1. Check the signature header. A missing required tag, an i= outside the d= domain, or an h= without From makes the receiver ignore the signature as a permanent failure. An expired x= may do the same.

  2. Fetch the key at s=._domainkey.d=. If DNS does not answer, the receiver may try again later. If the key record does not exist, is malformed, excludes the hash the signature used, or is revoked, the signature fails permanently.

  3. Compute and compare. The receiver normalizes the message the way c= says, hashes the body and compares it with bh=, then checks the signature in b= against the signed headers with the public key. Both must match.

A message can carry several signatures, from the sender and from services that handled it. Receivers evaluate each one on its own merits and should keep checking until one verifies.

A failed signature is not a verdict on the message. Signatures can fail through no fault of the signer, so a receiver should treat a message with only bad signatures like one with no signature at all, and the standard advises against rejecting mail on a missing or unverifiable signature alone. A receiver that wants to pass the result on may add an Authentication-Results header, where a pass may appear as dkim=pass header.d=example.com; the exact fields vary by receiver.

Canonicalization: simple or relaxed

Mail servers make small changes to messages in transit, such as rewrapping long header lines. Before hashing, both sides normalize the message, and c= says how. "simple" tolerates almost no change; "relaxed" tolerates common changes such as whitespace replacement and header rewrapping. The header and body can use different methods, written as c=relaxed/relaxed, and a signature without c= uses simple/simple. Normalizing never changes the message itself; it only prepares what gets hashed.

Algorithms and key sizes

RFC 6376 defined two algorithms, rsa-sha1 and rsa-sha256. RFC 8301 retired the first: signers must sign with rsa-sha256, and rsa-sha1 must not be used for signing or verifying. A key record whose h= leaves out sha256 can therefore verify nothing.

The same standard set the RSA key sizes:

The catch with 2048 bits is DNS. A single TXT string holds 255 characters, so a 2048-bit key has to be split into several strings in one record, and RFC 8301 notes that some DNS configuration software handles only a single string. That is why Google's setup offers 1024 bits for a domain host that cannot take a 2048-bit key, and recommends 2048 where it can.

Ed25519

RFC 8463 added a second key type, Ed25519, with much shorter keys than RSA for a similar level of security. Its public key is 44 characters in base64 and will generally fit in one TXT string. The standard says signers should implement it and verifiers must. To stay readable by receivers that only know RSA, a signer can sign each message twice, with an RSA key and an Ed25519 key under two selectors. Your mail service decides whether that is an option.

Rotating and retiring keys

Private keys can leak, and a leaked one lets anyone send mail signed by your domain. The standard treats rotation as normal, noting that keys can be replaced on a regular basis. Selectors are what make it painless. To move from one key to the next, as the standard describes it:

  1. Publish the new public key under a new selector, while the old one stays in place.
  2. Switch the sending server to sign with the new private key.
  3. Keep the old public key published until mail signed with it has had time to arrive and be verified, then remove it.

Two rules come with it. When you manage the keys yourself, use a new selector for each new key: the standard advises against reusing one, because an old signature that fails then cannot be told apart from a forgery. A provider that rotates keys for you, as Microsoft 365 does with its two selectors, follows its own scheme. And keep the old public key published for a reasonable time after you stop signing with it: receivers may verify late, and verification fails when their lookup finds no key. If a private key leaks, revoke it at once, accepting that genuine mail still in transit may fail.

Your provider may do the rotation for you. In Microsoft 365, one of the two selectors is active and the other is used after the next key rotation, and a rotation you start takes four days before the new key signs mail.

To retire a key for good, such as a service you no longer use, you can delete the record or publish it with an empty p=. The standard defines no difference in meaning between a revoked key and a removed one: verification fails when a receiver's lookup finds no key or a revoked one. Leaving the old key published means anyone who still holds the matching private key can still sign mail as your domain.

Why signatures break

A signature breaks when a change to what it covers survives DKIM's normalization. The standard is plain about it: survival after transit is not guaranteed. The usual causes:

Plain forwarding is kinder. When a forward preserves the content and makes no significant header changes, DKIM signatures may remain valid, which is why DKIM can keep forwarded mail authenticated when SPF no longer passes.

Why not use l=?

The l= tag signs only the first part of the body, so a list footer added after it does not break the signature. The standard warns that it lets an intermediary append content that can replace the original in the reader's eyes, and says signers should be extremely wary of it. RFC 7960 adds that it is seldom used because of those security issues, and that lists often do more than append. Sign the whole body.

For mail that passes through lists and forwarders, ARC, an experimental protocol, lets services that support it attach signed records of the authentication results they saw, for later receivers. Any mail handler can add them; turning on DKIM signing does not turn ARC on.

What a DKIM pass proves, and what it does not

A pass proves two things: the domain in d= claims some responsibility for the message, and the signed parts still match what it signed. That gives receivers a signing domain they can base trust and reputation decisions on. It does not prove:

And a fail does not prove forgery: a list footer can break a genuine signature just as surely as tampering can.

How DKIM counts for DMARC

A message can carry a valid signature from any domain, even one a bad actor runs, so DMARC counts a DKIM pass only when the signing domain is aligned with the From domain. In relaxed mode, the usual choice, the two need only share an organizational domain: a signature with d=mail.example.com aligns with example.com in the From line. One aligned, valid signature among several is enough.

The practical consequence: a service that signs your mail with its own domain gives you a DKIM pass that does nothing for your DMARC. Microsoft puts it directly: a message needs to be DKIM signed by the domain in the From address, and its guide says that no DKIM signing occurs for outbound mail from custom domains before walking through the setup. Google asks senders using an email service provider to verify that the provider authenticates your domain's email with SPF and DKIM. For every service that sends as you, set it to sign with your domain.

Gmail, for mail to personal Gmail accounts, and Yahoo both require at least one of SPF or DKIM from every sender, and both, with a DMARC record, from bulk senders; our SPF guide covers their requirements and the record that sits beside DKIM, and the DMARC guide covers the policy and its reports.

Setting up DKIM, step by step

  1. List every service that sends mail with your domain in the From line. Your mailbox provider, the newsletter tool, the CRM, the help desk, invoicing and any server that sends alerts. For each one, find which service actually signs the mail: an app that sends through your mailbox provider may rely on that provider to sign.

  2. Turn DKIM on for your domain in each signing service. Follow its instructions to get the selector and the DNS record; if you run the signing server yourself, generate the key pair there and keep the private key safe. In Google Workspace you generate the record in the Admin console, choose 2048 bits if your domain host supports it, and use the default selector google unless that name already holds a DKIM key. Microsoft 365 gives you two CNAME records, for selector1 and selector2.

  3. Publish exactly what you were given at selector._domainkey.yourdomain, as a TXT or CNAME record. One record per selector. If your DNS host splits a long key into several strings, keep them in one record.

  4. Switch signing on in the service once the record is live. Google notes that it can take up to 48 hours for DKIM to start working after you add the key.

  5. Test it. Send a message to a mailbox outside your organization; Google notes you cannot verify DKIM by sending yourself a test message. Open the received headers and look for dkim=pass in Authentication-Results. Formats vary by receiver, so also find the DKIM-Signature that passed and check its d= domain. Then run the DKIM checker with your selector to read the key's type and size.

  6. Plan the rotation. Know how your provider rotates and keeps the previous key during the change; if you manage the keys yourself, publish each new key under a new selector.

  7. Retire keys you no longer use. When you drop a service, stop sending through it, give its last messages time to be verified, then delete its DKIM record or revoke it with an empty p=.

  8. Add DMARC and ask for reports. The DMARC guide covers the policy for mail that passes neither SPF nor DKIM with alignment, and how reports help find senders that do not sign with your domain. Reports do not cover every receiver or message.

How to check your DKIM

From a terminal, dig +short TXT google._domainkey.example.com on Linux or macOS, or nslookup -type=TXT google._domainkey.example.com on Windows, shows the key at one selector. Take the selector from s= and the signing domain from d= of the same DKIM-Signature: the key is at selector._domainkey.signing-domain. Our guide to reading DNS records covers the output.

The free FortWatch DKIM checker looks up the selector you type and 18 common ones at once, from your browser through Cloudflare's public DNS, so the domain and selector you check never reach our servers. The common ones include google, selector1 and selector2, k1 to k3, s1 and s2, and default. It recognizes records that start with v=DKIM1 or carry a p= tag; at each selector with one, it reads the first and:

  • reads the key type and size, RSA or Ed25519;
  • fails an RSA key under 1024 bits, and warns on one under 2048;
  • flags a revoked key (an empty p=), a missing p=, a key that is not valid base64 or not a well-formed key, an h= that leaves out sha256, an s= that excludes email, and a key in testing mode;
  • flags a malformed record: v= that is not first or not DKIM1, a tag that appears twice, or more than one DKIM record at a selector.

It checks the keys you publish, not a signature on a real message: a test message's Authentication-Results header is where you see that. When it finds no key, it explains that another selector may still hold one and names any lookups that failed; if every lookup fails, it says DKIM could not be checked.

FortWatch's email monitoring looks for a record at eight common selector names on each email scan and records what it finds. It raises no DKIM issue, because a key under another selector could still exist. For a key's type, size and faults, use the free DKIM checker.

Common questions

Do I need DKIM if I already have SPF?

Yes. SPF checks the server that sent the message and can stop passing for your domain after a forward; DKIM checks the signed content and can survive a forward that leaves it unchanged. Gmail requires SPF and DKIM from senders of more than 5,000 messages a day to personal Gmail accounts, and Yahoo requires both from bulk senders.

How do I find my DKIM selector?

Open the headers of a message you sent and find the DKIM-Signature header: s= is the selector and d= the signing domain. The key lives at s._domainkey.d. Your provider's DKIM setup page names it too.

Can a domain have more than one DKIM key?

Yes, as many as it needs, each under its own selector. Each selector should hold one record only.

What key size should I use?

RSA at 2048 bits: signers should use at least 2048, and receivers must not accept a key under 1024. Always with SHA-256. If your service offers Ed25519, it can sign with it beside the RSA key, under a second selector.

Why does DKIM fail on mail sent through a mailing list?

Because lists change messages: a subject tag, a footer, removed attachments. These changes invalidate the signature when they touch content it covers beyond what normalization tolerates. A list can add its own signature to the changed copy, which then names the list's domain.

What does t=y mean in a DKIM record?

The domain is testing DKIM. Receivers must treat its mail like unsigned mail, whatever the signature result. Remove the flag once signing works.

Does a DKIM pass mean the email is safe?

No. It means the signing domain took responsibility and the signed parts still match. The signing domain need not match the From address, and a signed message can be replayed to new recipients. DMARC alignment is what ties the signature to the address people see.

What do I do with this?

  1. Check each service that sends as you. Find its selector in a sent message and run it through the DKIM checker: a key that exists, RSA at 2048 bits or Ed25519, not revoked, not in testing mode.

  2. Make each one sign with your domain. The passing signature's d= should align with the From domain: the same organizational domain in relaxed mode, the exact domain in strict mode.

  3. Replace weak keys. Move any 1024-bit RSA key to 2048, through your provider's rotation or under a new selector, and drop SHA-1.

  4. Write down your rotation. Which selector is live, which comes next, and when the old key comes out.

  5. Clean up old keys. Once their last messages have had time to arrive and be verified, delete or revoke the records of services you no longer use.

  6. Tie it together with DMARC. The DMARC guide walks through the policy and the reports, and the DNS security checklist covers the rest of your DNS. FortWatch rechecks SPF and DMARC on every name with email checks on, on your scan schedule.

Share this post

Ready to secure your stack?

Secure your entire stack today

Start scanning in under 5 minutes. No credit card required. 7-day free trial included.