Skip to content
Tutorials Center
My learning

Topics

Lesson 30 of 55 ยท Networks and the Internet

Networking Basics

Learn how computer networks work: LANs and WANs, switches and routers, Wi-Fi versus Ethernet, bandwidth versus latency, and how protocols stack into layers.

A single computer is useful, but connected computers are far more so. A network is a group of devices that can exchange data: your phone and laptop at home, the computers in an office, or the millions of machines that make up the Internet. Every time you load a page, send a message or stream a video, data is cut into small pieces, passed through several devices and put back together at the other end.

This lesson introduces the vocabulary and the key ideas: the kinds of network, the devices that link them, the difference between how much a link can carry and how fast a reply arrives, and the layered design that lets very different technologies work together. It starts the chapter after File Systems and prepares you for The Internet, IP Addresses and DNS.

LANs and WANs

A LAN (local area network) covers a small area such as a home, a school or an office floor. Devices on a LAN are close together, so links are fast and cheap, and one person or organization usually controls them. A WAN (wide area network) connects LANs across cities or countries, often using lines leased from telecom companies. The Internet is the largest WAN: a network of networks, each independently run, agreeing to exchange data using common rules.

Other names you will see: a PAN (personal area network, such as Bluetooth headphones and a phone), a MAN (metropolitan area network), and VPN (virtual private network), which sends private traffic through an encrypted tunnel across a public network.

Devices that build a network

Each device has a network interface (a card or chip) with a hardware address burned in at manufacture, called a MAC address. On top of that, the network gives it a logical IP address, which you will study in the next lesson. The devices in between do different jobs:

  • Switch. Connects the devices on one LAN. It learns which MAC address sits behind which port and forwards each frame only to the right port, so devices do not hear each other's traffic. (An older hub repeated everything to everyone.)
  • Router. Connects different networks and decides where to send each packet next. Your home router joins your LAN to your Internet provider's network. A router looks at IP addresses, not MAC addresses.
  • Access point. Gives Wi-Fi devices a way onto the wired network. Home routers usually combine router, switch and access point in one box.
  • Modem. Converts between the signals of a cable, fibre or phone line and the digital signals of your network.
flowchart LR
  L["Laptop"] --- SW["Switch"]
  P["Phone (Wi-Fi)"] --- AP["Access point"]
  AP --- SW
  S["Printer"] --- SW
  SW --- R["Router"]
  R --- ISP["Internet provider"]
  ISP --- NET(["The Internet"])

A typical home or office: devices join a switch, the router links the LAN to the Internet.

Wi-Fi versus Ethernet

Ethernet sends signals through cables (copper twisted pairs, or fibre for long distances). Wi-Fi sends them as radio waves. Both carry the same IP traffic, but they behave differently.

Ethernet Wi-Fi
Speed Steady, commonly 1 or 2.5 gigabit per second at home Varies with distance, walls and interference
Delay Low and consistent Higher and more variable
Sharing Each cable is a private link to the switch Devices share the same radio channel and take turns
Convenience Needs a cable Wireless and mobile
Security Someone must plug in Needs encryption (WPA2 or WPA3) because radio can be received by anyone nearby

Use a cable for a desktop, a game console or a video-call machine where stability matters, and Wi-Fi for everything that moves. Many Wi-Fi problems come from distance, thick walls, crowded channels (many neighbours' networks) and old devices slowing a shared channel for the rest.

Bandwidth versus latency

Two numbers describe a connection, and they are often confused.

Bandwidth is how much data a link can carry per second, measured in bits per second (Mbit/s, Gbit/s). It is the width of a pipe. Note the units: network speeds use bits, while file sizes use bytes, so a 100 Mbit/s link moves at most about 12.5 MB per second (divide by 8).

Latency is how long a single piece of data takes to travel from sender to receiver (or there and back, the round-trip time), measured in milliseconds. It is the length of the pipe. Latency has a physical floor: signals cannot travel faster than light, so a round trip across an ocean costs tens of milliseconds even on a perfect fibre. Distance, the number of devices on the path and congestion all add delay.

Which matters depends on the job. Downloading a large file needs bandwidth. Video calls, online games and remote desktops need low latency. Loading a page that makes many small requests suffers from latency, because each request waits for a reply. The stand-in below models the time to fetch data as latency plus size divided by bandwidth.

JS Bandwidth versus latency

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

No output.

Compare the rows. For the large file, the fast link wins even when the server is far away, because transfer time dominates. For fifty tiny files, the far server on the fast link is slower than the near server on the slow link, because 150 ms is paid fifty times. This is why browsers open several connections at once and why servers placed near users (see Email, the Cloud and Everyday Online Services) feel faster.

Packets and protocols

Networks do not send a file as one long stream. They cut it into packets, each a small chunk of data with a header that says where it is going. Packets from many conversations share the same links and are interleaved, which uses the wires efficiently. Different packets of one message may take different routes and arrive out of order; the receiver puts them back in sequence and asks for any that were lost.

For this to work, both ends must agree on exact rules: how addresses look, what a header contains, how to request a retry. A set of such rules is a protocol. Familiar ones include IP (addressing and routing), TCP (reliable delivery), HTTP (web pages), SMTP (email) and DNS (name lookup). No single protocol does everything, so they are arranged in layers.

Layers

In a layered design each layer does one job and relies on the layer below. A common simplified model has four layers:

Layer Job Examples
Application The service the user wants HTTP, DNS, SMTP
Transport Delivery between programs, with ports; reliability TCP, UDP
Internet (network) Addressing and routing across networks IP
Link Delivery over one physical hop Ethernet, Wi-Fi

When you send data, each layer wraps it in its own header, like putting a letter in an envelope, then that envelope in a bigger one. This is called encapsulation. The receiver peels the envelopes off in reverse order. A switch only needs the outermost link-layer envelope; a router opens it to read the IP address on the next one; the receiving program finally reads the original message. Because each layer only talks to its neighbours, Wi-Fi can be replaced by Ethernet without changing HTTP at all.

flowchart TD
  A["Application data<br/>GET /index.html"] --> T["Transport: add ports"]
  T --> I["Internet: add IP addresses"]
  I --> LK["Link: add MAC addresses"]
  LK --> W(["Bits on the wire or in the air"])

Encapsulation on the sending side; the receiver removes the headers in reverse order.

The stand-in wraps and unwraps a message through these layers. The addresses are made up.

JS Wrapping a message in layers

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

No output.

What is real and what is a stand-in? LANs, switches, routers, packets, encapsulation and the four-layer model are real. The code uses plain objects instead of binary headers, and real networks replace the MAC addresses at every hop (the link layer header is rewritten each time), while the IP addresses stay the same end to end. The addresses shown are examples from ranges reserved for documentation and private networks.

Network types and topologies

Networks are grouped by size and by shape. Size comes first.

Type Full name Covers Example
PAN Personal area network A few metres around one person Phone linked to earbuds and a watch by Bluetooth
LAN Local area network One building or campus Home Wi-Fi, a school's computer lab
MAN Metropolitan area network A city or large campus A city's linked government offices, a cable-TV network
WAN Wide area network Countries and continents A bank's network between its branches; the Internet

Two more terms describe how data travels. In a point-to-point link, two devices share a dedicated connection (a cable between two switches). In a broadcast network, many devices share one medium and everyone can hear every message, so each message carries an address and only the intended receiver keeps it (classic shared Ethernet, Wi-Fi). Messages can be sent as unicast (to one device), multicast (to a group) or broadcast (to all devices on the local network).

Topologies: the shape of a network

The topology is the layout of the devices and links.

flowchart TD
  subgraph Star["Star"]
    SW["Switch"] --- S1["PC 1"]
    SW --- S2["PC 2"]
    SW --- S3["PC 3"]
    SW --- S4["PC 4"]
  end
  subgraph Ring["Ring"]
    R1["A"] --- R2["B"] --- R3["C"] --- R4["D"] --- R1
  end
  subgraph Mesh["Full mesh"]
    M1["A"] --- M2["B"]
    M1 --- M3["C"]
    M1 --- M4["D"]
    M2 --- M3
    M2 --- M4
    M3 --- M4
  end

Three of the five common layouts: star, ring and full mesh.

Topology How devices connect Strengths Weaknesses
Bus All devices share one cable Cheap, little cable One break stops everyone; collisions; obsolete
Ring Each device links to two neighbours in a loop Orderly access One break can stop the ring (dual rings fix this)
Star Every device links to a central switch Easy to manage; one failed device does not affect others The centre is a single point of failure
Mesh Devices link to many or all others Very reliable; several routes Expensive; many links (n(n-1)/2 in a full mesh)
Tree (hierarchical) Stars connected in layers Scales well; matches buildings and organizations A failure high in the tree cuts off whole branches

Today's wired LANs are physically stars (every cable runs to a switch), and Wi-Fi networks are stars around an access point. The Internet itself is a partial mesh with many alternative routes, which is why it keeps working when a cable is cut.

Python How many links does each topology need?

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

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Network devices compared

You met the switch, router, access point and modem earlier. A few more devices complete the picture. They are often described by the layer they work at (see the Layers section above): a lower-layer device sees less of each message and is simpler and faster.

Device What it does Looks at Notes
Repeater Boosts a weakening signal so it travels farther Raw signal Wi-Fi range extenders do this
Hub Copies every incoming signal out of all other ports Raw signal Obsolete; everyone hears everything and collisions are common
Bridge Joins two network segments, forwarding only what needs to cross MAC addresses The ancestor of the switch
Switch Learns which MAC address is behind each port and forwards frames only there MAC addresses Each port is a private link; the heart of a LAN
Router Connects different networks and chooses the path for each packet IP addresses Your home router joins your LAN to the Internet
Modem Converts between your provider's line signals and digital data Signals Often built into the home router
Access point Joins Wi-Fi devices to the wired network Frames See Wi-Fi and Wireless Basics
Gateway Connects networks that use different protocols or formats; also the name for the device that is your way out to the Internet (your "default gateway") Varies Often the same box as the router
Firewall Allows or blocks traffic according to rules (addresses, ports, applications) Packets and connections Can be hardware or software; see Malware and Safe Habits
Load balancer Spreads requests over several servers Requests Used by busy websites

Remember the three that matter most at home: a switch moves data inside one network, a router moves it between networks, and a firewall decides what is allowed to pass. In a household one box typically combines all three plus a modem and an access point.

Check your understanding

Quick check ยท 5 questions

of 5 answered You scored / 5 ยท perfect!

  1. 1. Which device forwards packets between different networks using IP addresses?

    A router connects separate networks and chooses the next hop for each packet by its IP address. A switch works inside one LAN.
  2. 2. A connection has high bandwidth but also high latency. What kind of task suffers most?

    Each small exchange waits a full round trip, so delay adds up even though the pipe is wide.
  3. 3. A plan advertises 200 Mbit/s. About how many megabytes per second is that at most?

    There are 8 bits in a byte, so 200 / 8 = 25 MB/s at best, before overhead.
  4. 4. What does encapsulation mean in a layered protocol stack?

    Like envelopes inside envelopes: the receiver removes the headers in the opposite order.
  5. 5. Why is Ethernet usually better than Wi-Fi for a video-call desktop that never moves?

    A cable is a dedicated link without radio interference, while Wi-Fi shares the air and varies with the environment.

Summary

  • A LAN covers a small area; a WAN links LANs; the Internet is a network of networks.
  • Switches connect devices in a LAN using MAC addresses; routers connect networks using IP addresses.
  • Ethernet is steady and low-delay; Wi-Fi is convenient but variable and needs encryption.
  • Bandwidth is capacity (bits per second), latency is delay (milliseconds); different tasks depend on different ones.
  • Data travels in packets, governed by protocols arranged in layers (application, transport, internet, link).
  • Each layer wraps the data with a header (encapsulation), and the receiver unwraps it in reverse order.

Next: The Internet, IP Addresses and DNS.