# What is DNS, and DNS Record Types  | How DNS works

## What is DNS?

The Domain Name System is the phonebook of the Internet. Users access information online through domain names such as indiatimes.com or epson.com. A web browser communicates using the Internet Protocol address. DNS translates the domain name into an IP address, so the browser can load the internet resource.

*You type "*[*google.com*](http://google.com)*" in your browser and it loads. But how does your computer know where Google actually is?*

### **How does DNS work?**

The DNS resolution process converts a hostname into a computer-friendly IP address. An IP address is give to each device on the is used to find the appropriate internet device, like a street address, between what a user types into their web browser and the machine-friendly address necessary to locate the example.com webpage.

To understand the process of DNS resolution, it’s important to learn about the different hardware components a DNS query must pass through. For the web browser, the DNS lookup occurs “behind the scenes” and requires no interaction from the user’s computer apart from the request

## **What Are DNS Records?**

DNS records answer one question: **"Where should this request go?"**

Different record types give different answers:

* "Here's the IP address" (A Record)
    
* "Go ask that other domain" (CNAME Record)
    
* "Send email here" (MX Record)
    
* "These servers control this domain" (NS Record)
    

## **1\. A Record: The Basic Address**

**What it does:** Maps a domain name to an IP address.

**Example:**

```javascript
example.com  →  192.168.1.1
```

When someone types "example.com", DNS says "go to 192.168.1.1"

**Real use:** You point your domain to your server's IP address.

**Key point:** A records work with IPv4 addresses (like 192.168.1.1).

## **2\. CNAME Record: The Alias**

**What it does:** Points one domain name to another domain name.

**Example:**

```javascript
www.example.com  →  example.com
blog.example.com  →  example.com
```

**Real use:**

* Make [www.yoursite.com](http://www.yoursite.com/) and yoursite.com go to the same place
    
* Use blog.yoursite.com but host on Medium
    
* Route traffic through a CDN
    

**Key point:** CNAME redirects to another domain, which then has an A record pointing to the IP.

### **A Record vs CNAME**

**A Record:** Points directly to an IP

```javascript
example.com  →  192.168.1.1
```

**CNAME:** Points to another domain

```javascript
www.example.com  →  example.com  →  192.168.1.1
```

**Important:** You can't use CNAME for your root domain (example.com). Only subdomains can be CNAMEs.

## **3\. MX Record: Email Routing**

**What it does:** Tells email servers where to send emails for your domain.

**Example:**

```javascript
example.com  →  mail.example.com  (priority: 10)
example.com  →  backup-mail.example.com  (priority: 20)
```

**How it works:**

1. Someone emails [you@example.com](mailto:you@example.com)
    
2. Their email server checks MX records
    
3. Email goes to the server with lowest priority number
    

**Real use:** Point your domain's email to Gmail or Outlook servers.

**Key point:** Lower priority number = tried first. If it fails, tries the next one.

## **4\. NS Record: Who's in Control**

**What it does:** Says which DNS servers control your domain.

**Example:**

```javascript
example.com  →  ns1.cloudflare.com
example.com  →  ns2.cloudflare.com
```

**Real use:** You buy a domain from GoDaddy but use Cloudflare for DNS. You change NS records to Cloudflare's servers.

**Key point:** NS records determine who manages all your other DNS records.

### **NS vs MX: The Difference**

**NS Record:** Which servers control ALL DNS for this domain

**MX Record:** Which servers handle EMAIL only

## **How They Work Together**

Real example for company.com:

```javascript
A Record:
company.com  →  93.184.216.34

CNAME Records:
www.company.com  →  company.com
blog.company.com  →  company.com

MX Records:
company.com  →  smtp.google.com  (priority: 10)

NS Records:
company.com  →  ns1.cloudflare.com
```

**What this means:**

* Main site is at that IP
    
* www and blog point to the same server
    
* Emails go to Google
    
* Cloudflare manages the DNS
    

### **Complete Flow for** [**www.company.com**](http://www.company.com/)

1. Browser asks: "What's [www.company.com?](http://www.company.com/?)"
    
2. DNS checks NS records: "Ask Cloudflare"
    
3. Cloudflare checks CNAME: "It's an alias for company.com"
    
4. Cloudflare checks A record: "That's 93.184.216.34"
    
5. Browser connects to that IP
    

Happens in milliseconds!

## **Common Setups**

**Simple Website:**

```javascript
yoursite.com      →  192.168.1.1  (A)
www.yoursite.com  →  yoursite.com  (CNAME)
```

**Website + Email:**

```javascript
yoursite.com      →  192.168.1.1  (A)
www.yoursite.com  →  yoursite.com  (CNAME)
yoursite.com      →  mail.google.com  (MX)
```

**Using CDN:**

```javascript
yoursite.com      →  192.168.1.1  (A)
www.yoursite.com  →  yoursite.cdn.com  (CNAME)
yoursite.com      →  ns1.cloudflare.com  (NS)
```

## **Why Developers Need This**

You'll use DNS records for:

* **Deploying sites:** Point domain to server IP
    
* **Subdomains:** Create api.yoursite.com or dev.yoursite.com
    
* **Email setup:** Configure business email
    
* **CDNs:** Route through Cloudflare or AWS
    
* **Debugging:** Check DNS when sites don't load
    

**Interview tip:** Know A vs CNAME and what MX/NS records do.

## **Quick Summary**

* **A Record:** Domain → IP address
    
* **CNAME Record:** Domain → Another domain (alias)
    
* **MX Record:** Where emails go (with priority)
    
* **NS Record:** Which servers control DNS
    

**Remember:**

* A points to IPs, CNAME points to domains
    
* MX is for email, NS is for DNS control
    
* Lower MX priority number = higher priority
    
* Can't use CNAME on root domain
    

Understanding DNS helps you deploy sites, fix issues, and ace interviews.
