CNAME vs A Record
The DNS records which live on your domain’s authoritative server are key to the proper functioning of your domain and website. They hold the information that dictates how your domain will handle various requests, which IP addresses are associated with it, and so on. There are many DNS record types, and they vary from being absolutely essential, to simply being quite useful.
Two of the most commonly used DNS records are A records and CNAME records. In a way, A records fall into the category of essential DNS records. A records basically create the link between a website’s IP address (the server where a site’s content is stored) and its domain name (how users access the website through their browsers). CNAME records, on the other hand, aren’t absolutely necessary in theory, but are necessary in practice – if you want your website to be widely accessible, that is. CNAME records create a connection between subdomains or domain aliases and the main IP address for that, whether it’s on your domain or another domain.
Let’s take a closer look at what each of these DNS records is and what their functions are, so as to better understand what the difference between a CNAME and an A record is.
What Is an A Record?
The Domain Name System was created in order to allow users to access websites through their browsers by entering the site’s domain names rather than their IP addresses. Imagine how difficult it would be to keep track of all the websites’ IP addresses. For instance, to visit example.com all you have to do is type that domain name into your browser’s search bar. If the DNS wasn’t instituted, you’d need to type out its IP address, or 220.127.116.11. So rather than having to keep a long list of all website’s IP addresses, we just get to type in their domain names.
The DNS A record serves exactly this basic purpose of the DNS. It contains information about which IP address is associated with a given domain. That’s why the “A” in “A record” stands for “address.” So in the example we gave above, the zone files, or DNS records, concerning the website example.com, have an A record which specifies that example.com lives on the 18.104.22.168 IP address. Without an A record, a website wouldn’t be reachable through its domain name.
So, when a user types out a certain domain into their browser’s address bar, the appropriate server returns the IP address for that domain which is found in its zone files, allowing the user to access the website.
Keep in mind that A records only work with IPv4 addresses, and not IPv6 addresses (you’d use an AAAA record for those).
What Is A CNAME Record?
A CNAME record is a DNS record that provides an association for alias domains and subdomains to the main, parent domain. The “C” stands for “canonical,” as this DNS record connects subdomains to the canonical name-domain or the records delivered for another DNS hostname.
Let’s look at how this looks. When you set up an A record for example.com you associate it with the 22.214.171.124 IP address. However, that doesn’t include domain aliases, such as www.example.com. That’s right, even adding a www before the domain name won’t lead you to the correct website unless a CNAME record exists to provide instructions that those two domains are to result in the same page.
Keep in mind, however, that a CNAME record creates a connection between a subdomain and a parent domain also, which means that it doesn’t always result in the same page popping up. For instance, when you have subdomains for a website, such as blog.example.com or mail.example.com, you still need to create CNAME records that link these subdomains to the parent domain.
Of course, this doesn’t mean that when users try to access a subdomain of that domain they end up on the home page, i.e. the same page as the parent domain. Rather, users are directed to the appropriate files for that subdomain, such as the blog page or the mail page rather than the home page.
CNAME records are quite useful when webmasters change the IP address of their website. Rather than having to change A records for each subdomain, they only have to change the A record for the parent website. Which brings us to…
What Is the Difference Between a DNS A Record and A DNS CNAME Record?
To better clarify the difference between DNS A records and CNAME records, let’s look at an example of how both would work for the same website.
DNS Record Type
As you can see, an A record only serves to associate the parent domain (hostname) with the appropriate IP address. CNAME records, on the other hand, link domain aliases (www) and subdomains (mail) to the parent domain which is specified in the A record. The shop subdomain points to Shopify’s servers, so they can manage which A record (IP address) the online store is hosted on. So while A records connect websites to IP addresses, CNAME records connect subdomains and aliases to the another domain record, not its IP address.
It, therefore, follows that you can’t create CNAME records for the parent (main) domain name, but only A records.
Keep in mind that you should also strive to target all your CNAME records to the parent domain rather than other aliases that are in turn associated with the main domain. This creates an unnecessary additional step in the DNS lookup process, which can cost visitors time and result in needless complications.
For instance, avoid this configuration:
DNS Record Type
Here, mail.example.com is linked to www.example.com, which is in turn linked to the parent domain, example.com. Instead of this, use the configuration we presented above, where all subdomains have CNAME records pertaining to the parent domain (example.com).
A Few Words Before You Go…
Hopefully, our guide has been useful in helping you understand the difference between a CNAME record and an A record in DNS. Both these DNS records types are quite useful, but only A records are absolutely necessary.
However, it’s quite likely that your website won’t function successfully without CNAME records, as well. Even if your website consists of a single page, you’ll at least need to create a CNAME record for www targeting the parent domain.
Additionally, A records connect the parent domain to its IP address, while CNAME records connect domain aliases and subdomains to the parent domain. It’s through the A record of the parent domain that users can access the site’s content. CNAME records can’t be used for creating direct associations with IP addresses.
View Related Articles
There is no experience more frustrating than having your emails end up in the spam folder of your recipients rather than their inboxes. If you’ve found that your emails are going to spam instead of your subscribers’ inboxes, keep reading to find out why.
In a world where technology shapes our society and everyday life, knowing how to operate a computer and other common tech gadgets becomes a survival skill.
Emailing today is such an easy task. Compose, hit send, and your message travels across oceans and borders to reach its recipient. It is such an easy task that people’s attention starts to drown in their full inboxes, which are also littered by spammers, phishers and other members of the not-so-nice population of netizens.