MX Records Explained: How Email Finds Its Destination
Alex Chen
December 28, 2025
A comprehensive technical guide to Mail Exchange (MX) records and how they route email traffic across the internet.
Introduction
When you send an email to someone@example.com, how does the internet know which server should receive that message? The answer lies in MX (Mail Exchange) records—a critical component of the Domain Name System (DNS) that directs email traffic to the correct mail servers.
Email Routing Flow
┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐
│ Sender's Mail │ │ DNS Server │ │ Recipient's Mail│
│ Server │ │ │ │ Server │
└────────┬────────┘ └────────┬────────┘ └────────┬────────┘
│ │ │
│ 1. Query MX record │ │
│ for example.com │ │
│──────────────────────>│ │
│ │ │
│ 2. Return MX: │ │
│ mail.example.com │ │
│<──────────────────────│ │
│ │ │
│ 3. Connect to mail.example.com │
│──────────────────────────────────────────────>│
│ │ │
│ 4. Deliver email via SMTP │
│──────────────────────────────────────────────>│
│ │ │What Are MX Records?
MX records are DNS resource records that specify the mail servers responsible for accepting email on behalf of a domain. Unlike A records that point to IP addresses for web servers, MX records point to hostnames of mail servers.
MX Record Structure
An MX record consists of two main components:
| Component | Description | Example |
|---|---|---|
| Priority | Lower number = higher priority | 10 |
| Mail Server | Hostname of the mail server | mail.example.com |
Example MX Configuration
example.com. IN MX 10 mail1.example.com.
example.com. IN MX 20 mail2.example.com.
example.com. IN MX 30 backup.example.com.How MX Lookup Works
When a mail server needs to deliver an email, it performs the following steps:
Step 1: DNS Query
The sending server queries DNS for the MX records of the recipient's domain:
$ dig MX example.com
;; ANSWER SECTION:
example.com. 3600 IN MX 10 mail1.example.com.
example.com. 3600 IN MX 20 mail2.example.com.Step 2: Priority Sorting
The server sorts MX records by priority (lowest number first) and attempts delivery to each server in order.
Step 3: A/AAAA Record Resolution
For each MX hostname, the server resolves the corresponding A (IPv4) or AAAA (IPv6) record to get the actual IP address.
Step 4: SMTP Connection
The sending server establishes an SMTP connection to the resolved IP address on port 25.
MX Priority and Failover
The priority system provides built-in redundancy:
Priority 10: mail1.example.com (Primary)
↓ If unavailable
Priority 20: mail2.example.com (Secondary)
↓ If unavailable
Priority 30: backup.example.com (Backup)Load Balancing with Equal Priorities
When multiple MX records have the same priority, mail servers should distribute connections randomly:
example.com. IN MX 10 mail1.example.com.
example.com. IN MX 10 mail2.example.com.
example.com. IN MX 10 mail3.example.com.Common MX Configurations
Single Server Setup
example.com. IN MX 10 mail.example.com.
mail.example.com. IN A 192.168.1.100Google Workspace
example.com. IN MX 1 ASPMX.L.GOOGLE.COM.
example.com. IN MX 5 ALT1.ASPMX.L.GOOGLE.COM.
example.com. IN MX 5 ALT2.ASPMX.L.GOOGLE.COM.
example.com. IN MX 10 ALT3.ASPMX.L.GOOGLE.COM.
example.com. IN MX 10 ALT4.ASPMX.L.GOOGLE.COM.Microsoft 365
example.com. IN MX 0 example-com.mail.protection.outlook.com.MX Record Best Practices
1. Always Have Backup MX Servers
A single point of failure can cause email loss. Configure at least two MX records with different priorities.
2. Use Reasonable TTL Values
3. Ensure A Records Exist
Every hostname in an MX record must have a corresponding A or AAAA record.
4. Don't Point MX to CNAME
RFC 2181 prohibits MX records from pointing to CNAME records. Always use A/AAAA records.
# WRONG
example.com. IN MX 10 mail.example.com.
mail.example.com. IN CNAME mailserver.provider.com.
# CORRECT
example.com. IN MX 10 mail.example.com.
mail.example.com. IN A 203.0.113.10Troubleshooting MX Records
Common Issues
| Problem | Cause | Solution |
|---|---|---|
| Email not delivered | Missing MX record | Add MX record |
| Intermittent delivery | DNS propagation | Wait for TTL expiry |
| Bounced emails | Invalid MX hostname | Verify A record exists |
| Connection refused | Firewall blocking | Open port 25 |
Diagnostic Commands
# Check MX records
dig MX example.com +short
# Verify mail server is reachable
telnet mail.example.com 25
# Full DNS trace
dig MX example.com +traceMX Records and Email Security
MX records work alongside other DNS records for email security:
Together, these records form a comprehensive email authentication framework.
Conclusion
MX records are the foundation of email routing on the internet. Understanding how they work is essential for:
Proper MX configuration ensures your emails reach their destination reliably and efficiently.