A Record vs CNAME: When to Use Which
If you've ever configured DNS, you've probably wondered: should I use an A record or a CNAME record? Both point a domain to a destination, but they work very differently. Here's what you need to know.
What Is an A Record?
An A record (Address record) maps a domain name directly to an IPv4 address. It's the most fundamental DNS record type.
example.com. A 93.184.216.34
When someone visits your domain, the A record tells DNS resolvers the exact IP address of the server hosting your website.
What Is a CNAME Record?
A CNAME record (Canonical Name record) maps a domain name to another domain name. It's essentially an alias.
www.example.com. CNAME example.com.
blog.example.com. CNAME mysite.hosting.com.
When a resolver encounters a CNAME, it follows the chain and looks up the target domain's A record to get the final IP address.
Key Differences
| Feature | A Record | CNAME Record |
|---|---|---|
| Points to | IP address | Another domain name |
| Can be used at root/apex | Yes | No (with exceptions) |
| Can coexist with other records | Yes | No — a CNAME cannot share a name with other record types |
| Lookup speed | One lookup | Requires additional lookup(s) |
| Flexibility when IPs change | Must update manually | Automatically follows the target |
When to Use an A Record
- Root/apex domain — You must use an A record (or AAAA for IPv6) for your root domain (example.com) since CNAME records are not allowed at the zone apex per the DNS specification.
- When you know the IP address — If your hosting provider gives you a static IP, use an A record.
- Performance-sensitive setups — A records resolve in one lookup, while CNAMEs require at least two.
When to Use a CNAME Record
- Subdomains pointing to third-party services — Services like GitHub Pages, Heroku, or AWS load balancers give you a hostname, not an IP. Use a CNAME.
- www subdomain — Point
www.example.comtoexample.comwith a CNAME, then use an A record on the root. - When the IP might change — If the target service manages its own IPs, a CNAME automatically follows those changes.
The CNAME at Root Problem
One of the most common DNS mistakes is trying to use a CNAME at the root domain. The DNS specification (RFC 1034) prohibits this because a CNAME cannot coexist with other record types, and the root domain needs SOA and NS records.
Some DNS providers offer workarounds:
- Cloudflare — CNAME flattening (resolves the CNAME to an A record at the edge)
- AWS Route 53 — ALIAS records
- DNSimple — ALIAS records
Quick Decision Guide
Ask yourself: Am I pointing to an IP address or a hostname?
- IP address → A record
- Hostname → CNAME record (unless it's the root domain)
When in doubt, check your hosting provider's documentation. They'll usually tell you exactly which record type to use.