DKIM (DomainKeys Identified Mail) adds a cryptographic signature to every email you send. The receiving server fetches a public key from your DNS and uses it to confirm two things: the message really was signed by your domain, and the signed parts have not been changed on the way. Of the three authentication standards, it is usually the one that does the heavy lifting for DMARC.
How DKIM signing works
Your sending service holds a private key. When a message goes out, it takes a hash of the body and selected headers (From, Subject, Date and so on), signs them with the private key and adds the result as a DKIM-Signature header. A simplified example:
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=example.co.uk; s=mail2026; h=from:to:subject:date:message-id; bh=2jUSOH9NhtVGCQWNr9BrIAPreKQjO6Sn7XIkfJVOzv8=; b=AuUoFEfDxTDkHlLXSZEpZj79LICEps6eda7W3deTVFOk4yAUoqOB...
The tags that matter most:
d=the signing domain. This is what DMARC compares with your From address.s=the selector, which tells the receiver where to find the public key.h=the list of headers that were signed.bh=the hash of the message body.b=the signature itself.c=the canonicalisation method: how strictly whitespace and header formatting are treated.relaxed/relaxedtolerates minor reformatting and is the sensible default.
The receiver reads d= and s=, looks up the public key, recalculates the hashes and checks the signature. If everything matches, DKIM passes.
Selectors and the DNS record
The public key is published as a TXT record at selector._domainkey.yourdomain. For selector mail2026 on example.co.uk:
mail2026._domainkey.example.co.uk. 3600 IN TXT "v=DKIM1; k=rsa; p=MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAx3k...IDAQAB"
Selectors exist so one domain can have many keys at once. Your mailbox provider uses one, your newsletter platform another, your helpdesk a third. None of them need to share a private key, and you can revoke one without touching the others.
You do not normally invent the key yourself. Your provider generates the key pair, keeps the private half and shows you the record to publish. There are two common formats:
- TXT record with the key in it, as above. Google Workspace works this way, with a default selector of
google. - CNAME pointing at the provider, so the provider hosts the key and can rotate it without you editing DNS. Microsoft 365 uses two CNAMEs (
selector1andselector2), and many email platforms do the same. Copy the exact values from the provider's admin screen.
selector1._domainkey.example.co.uk. CNAME (target shown in your provider's admin centre) selector2._domainkey.example.co.uk. CNAME (target shown in your provider's admin centre)
Publishing the DNS record is only half the job. You must also switch signing on in the provider's settings. Microsoft 365 and Google Workspace both require this extra step, and it is easy to miss. See Google Workspace and Microsoft 365 authentication guides for the exact clicks.
Domains, DNS & emaildijitul DNSRegister and transfer .uk and .com domains, with Cloudflare DNS management and business email. SPF, DKIM and DMARC set up properly.Fix your DNS with dijitulKey length: 1024 vs 2048 bits
RSA keys come in different lengths. Longer is harder to crack.
| Key length | Status |
|---|---|
| 512 or 768-bit | Insecure. Replace immediately; receivers may ignore the signature. |
| 1024-bit | The accepted minimum. Still works, but no longer recommended for new setups. |
| 2048-bit | Recommended. Supported by all major mailbox providers. |
The practical snag with 2048-bit keys is length. The key is longer than the 255-character limit for a single TXT string, so it has to be split into two or more quoted strings within one record. Most modern DNS panels, including Cloudflare, handle this automatically. Older control panels sometimes truncate the value or reject it. If your 2048-bit key fails with "key not found" or "invalid key", check the published record has not been cut short.
mail2026._domainkey.example.co.uk. TXT ( "v=DKIM1; k=rsa; p=MIIBIjANBgkqh...first part..."
"...second part...IDAQAB" )
Rotating keys
Keys should be changed periodically, and immediately if you think a private key has leaked or a former supplier still holds it. Selectors make rotation painless:
- Generate a new key pair under a new selector (for example
mail2027). - Publish the new public key in DNS and wait for it to propagate.
- Switch the sending system to sign with the new selector.
- Leave the old key published for a week or so, because messages signed with it may still be queued or re-checked.
- Revoke the old key by publishing an empty key:
v=DKIM1; p=
If your provider uses the CNAME method, it handles rotation for you; you just need to leave the CNAMEs in place.
Alignment: why the signing domain matters
A message can carry a perfectly valid DKIM signature and still fail DMARC. That happens when the d= domain does not match your From domain. Many email platforms sign with their own domain by default (something like d=platform-mail.net) until you complete their domain authentication steps. The signature passes, but it proves nothing about your domain.
Under DMARC's default relaxed alignment, d=mail.example.co.uk aligns with a From address of hello@example.co.uk, because they share the same organisational domain. Under strict alignment they must match exactly. Gmail, Yahoo and Microsoft's sender requirements all expect at least one of SPF or DKIM to align with the From domain, and DKIM is the more robust choice because it survives forwarding.
Common DKIM failures and fixes
Body hash did not verify
The most common failure. Something changed the message body after it was signed. Usual culprits:
- Footers and disclaimers added by a mail gateway or Exchange transport rule after the message left the signing server.
- Mailing lists that add an unsubscribe footer or a
[List]tag to the subject. - Security gateways that rewrite links for click scanning or inject warning banners on outbound mail.
- Character encoding changes by a relay that re-wraps lines or converts the message.
The fix is to make signing the last thing that happens before a message leaves your systems. If a gateway adds a footer, either have the gateway sign the message itself or move the footer into the original template. Avoid the l= body length tag as a workaround: it lets anyone append content to a signed message.
Key not found or no key for signature
The receiver could not find a record at selector._domainkey.yourdomain. Check for typos in the selector, a DNS panel that automatically appended your domain (giving mail2026._domainkey.example.co.uk.example.co.uk), or a record that has not propagated yet.
Signature verification failed
The key was found but did not match. Usually the published key is truncated, has stray spaces or quotes, or belongs to a different selector. Copy it again from the provider.
No signature at all
The DNS record is there but signing was never switched on, or the message went out through a system that does not sign, such as a website sending directly through PHP mail. Route it through an authenticated service that signs with your domain.
Checking DKIM works
Send a real message and inspect the result. A Mail Tester UK report shows every DKIM signature on the message, the d= and s= values, whether each one verified and whether the signing domain aligns with your From address. Test from each system that sends for you, since each has its own selector and its own chance to go wrong.
Frequently asked questions
What is a DKIM selector?
A selector is a label that tells the receiver which public key to fetch. It appears as s= in the signature and the key lives at selector._domainkey.yourdomain, so one domain can have several keys for different services.
Should I use a 1024-bit or 2048-bit DKIM key?
Use 2048-bit wherever your provider and DNS host support it. 1024-bit is still accepted by the major mailbox providers but is the minimum, and anything shorter should be replaced.
Why does DKIM fail with a body hash mismatch?
Something changed the message after it was signed, usually a footer, disclaimer, link rewriting or a mailing list. Find the system adding content after signing and either move the signing step after it or stop it modifying the message.
Do I need DKIM if I already have SPF?
Yes. Gmail and Yahoo require both for bulk senders, and DKIM survives forwarding where SPF does not, which makes it the more reliable way to pass DMARC.