What is the difference between CNAME and A records, and when should they be used? This tutorial is designed to clear up some of the confusion around the differences between CNAME and A (address) records.
Websites are served from locations that are uniquely identified by a group of numbers, which are known as IP addresses; but to access these sites we usually type in their corresponding domain names, which are easier to remember. To find the correct IP address, your browser will contact a Domain Name Server (DNS) and query its database for the IP address.
CNAME and A records
What is an A Record?
An A record is a record in these Domain Name Servers that links or maps a domain directly to its corresponding IP address.
For example, when you type mydomain.com into your browser, your browser will perform a DNS lookup which will return the corresponding IP address eg. 111.222.333.444.
Whas is a CNAME Record?
A CNAME, or Canonical Name record, is a record that points to another domain address rather than an IP address.
For example, say you have several subdomains, like www.mydomain.com, ftp.mydomain.com, mail.mydomain.com etc and you want these sub domains to point to your main domain name mydomain.com. Instead of creating A records for each sub-domain and binding it to the IP address of your domain you can create CNAME records.
As you can see in the table below, in the case where the IP address of your server changes, you only need to update one A record and all the subdomains follow automatically because all the CNAMES point to the main domain with the A record:
(sub)Domain / Hostname | Record Type | Target / Destination |
mydomain.com | A | 111.222.333.444 |
www.mydomain.com | CNAME | mydomain.com |
ftp.mydomain.com | CNAME | mydomain.com |
mail.mydomain.com | CNAME | mydomain.com |
Examples of using CNAME records
Domains registered in different countries
CNAME records can also be handy in the case that you registered your domain name in several countries and you want to redirect them all to your main domain. For example mydomain.com.au and/or mydomain.co.nz can be redirected to mydomain.com
Products and brand names
In case you have registered several domain names, for example for your different products or brand names and you want to redirect them all to your main domain, you create CNAME records for all these other domains. For example: myproduct.com > mydomain.com.
Limitations of CNAME records
- Usage of CNAME records means that there is an additional request sent to the DNS servers, which can cause a delay of a few milliseconds.
- You cannot create a CNAME record for the main domain name (mydomain.com) itself, this must be an A record.
For example, you cannot map mydomain.com to google.com, however, you can map google.mydomain.com to google.com. - MX or NS (nameserver) records may never point to a CNAME record, only A records.
What are CNAME and A records
CNAME and A records are both types of DNS records used to map a domain name to an IP address.
A (Address) Record:
An A record is a DNS record that maps a domain name to an IP address. For example, if you type www.example.com into your web browser, the DNS resolver will look up the A record for example.com to determine the IP address associated with it, and then use that IP address to establish a connection with the server hosting the website.
CNAME (Canonical Name) Record:
A CNAME record is a DNS record that maps one domain name to another. For example, if you have a website hosted at www.example.com, but you also want visitors to be able to access it at blog.example.com, you can create a CNAME record that points blog.example.com to www.example.com. This way, if someone types blog.example.com into their browser, the DNS resolver will look up the CNAME record for blog.example.com, see that it points to www.example.com, and then look up the A record for www.example.com to determine the IP address associated with it.