What is the difference between an A record and a CNAME record?
A records
An A record (Address record) is the most basic DNS record. It tells the internet that a specific hostname, like example.com or www.example.com, corresponds to a particular IPv4 address, such as 192.0.2.1. When someone visits that hostname, the resolver returns the IP address, and the browser connects to it.
You can have multiple A records for the same name to provide redundancy or load balancing. Each A record can have its own TTL. A records are required for the root domain (example.com) in most cases, unless you use an ALIAS or ANAME record, which some DNS providers offer.
CNAME records
A CNAME record (Canonical Name record) points one domain name to another domain name. For example, you might create a CNAME for blog.example.com that points to example.com. When a resolver looks up blog.example.com, it gets the CNAME and then looks up example.com to find the final A record.
CNAMEs are useful for aliasing subdomains to a main domain or to a service provider's domain (like yoursite.herokuapp.com). However, you cannot have a CNAME at the root of a domain (example.com) because it would conflict with other required records like NS and SOA. Also, a CNAME cannot coexist with other records for the same name.
- A record: name → IP address (e.g., example.com → 192.0.2.1).
- CNAME record: name → another name (e.g., www.example.com → example.com).
- A records can be used at the root; CNAMEs cannot.
- CNAMEs add an extra lookup step, slightly increasing resolution time.
- Use CNAMEs for subdomains that need to follow another domain's IP changes.
Common mistakes
- Trying to use a CNAME at the root domain; it's not allowed by DNS standards.
- Creating a CNAME alongside other records for the same name; that breaks DNS rules.
- Thinking CNAMEs are faster; they actually add a lookup step.
