Skip to content
Tutorials Center
My learning

Topics

Lesson 32 of 55 ยท Networks and the Internet

The Internet, IP Addresses and DNS

Understand how the Internet works: IPv4 and IPv6 addresses, subnets, ports, how DNS turns names into addresses step by step, and what Internet providers do.

Computers on the Internet find each other by number, not by name. Behind every address you type, such as www.example.com, is a numeric IP address that tells routers where to send packets. Two systems work together to make this invisible to you: IP addressing, which gives every reachable device a location, and the Domain Name System (DNS), which translates human-friendly names into those numbers.

This lesson explains what IP addresses look like, how a subnet splits a network, what ports add, how a DNS lookup travels through a chain of servers, and where your Internet provider fits in. It follows Networking Basics and leads into How the Web Works.

The Internet and your provider

The Internet is thousands of independent networks run by Internet service providers (ISPs), universities, companies and cloud providers. They interconnect at exchange points and through paid agreements, and routers pass each packet along from one network to the next toward its destination. No one owns the whole thing; they cooperate because they use the same protocols.

Your ISP is the company that connects your home or phone to this web of networks. It assigns your router a public address, carries your packets to the rest of the Internet and usually provides a DNS server too. Packets typically cross several networks, with a router at each junction picking the next hop.

IPv4 addresses

An IPv4 address is a 32-bit number, written as four decimal numbers (0 to 255) separated by dots, such as 192.168.1.20. Each number is one byte, called an octet. 32 bits give about 4.3 billion addresses, which sounded like plenty in the 1980s and turned out not to be enough for phones, laptops and gadgets.

Two ideas stretched IPv4's lifetime. First, private addresses: ranges reserved for use inside networks and never routed on the public Internet (10.x.x.x, 172.16.x.x to 172.31.x.x, 192.168.x.x). Your home devices use them. Second, NAT (network address translation): your router replaces the private source address on outgoing packets with its single public address and remembers which internal device each reply belongs to. Hundreds of devices can share one public address this way.

A few other ranges are special: 127.0.0.1 is localhost, the machine itself; 0.0.0.0 means "any/unspecified"; and 169.254.x.x is what a device gives itself when it expected an address from the network but got none.

IPv6

IPv6 was designed to remove the shortage. Its addresses are 128 bits, written as eight groups of hexadecimal digits separated by colons, such as 2001:db8:85a3:0:0:8a2e:370:7334. Leading zeros in a group can be dropped, and one run of all-zero groups can be replaced by ::, so 2001:db8::1 is a valid address. 128 bits give a number of addresses so large that every device can have its own public address without NAT. IPv4 and IPv6 run side by side today, and most devices speak both. (Hexadecimal is covered in Binary, Octal and Hexadecimal.)

Subnets

An address has two parts: a network part, shared by all devices on the same network, and a host part, which identifies one device. A subnet mask or, more compactly, a prefix length says where the split is. In CIDR notation, 192.168.1.0/24 means that the first 24 bits are the network and the last 8 bits are for hosts. Those 8 bits allow 2^8 = 256 addresses, of which two are reserved (the network address and the broadcast address), leaving 254 usable devices.

Subnets matter because routers only need one entry per network, not one per device, and because a device decides whether a destination is on its own network (talk directly through the switch) or elsewhere (send to the router, the default gateway). The stand-in below performs those bit operations.

JS A subnet calculator

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Ports

An IP address gets a packet to the right machine, but a machine runs many network programs at once. A port is a 16-bit number (0 to 65535) that picks the right program on that machine. Think of the IP address as a building's street address and the port as the apartment number.

Servers listen on well-known ports by convention: HTTP on 80, HTTPS on 443, SSH on 22, DNS on 53, and SMTP (email sending) on 25 or 587. When your browser connects, the operating system picks a random high port as the source, so replies come back to the right tab. A connection is identified by the pair of addresses and ports at both ends. You write them together as address:port, for example 203.0.113.9:443. A firewall can allow or block traffic by port, which is how a server exposes the services it intends to offer and no others.

DNS: the Internet's phone book

Remembering numbers is hard and addresses change, so the Domain Name System translates names such as www.example.com into addresses. It is a worldwide, distributed database, and no single server holds all of it. Names are read right to left, from broadest to most specific: com (top-level domain), example (the registered domain), www (a host inside it).

When your device needs an address, it asks a recursive resolver, usually run by your ISP or a public DNS service. If the resolver does not already know, it asks around, level by level:

sequenceDiagram
  participant D as Your device
  participant R as Resolver
  participant Root as Root server
  participant TLD as .com server
  participant Auth as example.com server
  D->>R: What is www.example.com?
  R->>Root: www.example.com?
  Root-->>R: Ask the .com servers
  R->>TLD: www.example.com?
  TLD-->>R: Ask example.com's servers
  R->>Auth: www.example.com?
  Auth-->>R: 203.0.113.9 (valid 300 s)
  R-->>D: 203.0.113.9

The resolver does the walking so your device sends just one question.

The root servers know only who runs each top-level domain. The TLD servers know who is responsible for each registered name beneath them. The authoritative server for the domain holds the real records. Common record types are A (name to IPv4), AAAA (name to IPv6), CNAME (this name is an alias for another), MX (where to deliver email) and TXT (free text, used for verification).

Every answer carries a TTL (time to live): how many seconds it may be remembered. Resolvers, operating systems and browsers all cache answers, so the long chain above happens only occasionally. This keeps DNS fast and the root servers from drowning, but it also explains why a DNS change can take a while to be visible everywhere: old answers linger until their TTL runs out.

The stand-in below implements this chain with three small "servers" and a cache.

JS A DNS resolver with caching

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Looking at DNS and connections yourself

On a real computer you can ask DNS questions and test a connection from a terminal. The text below is read-only sample output, with an address from a range reserved for examples; your own results will differ in names, addresses and timing.

TEXT
> nslookup www.example.com
Server:   home.router
Address:  192.168.1.1

Non-authoritative answer:
Name:     www.example.com
Address:  203.0.113.9

> ping www.example.com
Reply from 203.0.113.9: bytes=32 time=24ms TTL=57
Reply from 203.0.113.9: bytes=32 time=23ms TTL=57

"Non-authoritative" means the answer came from a cache rather than from the domain's own server. time=24ms is the round-trip latency from the previous lesson, and TTL here is a hop limit: each router decreases it by one, so a packet in a routing loop eventually dies instead of circling forever. (Unlike the DNS TTL, which counts seconds.) Some servers do not answer ping, so no reply does not always mean the site is down.

What is real and what is a stand-in? IPv4, IPv6, CIDR, ports, the root, TLD and authoritative levels, record types and TTL caching are real. The JavaScript code models a resolver with three plain objects and a counter. A real resolver speaks the DNS protocol over the network, can use several servers per level, validates answers (DNSSEC) and may hide your queries from your ISP with encrypted DNS.

Check your understanding

Quick check ยท 5 questions

of 5 answered You scored / 5 ยท perfect!

  1. 1. How many bits does an IPv4 address have?

    IPv4 uses 32 bits, written as four octets. IPv6 uses 128 bits.
  2. 2. What does 192.168.1.0/24 tell you?

    The prefix length gives the number of network bits. The remaining 8 bits allow 256 addresses, 254 of them usable.
  3. 3. What does a port number identify?

    The IP address finds the machine; the port finds the application on it, such as 443 for HTTPS.
  4. 4. In which order does a recursive resolver typically ask when it has nothing cached?

    The root points to the TLD servers, which point to the domain's authoritative servers that hold the actual record.
  5. 5. Why can a DNS change take hours to reach everyone?

    Cached answers are reused until the time to live runs out, so some users keep seeing the old address for a while.

Summary

  • The Internet is a network of independent networks; your ISP connects you and assigns a public address.
  • IPv4 addresses have 32 bits and are running out; NAT and private ranges stretched them, and IPv6 has 128 bits.
  • A prefix length such as /24 splits an address into network and host parts, so devices know when to use the gateway.
  • Ports pick the program on a machine; well-known ports include 80, 443, 22 and 53.
  • DNS translates names to addresses through root, TLD and authoritative servers, with caching controlled by TTL.
  • Tools such as nslookup and ping let you inspect DNS answers and round-trip latency.

Continue with How the Web Works.