Support >
  About cybersecurity >
  What is the difference between an A record and a CNAME record? Which one should you use when building a website?

What is the difference between an A record and a CNAME record? Which one should you use when building a website?

Time : 2026-11-04 14:52:58
Edit : DNS.COM

  When setting up a website and configuring DNS, A records and CNAME records are unavoidable. In your control panel, they appear side-by-side with nearly identical input fields; once you save your settings and the website loads, they might seem interchangeable. However, when the time comes to switch servers, integrate a CDN, or troubleshoot issues—such as suddenly failing to receive emails—the record type you initially chose can lead to far more trouble than you might have anticipated.

  The fundamental difference between these two records isn't just a matter of format—whether you enter an IP address or a domain name—but rather the distinct roles they play in the DNS resolution process. Once you grasp this, it becomes clear which record to use when building a site, and why certain scenarios mandate the use of one over the other.

  The Fundamental Difference: Destination vs. Transit Point

  An A record functions in a very direct manner. You point a domain name to an IPv4 address; when the DNS server receives a query, it returns that IP address straight to the client. The client then uses that IP to establish a connection. There are no intermediate steps—it is a one-to-one mapping between the domain name and the IP address.

  A CNAME record works differently. You point one domain name to another; when the DNS server receives a query, it doesn't return an IP address. Instead, it tells the client: "This domain is an alias for that other domain—go look that one up instead." The client must then initiate a second query to resolve the target domain, ultimately obtaining the IP address from that target.

  To use an analogy—imprecise, perhaps, but intuitive—an A record is like telling someone, "I live at [specific address]," allowing them to find you directly. A CNAME record is like saying, "I’m staying at a friend’s place"; the person must first locate your friend, and then find you through them. This adds an extra step of redirection, but it also offers a key advantage: if your "friend" moves, you don’t need to notify anyone to update your address—you simply ensure that your friend’s address is updated, and everything else remains correct. The direct consequence of this difference is that an A record hardcodes an IP address, whereas a CNAME record delegates the management of the IP address to a target domain name. The former is stable but rigid, while the latter is flexible but introduces an additional layer of dependency.

  A hard rule: The two cannot coexist for the same hostname.

  This is a requirement at the DNS protocol level, not a restriction imposed by any specific service provider. According to RFC 1034 and RFC 2181, once a CNAME record is set for a hostname, no other types of records—such as A, MX, or TXT records—can exist for that same hostname.

  The reason lies in the necessity for a deterministic resolution logic. If `www.example.com` were to have both a CNAME record pointing to `cdn.example.com` and an A record pointing to `1.2.3.4`, a DNS server responding to a query would face an unresolvable conflict: should it return the CNAME, directing the client to follow another domain, or should it return the IP address from the A record? The protocol does not permit such ambiguity, so it simply prohibits coexistence.

  In practice, most DNS management interfaces will block such conflicting configurations; you will receive an error if you attempt to add a CNAME record to a hostname that already has an A record. There is, however, one notable exception: on some platforms, the root domain (represented by `@` as the host record) may allow a CNAME record to coexist with MX or TXT records—a relaxation intended to accommodate specific business requirements. Nevertheless, this configuration carries risks; for instance, it can lead to intermittent issues with receiving emails, as MX queries might be "hijacked" by the CNAME record. For website hosting, using an A record for the root domain is the safer and more reliable choice.

  Which one should you use for your website? It depends on the scenario.

  The term "website hosting" encompasses a wide variety of scenarios, so it cannot be treated as a one-size-fits-all situation.

  Scenario 1: The domain points directly to a VPS with a static public IP address.

  This is the most common scenario. You purchase a VPS, receive a static public IP address, and decide to point your domain name to it. You use an "A record," entering that IP address as the value. Once saved and propagated, your domain will point directly to this machine. It’s simple, straightforward, and involves no intermediaries—the resolution path is as short as possible, and there are fewer potential points of failure.

  One might ask: "Could I use a CNAME record to point to a default domain name provided by the VPS host?" While technically possible, it is unnecessary. Since a VPS IP is typically static (unless you choose to change it), the primary advantage of a CNAME—avoiding the need to update DNS records when an IP changes—is irrelevant here. In fact, it introduces an unnecessary dependency: if the VPS provider’s default domain fails to resolve, your website will also become inaccessible.

  Scenario 2: Integrating a CDN or Reverse Proxy Service

  This is where a CNAME record truly shines. When you use a CDN, the provider assigns you a dedicated "acceleration" domain (e.g., `xxx.cdn-provider.com`). You should configure a CNAME record in your DNS settings to point `www.yourdomain.com` to this acceleration domain. The CDN provider manages the underlying node IP addresses—handling node scheduling, failover, and IP updates—so your CNAME record remains unchanged.

  If you were to use an A record instead—pointing `www` directly to a specific CDN node IP—your website would point to a defunct address the moment the CDN provider adjusts its nodes or reclaims that IP. You would then have to manually discover the issue and update the record. With a CNAME, such changes are entirely transparent to you.

  Scenario 3: Handling the Root Domain (@)

  Using a CNAME record for a root domain (often represented as `@`) is a common pitfall. Although some DNS providers may allow a CNAME at the root level, it can cause side effects. Root domains frequently host other records, such as MX records (for email) and TXT records (for SPF verification, etc.); the presence of a CNAME can interfere with the resolution of these other records. A more robust approach is as follows: use an A record for the root domain to point to the origin server's IP address, and use a CNAME record (or an A record pointing to the origin) for the "www" subdomain. This allows each to serve its specific purpose.

  Scenario 4: Multiple subdomains pointing to the same server

  For example, suppose `blog.example.com`, `shop.example.com`, and `api.example.com` all point to the same VPS. If you use A records, you would need to enter the IP address for each subdomain individually. Should the VPS IP change, you would have to update every single record. Alternatively, you could use an A record to point `server.example.com` to the IP, and then configure all subdomains as CNAME records pointing to `server.example.com`. If the IP changes, you only need to update that single A record, and all CNAME records will automatically follow suit. This is a classic use case for CNAMEs to reduce maintenance overhead—provided you are willing to accept a negligible increase in latency caused by the additional DNS lookup step.

  A detail often overlooked: The "flexibility" of CNAMEs comes at a cost.

  The convenience of CNAME records is not free; resolving one requires the client to perform an additional DNS query. In most cases, this extra query is handled within the cache of a recursive resolver (such as your ISP’s DNS or a public DNS service), so users experience no perceptible delay. However, if the target domain—the one the CNAME points to—encounters resolution issues, or if its TTL (Time-to-Live) is set so low that the cache expires frequently, the risk of resolution failure propagates along the chain.

  Another point to consider: A CNAME record should ideally point directly to the final destination, rather than into a long chain of CNAMEs. While the protocol permits chains—such as `a.com` pointing to `b.com`, which in turn points to `c.com`—this slows down resolution and complicates troubleshooting if any link in the chain fails. When configuring your DNS, ensure that CNAME records point directly to the domain that ultimately provides the service, rather than creating unnecessarily long chains.

DNS Amy
DNS Anna
DNS Jade
DNS NOC
Title
Email Address
Type
Information
Code
Submit