What is DKIM? Signatures, Selectors, Key Length and How to Check It
DKIM is one of the pillars of email authentication, alongside SPF and DMARC. Here is how the signature works and how to check for yourself that it is set up correctly.
Published: November 13, 2026 · 日本語
DKIM is a digital signature on your email
With DKIM (DomainKeys Identified Mail), the sending server adds a digital signature to each outgoing message and the receiver verifies it. That confirms the message really was sent under the control of that domain and was not modified on the way. It is defined in RFC 6376.
SPF looks at which server sent the message; DKIM signs the message itself. So even when a message is forwarded and the sending IP address changes, the signature stays valid as long as the body and key headers are unchanged. That is the main reason DKIM makes up for SPF's weakness with forwarding.
How signing and verification work
- The sending mail server computes a hash of the body and some headers (From, Subject, Date and so on) and signs it with a private key.
- The signature is added at the top of the message as a
DKIM-Signatureheader. - The receiving server reads the domain and selector in that header and fetches the public key published in DNS.
- It verifies the signature with the public key: "pass" if the message is untouched, "fail" if the signature does not match.
Only the sender holds the private key; only the public key goes in DNS. The private key cannot be derived from the public key, so it does no harm that anyone can see the public key.
Reading the DKIM-Signature header
If you view the source of a received message, you will find a header like this (shortened):
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=example.com; s=selector1;
h=from:to:subject:date:message-id;
bh=(hash of the body); b=(signature)
d=: the signing domain. For DMARC, what matters is whether this matches the From domain (alignment).s=: the selector, a name used to find the public key.h=: the list of headers covered by the signature.bh=: the hash of the body;b=: the signature itself.a=: the algorithm. rsa-sha256 is the usual one today.
Selectors and the public key in DNS
The public key goes in a TXT record at the DNS name selector._domainkey.domain. For selector selector1 and domain example.com, the name to look up is:
selector1._domainkey.example.com. TXT "v=DKIM1; k=rsa; p=MIIBIjANBgkq..."
The public key is in p=. Selectors exist so that one domain can use several keys at the same time. If you use more than one mailing service, or are switching keys, separate selectors keep them from interfering with each other.
s= value in the header of a message actually sent from your domain.Key length and algorithm
2048-bit RSA keys are the current recommendation. 1024-bit keys still work in many places, but moving to 2048 bits is advised for strength. A 2048-bit public key makes the TXT record longer than 255 characters, so depending on your DNS control panel you may need to enter it as several strings (DNS joins them back into a single value).
When entering a long key, some panels handle quotes and line breaks for you and some do not. After saving, always check that the value you get back from DNS is not cut off part way.
Rotating DKIM keys
A private key carries a lasting risk of leaking, so changing it regularly is recommended. The basic steps are:
- Create a new key pair under a new selector name.
- Add the new public key to DNS (do not delete the old one yet).
- Switch the sender's signing setting to the new selector.
- Wait while messages signed with the old key may still be in transit (a few days), then delete the old public key.
Delete the old key first and messages still in transit fail verification. Always go in the order add, switch, wait, delete.
Why DKIM alone is not enough
DKIM vouches for the signing domain, but not that it is the same as the From domain the recipient sees. An attacker can sign a message with their own domain while displaying your domain as the sender. Catching that mismatch, and saying what to do with messages that do not match, is DMARC's job. Think of DKIM and DMARC as a pair.
How to check your setup
- Send a real message: send from an address on your domain to another address such as Gmail, open the header on the receiving side ("Show original" in Gmail), and check for
dkim=passwithheader.d=set to your domain. - Query DNS directly: look up the selector, for example
dig TXT selector1._domainkey.example.com, and check forv=DKIM1andp=. - Use a tool: the DMARC Check tries commonly used selector names and shows the ones it finds.
Common pitfalls
- Many mailing services set up DKIM by having you add CNAME records they provide to your own DNS. Forget to add them and messages are signed with the service's domain, so they do not align with yours.
- If something along the sending path appends an ad or disclaimer to the end of the body, the body changes after signing and verification fails.
- Extra spaces or line breaks at the end of the public key record can make verification fail.
FAQ
Does setting up DKIM alone stop spoofing?
No. DKIM only shows which domain signed; it does not guarantee a match with the From domain the recipient sees. Use it together with DMARC, which checks that match and says what to do with messages that fail.
How often should I rotate DKIM keys?
There is no fixed rule, but many organizations rotate about once a year. Rotate right away if you suspect the key has leaked or when the person responsible leaves.
Can forwarding break a DKIM signature?
If the body and signed headers are not rewritten, the signature survives forwarding. But a mailing list that adds text to the subject or body can invalidate it.
Check your own domain
Enter your domain and the points in this article are checked for free. No sign-up.
Check DKIM and DMARC for free