Differences Between A and CNAME Records
Last updated
The A record and the CNAME record are two of the most fundamental, commonly used ways to map a hostname (like www.example.com or blog.example.com) in the Domain Name System (DNS). While both ultimately lead a client to an IP address, they achieve this through distinct mechanisms with important implications for how you manage your domain.
Understanding these differences is necessary for correctly configuring your DNS and avoiding common pitfalls.
Understanding the core distinctions
The primary difference between an A record and a CNAME record lies in what they point to:
A record (address record):
- Direct IP mapping: An A record maps a hostname directly to one or more IPv4 addresses. This is the most straightforward way to tell a DNS resolver the exact numerical location of a server.
-
Example: If you want
blog.example.comto point directly to the server at192.0.2.10, you would configure:blog.example.com. A 192.0.2.10 - Use case: Ideal when you have a stable, known IP address for your server and want direct control over that mapping.
- Learn more: What Is an A Record?
CNAME record (canonical name record):
-
Maps to another name: A CNAME record maps one hostname (e.g.,
www.example.com) to another hostname (the “canonical name,” e.g.,example.comorservice.provider.com). It functions as a pointer, instructing DNS resolvers to look up the IP address of the target hostname. - Inherits resolution: When a DNS query encounters a CNAME record, it effectively follows the pointer. The DNS resolver then attempts to resolve the canonical name, inheriting its entire resolution chain until an IP address (usually via an A or AAAA record) is found.
- Exclusivity restriction: A CNAME record cannot coexist with any other record type (such as MX records for email, TXT records, or NS records) for the exact same hostname. If a name has a CNAME record, it can have no other records associated with it. This is a fundamental limitation of standard DNS.
-
Use case: A CNAME record is best when you want one hostname to mirror another, or when the IP address of your service is managed by a third party and might change, but their hostname (e.g.,
your-app.heroku.com) remains stable. - Learn more: What Is a CNAME Record?
Practical example: CNAME chaining for flexibility
Here is a typical setup for a blog hosted on a platform that uses a CDN, with placeholder names:
blog.example.com. CNAME example-blog.host.example.
example-blog.host.example. CNAME edge.cdn.example.
edge.cdn.example. A 192.0.2.10
When someone visits blog.example.com:
- The DNS resolver looks up
blog.example.comand finds a CNAME pointing toexample-blog.host.example. - It then queries
example-blog.host.example, and finds another CNAME pointing toedge.cdn.example. - Finally, it resolves
edge.cdn.exampleto its A record,192.0.2.10. The browser then connects to192.0.2.10.
The benefit of this CNAME chain is that if the hosting platform or CDN changes its IP addresses, only their records change. The blog.example.com CNAME follows the change without you updating your DNS records.
Note
While CNAME chaining is possible, each additional step adds another DNS lookup. Too many chained CNAMEs can slow down resolution, so it is best to keep chains short.
Which one should you use?
Choosing between an A record and a CNAME record depends directly on your specific needs and the capabilities of your hosting environment:
Choose an A record if:
- You know and control the stable IPv4 address of your server.
- You want to point your root domain (for example,
example.com) directly to an IP address. A CNAME cannot be used at the root, because the root always has SOA and NS records. - You want fine-grained control over the exact IP resolution.
Choose a CNAME record if:
- You want to alias one subdomain (e.g.,
www.example.com,app.example.com) to another hostname, especially if that hostname’s IP address might change (e.g., cloud services, CDNs). - You understand and accept the restriction that no other DNS records can exist for that specific hostname (e.g., if
www.example.comis a CNAME, you cannot have an MX record forwww.example.com).
Warning
Never use a CNAME record for your root domain name (for example, example.com). The root always needs SOA and NS records, and usually MX records, and none of them can exist alongside a CNAME. DNS hosting at DNSimple offers the ALIAS record for this case.
Have more questions?
If you have additional questions or need any assistance with your DNS records, just contact support, and we will be happy to help.