DKIM key rotation: when and how to rotate your selectors
DKIM lets receivers check that a message really comes from your domain and was not changed on the way. Your mail server signs each message with a private key, and receivers fetch the matching public key from DNS. Anyone who holds that private key can sign mail that passes DKIM as your domain, so the key deserves the same care as a password: it should be strong, kept private and replaced on a schedule.
Replacing it is called key rotation. Done carelessly, it breaks signatures on mail that is still in transit or waiting to be read. Done with selectors, it is invisible to your recipients.
The short answer: use RSA keys of at least 2048 bits, rotate at least every 6 months, publish the new key before you start signing with it, and keep the old public key in DNS for a few weeks before you retire it. If DKIM itself is new to you, start with SPF, DKIM and DMARC explained.
Why rotate DKIM keys at all
DKIM is defined in RFC 6376. Its section on a misappropriated private key is blunt: a compromised private key means an intruder or malware can send mail signed by your domain. Nothing in DKIM tells you that a key has leaked. A copied key keeps working until you stop publishing the public half.
Keys also age. RFC 8301 requires signers to use RSA keys of at least 1024 bits and says they should use keys of at least 2048 bits. Many domains still sign with 1024 bit keys created years ago, often by a provider or an agency nobody works with anymore.
The industry group M3AAWG recommends in its DKIM Key Rotation Best Common Practices (revised March 2019) that keys be rotated at least every 6 months. It gives a practical reason too: a routine process means that when an emergency rotation is needed, the team already knows how to do it.
How selectors make rotation possible
Every DKIM public key lives under a name called a selector:
<selector>._domainkey.example.com
The selector travels inside each signature as the s= tag, so a receiver knows which key to fetch. RFC 6376 section 3.1 explains that selectors exist precisely so a domain can publish several keys at once and replace them on a routine basis: both keys are published during a transition period, the servers switch to signing with the new one, and the old one is removed at the end.
That is why a good selector name says something about the key. A date or a sequence number works well, for example s202611 or dkim3. A selector called default that has not changed since the domain was set up is usually a sign that the key has never been rotated.
A safe rotation, step by step
- Generate a new key pair with an RSA key of 2048 bits.
- Publish the new public key under a new selector, and wait until DNS caches have picked it up. Check it with
dig. - Switch signing to the new private key on your mail server or in your provider's settings.
- Keep the old public key published. Mail signed with the old key may still be in transit or waiting to be read. RFC 6376 advises in section 5.2 that a signer should not sign with a key that is expected to be removed before the verifier has a chance to validate the signature. M3AAWG suggests keeping the old key unchanged for at least a week and up to 30 days.
- Retire the old key by publishing its record with an empty
p=value instead of deleting it. RFC 6376 defines an emptyp=as a revoked key, and M3AAWG recommends this form because it shows the key was retired on purpose.
Before and after the switch, the records might look like this:
s202605._domainkey.example.com. TXT "v=DKIM1; k=rsa; p="
s202611._domainkey.example.com. TXT "v=DKIM1; k=rsa; p=MIIBIjANBgkqh...IDAQAB"
A 2048 bit key does not fit into a single 255 character string (RFC 8301 mentions this practical limit), so the TXT value has to be split into several quoted strings inside 1 record. Most DNS providers handle this for you; if yours does not, the record will look valid in the panel and fail at the receiver.
Rotation with Microsoft 365, Google Workspace and other senders
Hosted mail services handle much of this for you, but someone still has to start it.
- Microsoft 365 publishes 2 selectors as CNAME records and rotates between them. Microsoft's DKIM configuration guide describes a Rotate DKIM keys action in the Defender portal and the
Rotate-DkimSigningConfigcmdlet, which can also move a domain from 1024 to 2048 bit keys. The new key starts signing after 4 days (96 hours). - Google Workspace creates the DKIM record in the Admin console. Rotating means generating a new record under a new selector, publishing it, and only then turning signing on with it.
- Newsletter, help desk and invoicing tools that sign as your domain each use their own selectors, often as CNAME records pointing at the vendor. The vendor rotates the key behind the CNAME. Your job is to remove the CNAME when you stop using the tool, so that an old selector does not keep pointing at a service you no longer control.
Your DMARC aggregate reports show which selectors are really in use, because each DKIM result lists the selector. Our guide on how to read a DMARC aggregate report explains where to find it.
How to check your current keys
Look at the DKIM-Signature header of a message you sent recently and note the d= domain and the s= selector. Then fetch the key:
dig +short TXT s202611._domainkey.example.com
Check 3 things:
- The record exists and has a non-empty
p=value. - The key is at least 2048 bits. Decode the
p=value withopensslor use a DKIM checker to see its length. - Selectors of tools you no longer use are either retired with
p=or removed.
If your SPF record is also crowded with old tools, the same cleanup applies there, as described in SPF too many DNS lookups.
A short checklist
- RSA keys of 2048 bits for every selector you sign with.
- Rotation at least every 6 months, with the date written down.
- New key published before signing starts, old key kept for a few weeks.
- Old keys retired with an empty
p=, not left active. - A list of every third party that signs as your domain and the selector it uses.
- An emergency rotation procedure the team has already run once.
Where Business Alerts fit
A forgotten DKIM key does not cause a visible error, which is why it tends to stay in DNS for years. We watch your SPF, DKIM and DMARC records along with the rest of what we guard from the outside, without entering your systems. When DKIM signing goes missing or your email authentication weakens, a person reviews it and you get the exact steps for your developer, as described in what happens when we find something. The example dashboard shows how it looks.
More articles
DNSSEC for a business domain: what it protects and what it does not
DNSSEC proves that the DNS answers for your domain really come from you. It does not encrypt anything and it does not stop a hijacked registrar account. Here is where it helps.
SPF "too many DNS lookups" (permerror): how to fix the 10 lookup limit
Every tool that sends mail for you adds an include to your SPF record. Past 10 DNS lookups the record breaks for everyone. Here is how to count them and how to fix it.
CAA records: deciding which certificate authorities may issue for your domain
A CAA record tells certificate authorities which of them may issue a TLS certificate for your domain. It takes a few minutes to set up and closes a door most companies leave open.