# DNS Record Types Explained 
(A, AAAA, CNAME, MX, TXT, NS)

## **How does a browser know where a website lives?**

When you type [**google.com**](http://google.com) in your browser and hit Enter…  
your browser somehow finds the correct server and loads the website.

But here’s the twist:

👉 Computers don’t understand names like [**google.com**](http://google.com)  
✅ They understand **IP addresses** like `142.250.190.14`

So the big question is:

**How does “**[**google.com**](http://google.com)**” turn into an IP address?**  
That’s where **DNS** comes in.

---

## **What is DNS? (Super simple)**

DNS stands for **Domain Name System**.

Think of DNS as the **phonebook of the internet** 📖

* You search a name: **Shubham**
    
* You get the number: **+91xxxxx**
    

Same here:

* You type: [**example.com**](http://example.com)
    
* DNS returns: **IP address of the server**
    

✅ DNS helps humans use easy website names  
✅ while computers talk using IP addresses

---

## **Why DNS records are needed**

DNS doesn’t work with just one line of data.  
Different internet tasks need different information, like:

* Where is the website hosted?
    
* Who controls this domain?
    
* Where should emails go?
    
* Is this domain verified for Google / GitHub / SSL?
    

All of this info is stored as **DNS Records**.

👉 DNS records are like “instructions” saved for your domain.

---

## **DNS Record Types (One by One)**

### **1\. NS Record (Name Server Record)**

**NS record tells: who is responsible for the domain.**

It points your domain to **Name Servers** (DNS servers), like:

* Cloudflare
    
* GoDaddy
    
* Namecheap
    
* AWS Route 53
    

**Simple example**

Think of a domain as a house 🏠  
NS record is like saying:

✅ “This property is managed by these offices (name servers).”

If NS records are wrong, nothing works — your website and email won’t resolve properly.

---

### **2\. A Record (Address Record)**

**A record maps: domain → IPv4 address**

Example:

```plaintext
example.com → 93.184.216.34
```

### What problem does it solve?

Browser needs the real server location (IP).  
A record tells where your website lives (IPv4).

✅ Most common DNS record for websites.

---

### **3\. AAAA Record**

**AAAA record maps: domain → IPv6 address**

Example:

```plaintext
example.com → 2606:2800:220:1:248:1893:25c8:1946
```

**What problem does it solve?**

Same as A record, but for **IPv6** (newer version of IP).

👉 A = IPv4  
👉 AAAA = IPv6

Most websites keep both for better compatibility.

---

### **4\. CNAME Record (Canonical Name Record)**

**CNAME means: one domain name points to another domain name.**

Example:

```plaintext
www.example.com → example.com
```

or

```plaintext
blog.example.com → myblog.hashnode.dev
```

**What problem does it solve?**

Sometimes you don’t want to manage IP addresses directly.  
Instead, you want one name to follow another name automatically.

✅ If the target domain changes its IP, your CNAME still works.

**Real-life example**

CNAME is like saying:

📌 “My home address is the same as my main house address.”

---

### **A vs CNAME (Beginner confusion cleared)**

✅ **A Record**

Domain points directly to an IP:

```plaintext
example.com → 93.184.216.34
```

✅ **CNAME**

Domain points to another domain:

```plaintext
www.example.com → example.com
```

📌 Easy rule:  
✅ Use **A record** when you know the server IP  
✅ Use **CNAME** when you want to point to another domain/service

---

### **5\. MX Record (Mail Exchange Record)**

**MX record tells: where your emails should go.**

Example:

```plaintext
example.com → mail server (Google Workspace / Zoho / Outlook)
```

**What problem does it solve?**

When someone sends an email to:  
📩 [`contact@example.com`](mailto:contact@example.com)

Email systems need to know:  
✅ “Which mail server handles this domain?”

That’s exactly what MX record does.

### Simple example

MX record is like a **post office route** 📬  
It tells:  
✅ “All letters for this domain should go to this address.”

---

### **NS vs MX (Beginner confusion cleared)**

✅ **NS Record:** who manages DNS for the domain  
✅ **MX Record:** where emails for the domain should be delivered

---

### **6\. TXT Record**

**TXT record stores extra text-based information.**

It is commonly used for:  
✅ Domain verification (Google, GitHub, etc.)  
✅ Email security (SPF / DKIM / DMARC)  
✅ Ownership proof

### What problem does it solve?

TXT helps prove:  
✅ “Yes, I own this domain.”  
✅ “Yes, this server is allowed to send emails.”

Example:

```plaintext
google-site-verification=xxxxxxx
```

---

## **How all DNS records work together for one website**

Let’s say you have a small website:

🌐 [`example.com`](http://example.com)  
and you also want:

* [`www.example.com`](http://www.example.com)
    
* professional email [`hello@example.com`](mailto:hello@example.com)
    

Here’s how DNS records work together:

✅ **NS records** → your DNS provider controls the domain  
✅ **A record** → points [`example.com`](http://example.com) to your server IP  
✅ **CNAME** → points [`www.example.com`](http://www.example.com) to [`example.com`](http://example.com)  
✅ **MX records** → emails go to Gmail/Zoho mail servers  
✅ **TXT records** → verification + email security  
✅ **AAAA record (optional)** → if you also use IPv6

---

## Mini Flow: Browser → DNS → Server

When user opens your website:

1. User types [`example.com`](http://example.com)
    
2. Browser asks DNS: “Where is this website?”
    
3. DNS replies with A/AAAA record (IP)
    
4. Browser connects to that IP server
    
5. Website loads ✅
    

---

## Quick Summary (Easy Revision)

✅ **NS** = who controls the domain DNS  
✅ **A** = domain → IPv4 address  
✅ **AAAA** = domain → IPv6 address  
✅ **CNAME** = name → another name  
✅ **MX** = where email should go  
✅ **TXT** = verification and extra info
