Insights

Thinking a Higher MX Priority Number Wins? Lower Values Get Mail First

November 9, 2026
0:00
An MX record carries two things: a hostname and a number. Many people read that number as a score. They give the main mail server 20 and the backup 10, expecting the bigger number to win. It works the other way around: sending servers try the lowest value first. A second misconception tends to follow close behind, which is that giving two hosts the same number makes one of them a standby. Both mistakes look harmless in a DNS editor. In practice they decide which machine receives every message sent to your domain. Seeing how a sending server actually reads the records makes the right setup obvious.
When a mail transfer agent (MTA) such as Postfix or Exim, or a large provider's outbound system, has a message for [email protected], it goes through roughly these steps before opening any connection:
  1. It takes the domain part of the address and asks DNS for its MX records.
  2. It gets back a set of records. Each one has a preference value, an unsigned 16-bit number from 0 to 65535, and a target hostname.
  3. It sorts them in ascending order. The lowest number is the most preferred host.
  4. It groups records with the same preference. Within each group the order is shuffled. RFC 5321, the SMTP standard, recommends that senders randomize here.
  5. If the sending machine finds its own hostname in the list, it drops its own entry and every entry with an equal or higher number. This prevents mail loops. It is also why a backup MX relays mail onward to the primary instead of sending it back to itself.
  6. It resolves each remaining hostname to IPv4 (A) and IPv6 (AAAA) addresses, then works through those addresses in that order.
Only the relative order of the numbers matters. A pair of 10 and 20 behaves exactly like 1 and 2, or 0 and 500. The common habit of using gaps such as 10, 20, 30 is just a convention. It leaves room to slot a host in between later without renumbering everything. The order in which DNS returns the records means nothing. Authoritative servers and resolvers are free to return records in any order, and some rotate them on purpose. The sender sorts by the numbers, so you should too. Two edge cases are worth knowing:
  • If a domain has no MX records at all, senders typically fall back to the domain's own A or AAAA address, often called an implicit MX.
  • If a domain should never receive mail, a null MX record (preference 0, target a single dot) states that explicitly.
The target of an MX record is meant to be a hostname with its own address records. It should not be a raw IP address or a CNAME, although some MTAs tolerate a CNAME.
The sorted list is not a menu the sender shops through. It moves to the next address or host only on a temporary failure:
  • connection refused
  • a timeout
  • no route to the host
  • a 4xx temporary reply from the receiving server
A permanent 5xx rejection, such as a 550 for an unknown user or a policy block, ends the attempt. The sender generates a bounce. It does not try a higher-numbered MX in the hope that the backup is more lenient. A backup MX therefore cannot rescue mail that your primary server rejects. It only helps when the primary cannot be reached. If every host fails temporarily, the message stays in the sender's queue and is retried on that sender's schedule. How long it keeps trying depends on the MTA and its configuration, but retrying over hours or days before giving up is typical. For a short outage, the sender's own queue already acts as a buffer. That is one reason a secondary MX is often less necessary than people expect. With this in mind, a reversed priority stops looking like a cosmetic error. Say the backup host has 10 and the main server has 20. Every sender that can reach the backup will deliver there, every time. What happens next depends on what the backup actually is:
  • A store-and-forward relay. Mail takes an extra hop and may arrive late. If the relay does not know which mailboxes exist, it accepts mail for any address and later bounces the invalid ones. This produces backscatter: bounces sent to forged sender addresses.
  • A leftover mailbox server, such as the old host after a migration. Messages land in mailboxes nobody checks anymore.
Migrations are where this shows up most. The old server's record stays at a low number, the new server is added at a higher one, and mail quietly keeps going to the old machine. Spammers also know that backup MX hosts often have weaker filtering than the primary. Some deliberately target higher-numbered hosts first. A backup that accepts mail should get the same recipient checks and filtering as the primary. From the support desk, the first useful question in these cases is not what the DNS says but where the mail is actually landing. The Received headers of a delivered message show which host accepted it. That usually settles the question faster than reading zone files.
Give two hosts the same preference, say 10 and 10, and neither one is the primary. Each sender randomizes between them for each delivery. Across many senders the traffic ends up spread over both hosts. The split is not guaranteed to be even, because each sender's implementation decides how it shuffles. Equal-preference hosts do back each other up, in a limited way. If the host a sender picked first is unreachable, the sender tries the other one in the same group before moving on to any higher number. So an equal group gives you load sharing plus mutual failover. It does not give you one host that receives mail while the other waits idle. This setup is correct when the hosts are equivalent. Examples include several inbound gateways in front of the same mailbox storage, or nodes of a mail cluster that all know the same users. It is wrong when one host holds the real mailboxes and the other is a relay, an old server, or a different provider. In that case a share of your incoming mail goes somewhere you did not intend, and which messages go where looks random to the people affected. If you want a strict primary with a fallback, the primary needs a lower number than the fallback. There is no other way to express that order in MX records.
Start by asking for the MX set. It is worth comparing what your usual resolver returns with what the domain's authoritative nameserver returns. A resolver may still be serving older records from cache until their TTL runs out. In the example below, replace example.com with your domain and ns1.example-dns.net with one of the nameservers that the NS query returns.
BASH
# MX records as your current resolver sees them
dig +short MX example.com

# Find the authoritative nameservers, then ask one directly (placeholder name)
dig +short NS example.com
dig +norecurse MX example.com @ns1.example-dns.net
The short form prints one record per line, with the preference first and the target second:
TEXT
# Sample output format
20 backup.example.com.
10 mail.example.com.
In this output, mail.example.com is the preferred host even though it is printed second. Read the numbers, not the line order. If two lines share a number, expect senders to split mail between those hosts. Next, confirm that every target resolves to the address you expect. A preferred host that points at a decommissioned IP will make senders time out on it before moving on. That shows up as slow delivery rather than an obvious error.
BASH
# Each MX target should resolve to the intended server
dig +short A mail.example.com
dig +short AAAA mail.example.com
Pay attention to AAAA results. If a target has an IPv6 address that the mail server does not actually listen on, IPv6-capable senders may try it first. They typically fall back to IPv4, but often only after a delay. When you change records, check how your DNS panel expects the preference to be entered. Most editors have a separate priority field. Typing the number into the hostname field as well can produce a broken target, so re-run the dig commands after saving rather than trusting the editor's display.
Decide which server should receive mail under normal conditions and give it the lowest number. Give any true fallback a higher number, and only keep that fallback if it validates recipients and filters spam as well as the primary does. Use equal numbers only for hosts that are interchangeable and deliver into the same mailboxes. After any change, query the authoritative nameserver with dig, sort the results by preference yourself, and confirm each target's addresses. Then send a test message and read its Received headers to see which host actually accepted it.

Join My Newsletter & Get Updates!

Get notified whenever a new technical guide, server infrastructure breakdown, or personal reflection goes live, plus a curated weekly digest.