DNS Record Types: Complete Guide

A, CNAME, MX, TXT, NS — every DNS record type explained with real examples and use cases. The essential reference for domain and subdomain management.

A

A Record — Address Record

The A record is the most fundamental DNS record. It maps a hostname (like example.com or api.example.com) directly to an IPv4 address. When someone visits your domain, DNS resolution starts by looking up the A record to find which IP address to connect to.

You can have multiple A records for the same hostname pointing to different IP addresses — this is used for round-robin DNS load balancing (each query returns a different IP from the list, distributing traffic across multiple servers). A records have a TTL (Time to Live) that controls how long DNS resolvers cache the record; lower TTL means faster propagation when you change an IP, but more DNS queries.

# A record examples example.com IN A 203.0.113.1 www.example.com IN A 203.0.113.1 api.example.com IN A 203.0.113.50 # Multiple A records for load balancing www.example.com IN A 203.0.113.1 www.example.com IN A 203.0.113.2
Use for: Pointing any hostname to a specific server IP address. Required for root domains (naked domains like example.com). The most common DNS record you'll create.
AAAA

AAAA Record — IPv6 Address Record

The AAAA record (quad-A) is the IPv6 equivalent of the A record. It maps a hostname to an IPv6 address. As IPv4 address space has been exhausted, IPv6 adoption is growing. Modern servers, CDNs, and hosting providers increasingly support IPv6. A properly configured website should have both A and AAAA records — visitors with IPv6 connectivity will prefer the AAAA record.

example.com IN AAAA 2001:0db8:85a3:0000:0000:8a2e:0370:7334
CNAME

CNAME Record — Canonical Name Record

A CNAME record creates an alias — it maps one hostname to another hostname (not directly to an IP). When a DNS resolver looks up a CNAME, it follows the chain to the final A/AAAA record. CNAMEs are useful when you want a subdomain to point to a third-party service that gives you a hostname (not an IP) as their endpoint.

Important limitation: A CNAME record cannot coexist with other record types at the same name. Most critically, you cannot put a CNAME at the root/apex of your domain (example.com), because the apex also needs SOA and NS records. This is why services like Cloudflare offer "CNAME flattening" or "ALIAS" records that allow root domain CNAME-like behavior.

# CNAME examples www IN CNAME example.com. shop IN CNAME stores.shopify.com. docs IN CNAME example.github.io. cdn IN CNAME d1abc23def.cloudfront.net. # Note the trailing dot — it means "absolute" name
Use for: Pointing subdomains to third-party service endpoints (Shopify, GitHub Pages, Cloudfront, Heroku, etc.). Never use CNAME at the root domain.
MX

MX Record — Mail Exchange Record

MX records specify which mail servers receive email for your domain. When someone sends an email to user@example.com, the sender's mail server queries the MX record to find which server to deliver to. MX records have a priority number — lower numbers mean higher priority. You typically have 2-3 MX records pointing to different mail servers for redundancy.

Modern email providers (Google Workspace, Microsoft 365, Proton Mail for Business) give you specific MX records to add when setting up your custom domain email. If you change email providers, you update the MX records — and after the TTL expires, email automatically routes to the new provider.

# Google Workspace MX records @ IN MX 1 aspmx.l.google.com. @ IN MX 5 alt1.aspmx.l.google.com. @ IN MX 5 alt2.aspmx.l.google.com. @ IN MX 10 alt3.aspmx.l.google.com. @ IN MX 10 alt4.aspmx.l.google.com.
Use for: Configuring which mail servers receive email for your domain. Required for any custom email address (@yourcompany.com). Never use IP addresses in MX records — only hostnames.
TXT

TXT Record — Text Record (SPF, DKIM, DMARC)

TXT records store arbitrary text associated with a domain. Originally for informational purposes, TXT records are now primarily used for email authentication standards and domain ownership verification.

SPF (Sender Policy Framework): Specifies which servers are authorized to send email for your domain. Helps prevent email spoofing. An SPF record lists your authorized sending IP addresses or mail servers. Recipients' mail servers check SPF to determine if the email appears to be from an authorized source.

DKIM (DomainKeys Identified Mail): Adds a cryptographic signature to outgoing emails that allows recipients to verify the email genuinely came from your domain and wasn't tampered with in transit. Your mail server signs emails with a private key; the corresponding public key is published in a DKIM TXT record at a selector subdomain (e.g., google._domainkey.example.com).

DMARC (Domain-based Message Authentication): Builds on SPF and DKIM to specify what happens to emails that fail authentication — reject them, quarantine them (mark as spam), or just report them. DMARC also provides a reporting mechanism where receiving servers send data about failed authentications to your specified email address.

# SPF record @ IN TXT "v=spf1 include:_spf.google.com ~all" # DKIM record (selector = "google") google._domainkey IN TXT "v=DKIM1; k=rsa; p=MIIBIjANBgkq..." # DMARC record _dmarc IN TXT "v=DMARC1; p=quarantine; rua=mailto:dmarc@example.com" # Domain ownership verification (Google Search Console) @ IN TXT "google-site-verification=abc123def456..."
Use for: Email authentication (SPF, DKIM, DMARC) — essential for email deliverability. Domain ownership verification for Google Search Console, AWS, Cloudflare, etc.
NS

NS Record — Name Server Record

NS records specify which DNS servers are authoritative for your domain — i.e., which servers hold the "official" DNS records for your domain. When you register a domain, you set NS records to point to your chosen DNS provider (your registrar's nameservers, Cloudflare, AWS Route 53, etc.). All DNS queries for your domain are ultimately directed to these nameservers.

Changing NS records means moving all DNS management to a new provider. The change propagates slowly (NS record TTLs are typically 48-72 hours) and must be made at your domain registrar — not in your current DNS provider's control panel. After an NS change, you must recreate all DNS records at the new provider before switching, to avoid downtime.

# Cloudflare nameservers (example) example.com IN NS alice.ns.cloudflare.com. example.com IN NS bob.ns.cloudflare.com.
Change NS records when: Switching DNS providers. For example, moving from your registrar's default DNS to Cloudflare for performance, security, or analytics. Set at your registrar control panel.