Skip to content

MX Record: syntax, examples, and troubleshooting

An MX record names a mail exchanger for a domain and gives it a 16-bit preference value. Sending servers collect the whole MX set, sort it by preference ascending, and try the lowest number first. Without MX records, mail delivery falls back to the domain's address records.

Example MX record

google.com.		292	IN	MX	10 smtp.google.com.
github.com.		57	IN	MX	0 github-com.mail.protection.outlook.com.
example.com.		162	IN	MX	0 .
A real MX record as a resolver returns it
Look one up
MX Lookup

What does an MX record do?

MX is record type 15, defined in RFC 1035 and refined by RFC 5321 and RFC 7505. It exists because the host that receives your mail is usually not the host that serves your website. When an MTA has a message for [email protected], it queries example.com for MX, gets back a list of hostnames with preference numbers, resolves those hostnames to addresses, and opens an SMTP connection.

If no MX records exist, RFC 5321 says the sender falls back to the domain's A or AAAA records — the "implicit MX" rule. That fallback is why a domain with a web server and no MX records will have connection attempts on port 25 hitting the web server, and why mail sometimes appears to "half work" after a bad DNS change.

MX Lookup
Mail servers and priorities for a domain

MX syntax and fields

FieldExampleMeaning
Name (owner)google.com.The mail domain — the part after the @ in an address. Usually the apex; subdomains need their own MX if they receive mail.
TTL292Cache lifetime of the MX set.
ClassINInternet class.
TypeMXRecord type 15.
Preference1016-bit unsigned integer, 0–65535. Lower is tried first. Often mislabelled "priority" in provider UIs.
Exchangesmtp.google.com.Hostname of the mail server. Must resolve to A/AAAA records. Must not be an IP address or a CNAME.

How preference actually works

The sending MTA sorts all MX records by preference ascending and attempts them in that order, moving to the next only when the current one fails to accept the message — connection refused, timeout, or a 4xx temporary rejection. A 5xx permanent rejection ends the delivery attempt; it does not cause a fallthrough to the next MX.

  • Lower number = higher priority. 10 is tried before 20. This inversion catches people constantly.
  • Equal preference means load sharing. Records with the same value are tried in random order, spreading load across a pool. Five servers all at preference 10 is a normal, healthy configuration.
  • The absolute values are meaningless. 1, 5, 10 behaves identically to 10, 20, 30. Only relative ordering matters. Conventional spacing by tens just leaves room to insert a server later.
  • A backup MX must be able to deliver onward. A "backup" that accepts mail and cannot relay it to the primary is a mail black hole, and one that accepts for unknown recipients turns into a backscatter source. Modern practice at most shops is to skip backup MX entirely — sending MTAs already queue and retry for days.

For a fuller treatment including multi-provider setups, see MX priority explained.

Null MX: saying "this domain sends no mail"

RFC 7505 defines a null MX: a single MX record with preference 0 and an exchange of . (the root). It is an explicit statement that the domain accepts no mail. A sender that sees it can reject immediately with a permanent error instead of queueing and retrying for days.

; Zone file
example.com.    IN  MX  0 .

; What dig shows
example.com.    162  IN  MX  0 .
A real null MX — example.com publishes exactly this.

Publish a null MX on parked domains, on domains used only for outbound transactional sending, and on subdomains that should never receive mail. Two rules: it must be the only MX record in the set, and it should be paired with an SPF record of v=spf1 -all and a DMARC record at _dmarc with p=reject so the domain is fully locked down for both directions. The DMARC generator and SPF generator will build those.

A null MX alongside real MX records is a broken configuration. Some senders will honour the null MX and reject your mail outright. It is all or nothing.

MX targets must be hostnames

The exchange field is a domain name, and RFC 2181 is explicit that it must not be an alias. Two hard rules follow:

  • Never an IP address. MX 10 203.0.113.25 is invalid. Some provider UIs accept it and produce a record that resolves to 203.0.113.25.example.com, which is NXDOMAIN. Create a hostname like mail.example.com with an A record and point the MX at that.
  • Never a CNAME. If mail.example.com is a CNAME, some senders will chase it and others will treat the MX as broken. The result is mail that arrives from some sources and not others — one of the worst failure modes to diagnose.
  • The target needs address records. An MX pointing at a hostname with no A or AAAA record is a lookup that succeeds and a delivery that cannot happen.
  • Use a name in a zone you control or your provider's own name. Pointing MX at a third party's hostname you have no relationship with does not make them accept your mail.

TTL guidance

MX records are among the safest to give a long TTL — 3600 to 14400 is common, and a long TTL means that if your DNS provider has a partial outage, senders keep using cached MX data rather than queueing. Drop to 300 for 24–48 hours before a mail platform migration, complete the cutover, verify inbound delivery from an external address, then raise it back. Because senders queue and retry for days, an MX misconfiguration is usually recoverable — but only if you notice it before the retry windows expire.

Mistakes engineers make with MX

  • Inverting the priority. Putting the primary at 20 and the backup at 10 sends all mail to the backup. It often still "works", which is why it survives for months.
  • Leaving the old provider's MX in place during a migration. Two providers at different preferences means mail splits across both mailstores. Delete the old records in the same change, not later.
  • Adding MX records to `www`. Mail is addressed to [email protected], so the MX belongs at the apex. An MX at www.example.com only matters for mail to [email protected].
  • Trailing-dot errors. In a raw zone file, smtp.google.com without the dot becomes smtp.google.com.example.com..
  • Assuming MX changes fix authentication. MX governs inbound mail. Outbound reputation is SPF, DKIM, DMARC, and PTR. Changing MX does nothing for a 550 5.7.x rejection — see mail bouncing after a DNS change.
  • Forgetting subdomains. example.com having MX records does not give sub.example.com mail service. Each mail-receiving name needs its own MX (or a null MX to say it receives none).

Check it with dig

# Preference and exchange for a domain
dig +short google.com MX

# Full answer with TTL
dig +noall +answer github.com MX

# Confirm the exchange actually has address records
dig +short smtp.google.com A
dig +short smtp.google.com AAAA

# Make sure the exchange is NOT a CNAME (should be empty)
dig +short smtp.google.com CNAME

# Ask the authoritative servers directly
dig +noall +answer @ns1.google.com google.com MX

# A null MX looks like this
dig +short example.com MX
Every MX audit is these five queries: the MX set, the target's A, the target's AAAA, the target's CNAME (must be empty), and the authoritative copy.

Once MX is correct, confirm the server is actually reachable with the SMTP connection test, check reverse DNS on the sending IP with the reverse DNS lookup, and run the full deliverability test for SPF, DKIM, and DMARC together.

Frequently asked questions

Does a lower MX priority number mean higher or lower priority?
Lower number means tried first. An MX at preference 10 is attempted before one at 20. The field is a "preference" in the RFC, which is why the ordering feels inverted compared to the word "priority" that most control panels use.
Can I have several MX records with the same priority?
Yes, and it is a normal configuration. Sending servers pick randomly among records with equal preference, which distributes inbound load across a pool. Many hosted mail providers publish several equal-preference exchanges for exactly this reason.
What is a null MX record?
A single MX record with preference 0 and the target . (the root). Defined in RFC 7505, it tells senders the domain accepts no mail so they can reject immediately instead of retrying for days. Publish it on parked domains and send-only domains, and pair it with v=spf1 -all and a DMARC reject policy.
Can an MX record point to an IP address?
No. The exchange field is a hostname. Some provider forms accept an IP and quietly create a record that resolves to 1.2.3.4.example.com, which does not exist. Create a hostname such as mail.example.com with an A record, then point the MX at that.
What happens if I have no MX records at all?
Senders fall back to the domain's A or AAAA records under the implicit MX rule in RFC 5321, and try to deliver to whatever is listening on port 25 there — typically your web server. If the domain should not receive mail, publish a null MX rather than relying on nothing being there.
Do I still need a backup MX server?
Usually not. Sending MTAs queue and retry for days, so a primary that is down for a few hours loses nothing. A backup MX that cannot relay onward, or that accepts mail for unknown recipients, actively hurts you — it becomes a spam target and a backscatter source. Most modern setups use a pool of equal-preference exchanges instead.