DEV Community

Cover image for Difference between CNAME and A records
Paschal Kenechukwu Oruche
Paschal Kenechukwu Oruche

Posted on

Difference between CNAME and A records

As a Cloud practitioner ☁️ , DevOps Engineer ♾ and the likes, you'll realize that whilst working on projects, you will experience the constant need for creating environments (test, deployment, sandbox, staging, production etc.), based on specific needs.

If you're like me, you're constantly working on projects that require the creation of environments with sub-domains or additional domains to serve your applications.

In this article, I'm going to break down the difference between these two types of DNS records, so you can choose the right one for your project. #FYI -> from my practical point of view.

" Let's dive right in 😊 😃 "

A CNAME (Canonical Name) record and an A (Address) record are both types of DNS (Domain Name System) records that are used to map a domain name to an IP address. However, they differ in their functionality and usage.

Let's start with A records. An A record is used to map a domain name to a specific IP address. For example, if you have a web server with an IP address of 192.0.2.1, you can create an A record that maps the domain name "example.com" to that IP address. This allows users to access your website by typing "example.com" into their web browser.

Here's an image to help you visualize an A record:

A Record preview

On the other hand, a CNAME record is used to map a domain name to another domain name. For example, if you have a web server with the domain name "www.example.com", you can create a CNAME record that maps "blog.example.com" to "www.example.com". This allows users to access your blog using the "blog.example.com" domain name instead of the "www.example.com" domain name.

The image below depicts how CNAME records work:

CNAME Record preview

PS: It is important to note that using a CNAME record can cause additional DNS lookups, which can increase the response time for the user. Therefore, it is recommended to use A records whenever possible, and to use CNAME records only when necessary.

Now, a quick Recap:

An A record is used to map a domain name directly to an IP address. For example, let's say you have a web server with the IP address 192.0.2.1

A CNAME record is used to map a domain name to another domain name, which in turn is mapped to an IP address through an A record.

That's all for now, folks! Happy 😊 mapping!

Top comments (0)