Computer and Networking Basics, Explained from Zero
If you are reading this, you probably want to understand how computers and networks really work, without a pile of jargon in the way. That is what this guide is for.
By the end you will be able to explain, in your own words, what a CPU and RAM do, what the OSI and TCP/IP models are for, how an IP address and a port work together, and what happens in the two seconds between typing a web address and seeing the page. Each idea builds on the one before it, so read it in order the first time.
1. How a computer works
Before computers can talk to each other, you need to know what one computer is made of. Four things matter.
The CPU: the part that does the work
The CPU (central processing unit) executes instructions. Everything a computer does, from adding two numbers to drawing a window, is broken down into tiny instructions the CPU runs one after another.
It repeats the same three steps over and over, called the fetch-decode-execute cycle:
- Fetch: get the next instruction from memory. The CPU keeps track of where it is using a program counter, which holds the address of the next instruction.
- Decode: work out what the instruction means and what data it needs.
- Execute: carry it out, for example do some arithmetic, read or write memory, or jump to a different instruction.
A modern CPU has several cores, and each core can run its own stream of instructions. More cores means more things can truly happen at the same time.
RAM: the desk you are working at
RAM (random access memory) holds the programs and data the CPU is using right now. It is fast, which is why the CPU works from it. But it is volatile: when power goes off, everything in it disappears.
Think of RAM as the desk you are working at. Whatever is on the desk is quick to reach, but the desk is small and gets cleared when you leave.
Storage: the filing cabinet
Storage (an SSD or hard drive) keeps your files, programs and operating system permanently. It is non-volatile: data stays when the power is off. It is much bigger and cheaper per byte than RAM, but slower.
Think of storage as the filing cabinet. It holds everything, but fetching from it takes longer than picking something up from your desk.
| CPU cache | RAM | Storage (SSD / hard drive) | |
|---|---|---|---|
| Speed | Fastest | Fast | Slowest of the three |
| Size | Smallest | Medium | Largest |
| Keeps data without power? | No | No | Yes |
| Role | Keeps what the CPU needs next, closest to it | Holds running programs and their data | Holds files and installed programs for the long term |
Computers are built this way because speed and size trade off against each other: the fastest memory is the most expensive per byte, so a computer uses a small amount of very fast memory and a large amount of slower memory, arranged as a hierarchy.
Programs and processes
A program is a set of instructions sitting on storage. It does nothing by itself. When you open it, the operating system loads it into memory and starts running it. That running instance is a process.
A process is more than code. The operating system also gives it its own memory area, a record of the files it has open, and permissions saying what it is allowed to do. A process moves between states: it is created, waits for its turn on the CPU, runs, sometimes blocks while waiting for something (such as a keypress or a file), and finally ends.
You may have many more processes than CPU cores. The operating system handles this by switching rapidly between them, a trick called context switching. Each core runs only one process at any moment, but the switching is so fast that everything seems to run at once.
Try it: open Task Manager (Windows), Activity Monitor (macOS), or run top in a Linux terminal. Each line is a process.
Why this matters for networking: every network connection belongs to some process. When we later talk about ports, you will see that a port is how the operating system hands incoming data to the right process.
2. How computers talk: layers and models
Sending a message from your laptop to a server on the other side of the world involves cables, radio waves, addresses, error handling, encryption and applications. Nobody could design all of that as one piece, so networking is split into layers. Each layer does one job and relies on the layer below it.
Think of posting a letter. You write the letter (the content), put it in an envelope with an address (instructions on where it goes), and the postal system moves it through trucks and sorting offices (the physical delivery). You do not need to know how the trucks work, and the truck drivers do not read your letter.
The OSI model (7 layers)
The OSI model is a reference model with seven layers. Read it from the bottom (closest to the wire) to the top (closest to you).
| # | Layer | What it does | Data unit | Examples |
|---|---|---|---|---|
| 7 | Application | Network services that applications use | Data | HTTP, DNS, SMTP |
| 6 | Presentation | Translating and formatting data, such as character encoding, compression, encryption | Data | Character encodings, compression |
| 5 | Session | Starting, managing and ending conversations | Data | Rarely a separate layer in practice; often handled inside the application |
| 4 | Transport | Delivering data between programs, with segmentation, acknowledgement and multiplexing | Segment | TCP, UDP |
| 3 | Network | Addressing and routing across many networks | Packet | IP, ICMP |
| 2 | Data Link | Moving frames between two directly connected devices | Frame | Ethernet, Wi-Fi |
| 1 | Physical | Sending raw bits over a medium | Bits | Cables, radio signals |
A classic memory trick, top to bottom: All People Seem To Need Data Processing.
The TCP/IP model (what the internet actually uses)
The TCP/IP model (also called the Internet protocol suite) is the model that matches the protocols actually running on the internet. The standard that describes it (RFC 1122) uses four layers:
| TCP/IP layer | What it does | Roughly covers OSI layers |
|---|---|---|
| Application | The protocols programs use: HTTP, DNS, SMTP and so on. RFC 1122 says it combines OSI's Presentation and Application functions; most diagrams also fold Session in | 5, 6, 7 |
| Transport | End-to-end communication between applications: TCP and UDP | 4 |
| Internet | Carries data from source host to destination host with IP | 3 |
| Link | Talks to the directly connected network: Ethernet, Wi-Fi | 1, 2 |
Some textbooks split the Link layer into Data Link and Physical and teach five layers. Both are common, so do not be thrown if you see five.
Which one is "correct"?
Both are models, and they are used for different purposes:
- OSI is a reference framework. It is used to teach and to talk about where a problem sits ("that is a layer 2 issue"). The internet was not built from it.
- TCP/IP describes the protocols that actually run the internet.
When people say "layer 3" or "layer 7" they are using OSI numbering, even when discussing TCP/IP networks.
Encapsulation: how the layers work together
When you send data, each layer wraps what it receives from above with its own header (and the link layer also adds a trailer). This is called encapsulation. The receiver unwraps the layers in reverse order.
Using a web request as the example:
- Application: your browser creates an HTTP request.
- Transport: TCP puts the request in a segment, adding the source and destination ports.
- Internet/Network: IP puts the segment in a packet, adding the source and destination IP addresses.
- Link: Ethernet or Wi-Fi puts the packet in a frame, adding the source and destination MAC addresses.
- Physical: the frame is sent as bits.
Remember this order: ports, then IP addresses, then MAC addresses, from inside to outside. It makes much of the rest of this guide fall into place.
3. IP addressing
Every device that talks on a network needs an IP address, so that data knows where to go and where it came from. It is like a postal address.
IPv4
An IPv4 address is a 32-bit number. To make it readable, it is written as four numbers from 0 to 255 separated by dots, such as 192.168.1.25. Each of the four numbers is called an octet because it is 8 bits.
A 32-bit space gives 2³² = 4,294,967,296 addresses in total, which turned out not to be enough for the whole world. Large blocks are also reserved for special uses, so fewer are available for the public internet.
Network part and host part
An IP address has two parts: which network the device is on, and which device it is on that network. A subnet mask or a CIDR prefix shows where the split is.
CIDR writes it as a slash and a number: the number of leading bits that identify the network. So:
192.168.1.25/24means the first 24 bits are the network and the last 8 bits identify the device.- The same thing as a mask is
255.255.255.0. - That network has 2⁸ = 256 addresses. The first (
192.168.1.0) names the network and the last (192.168.1.255) is the broadcast address, which leaves 254 addresses for devices.
Two devices can talk directly on a local network if they are in the same network. For anything outside, traffic goes to a router. More on that in section 9.
Public and private addresses
Three blocks are reserved for private networks (defined in RFC 1918). They are used inside homes and offices and are not routed on the public internet:
| Block | Range |
|---|---|
10.0.0.0/8 |
10.0.0.0 to 10.255.255.255 |
172.16.0.0/12 |
172.16.0.0 to 172.31.255.255 |
192.168.0.0/16 |
192.168.0.0 to 192.168.255.255 |
Notice 172.16.0.0/12 stops at 172.31.x.x. An address like 172.32.0.1 is not private. This is a common slip.
Other special addresses worth knowing:
127.0.0.0/8(usually127.0.0.1) is loopback, meaning "this very computer". Traffic to it never leaves the machine.169.254.0.0/16is link-local. A device gives itself one of these when it cannot get an address automatically.
TTL
Each IP packet carries a TTL (time to live) value. In practice it works as a hop counter: every router that forwards the packet subtracts one, and when it reaches zero the packet is discarded. This stops lost packets from circling forever.
IPv6
IPv6 was created to solve the shortage. An IPv6 address is 128 bits, written as eight groups of four hexadecimal digits separated by colons, such as 2001:0db8:0000:0000:0000:0000:0000:0001. That gives about 3.4 × 10³⁸ addresses.
Two rules shorten the writing:
- Leading zeros in each group can be dropped.
- One run of consecutive all-zero groups can be replaced by
::(only once per address).
So the address above becomes 2001:db8::1.
Useful special ones: ::1 is loopback, fe80::/10 is link-local, and fc00::/7 is for private local use. Global addresses currently come from 2000::/3.
4. Ports and common protocols
An IP address gets data to the right device. But many programs run on that device at the same time: a browser, a chat app, a mail client. How does incoming data reach the right one?
With ports. A port is a number from 0 to 65535 that identifies a service or conversation on a device. The IP address is the building's street address; the port is the apartment number.
TCP and UDP both use ports. A connection is identified by four things: your IP and port, and the other side's IP and port. This is why one server can handle thousands of connections to port 443 at once: each has a different client address and port.
Port ranges
IANA, the body that manages the registry, divides ports into:
| Range | Name |
|---|---|
| 0 to 1023 | System (well-known) ports |
| 1024 to 49151 | User (registered) ports |
| 49152 to 65535 | Dynamic / private ports |
When your browser connects to a website, it connects to a well-known port on the server (443) and the operating system picks a temporary dynamic port for your end. Exact ranges for the temporary ports vary by operating system, so treat the IANA range as the standard suggestion.
Common protocols and their ports
| Port | Protocol | What it is for |
|---|---|---|
| 20, 21 | FTP | File transfer (21 is control, 20 is data) |
| 22 | SSH | Secure remote login and file transfer |
| 23 | Telnet | Remote login in plain text. Do not use it, because everything is readable |
| 25 | SMTP | Email routing between servers |
| 53 | DNS | Turns names into addresses |
| 67, 68 | DHCP | Gives devices their network settings (67 server, 68 client) |
| 80 | HTTP | Web, unencrypted |
| 110 | POP3 | Email retrieval |
| 123 | NTP | Time synchronisation |
| 143 | IMAP | Email retrieval and sync |
| 443 | HTTPS | Web, encrypted |
| 445 | SMB | Windows file sharing |
| 3389 | RDP | Windows remote desktop |
A port number is a convention, not a law. A web server can run on port 8080, and nothing stops a program from using port 22 for something else. The table tells you what is normally there, not what must be there.
TCP and UDP
Two protocols at the transport layer carry almost everything:
TCP (Transmission Control Protocol) is reliable. It sets up a connection first, numbers every byte, confirms receipt, resends what is lost, and controls the sending speed so the receiver is not overwhelmed. Web pages, email and file transfers use it.
It starts with the three-way handshake:
- Client sends SYN ("I want to talk, my starting number is X").
- Server replies SYN-ACK ("OK, here is mine, and I got yours").
- Client sends ACK ("Got it").
Only then does data flow. At the end, each side sends a FIN to close politely.
UDP (User Datagram Protocol) is simple. It sends messages with no connection set-up and no guarantee of delivery or order. Its header has just four fields: source port, destination port, length and checksum. This low overhead makes it good for things where being fast matters more than being perfect: DNS queries, voice and video calls, and online games.
| TCP | UDP | |
|---|---|---|
| Connection set-up | Yes (handshake) | No |
| Delivery guaranteed and in order | Yes | No |
| Speed and overhead | More overhead | Lightweight |
| Typical use | Web, email, file transfer | DNS queries, calls, streaming, games |
One thing that is not TCP or UDP: ICMP
ICMP carries network error and status messages. ping uses ICMP echo request and reply, and traceroute uses the TTL value and the "time exceeded" replies from routers. ICMP lives at the network layer and has no port numbers. So the phrase "ping port 80" does not make sense.
5. DNS: the internet's phonebook
People remember names like example.com. Computers need IP addresses. DNS (Domain Name System) translates one into the other.
How a lookup works
When you type a name, your computer does not know the answer, so it asks a recursive resolver, usually run by your internet provider or a public DNS service. The resolver does the legwork:
- It checks its cache. If it looked up that name recently, it answers immediately.
- If not, it asks a root server, which does not know the final answer but points to the servers for the top-level domain (the part after the last dot, such as
.com). - The TLD server points to the authoritative name server for that specific domain.
- The authoritative server gives the real answer, such as the IP address.
- The resolver returns the answer to your computer and caches it.
Caching works through a TTL set on each record by its owner: until it runs out, the answer is reused; after that, the resolver asks again.
Common record types
| Type | Meaning |
|---|---|
| A | Name to an IPv4 address |
| AAAA | Name to an IPv6 address |
| CNAME | One name is an alias for another |
| MX | Where the domain's mail goes |
| NS | Which name servers are responsible for the domain |
| TXT | Free text, used for things like email authentication and domain verification |
Transport
DNS normally uses UDP port 53, since a query and its answer are small. It uses TCP port 53 for larger responses and for zone transfers.
Standard DNS is not encrypted, so someone on the path can see which names you look up. Two encrypted versions exist: DNS over TLS (DoT) on port 853, and DNS over HTTPS (DoH) on port 443.
Try it:
nslookup example.com # Windows, macOS, Linux
dig example.com # macOS, Linux
dig example.com MX # ask for a specific record type
macOS includes dig, nslookup, traceroute and whois. On a Linux system where one is missing, install it: on Debian or Ubuntu sudo apt install bind9-dnsutils traceroute whois, on Fedora sudo dnf install bind-utils traceroute whois. Windows has nslookup and tracert built in; for dig on Windows, use WSL (see Linux Fundamentals).
6. DHCP: getting your network settings automatically
A new device needs an IP address, a mask, a gateway and DNS servers before it can do anything. Typing these into every phone and laptop would be tedious, so DHCP (Dynamic Host Configuration Protocol) hands them out automatically.
The challenge: the device has no IP address yet, so how does it ask? It broadcasts its request to everyone on the local network, and a DHCP server answers. The process has four steps, remembered as DORA:
- Discover: the device broadcasts "Is there a DHCP server out there?"
- Offer: a server replies with an available address and settings.
- Request: the device says "I would like that offer, please."
- Acknowledge: the server confirms, and the device can start using the address.
DHCP runs over UDP, with the server on port 67 and the client on port 68. The first message goes to the broadcast address 255.255.255.255.
The address is leased, not given forever. The device starts trying to renew when about half the lease time has passed. If a device cannot get an address from DHCP, it may assign itself a 169.254.x.x link-local one, which is a sign that DHCP is not working.
A DHCP server typically provides: IP address, subnet mask, the default gateway (the router), DNS servers, and the lease duration.
7. HTTP and HTTPS
HTTP (Hypertext Transfer Protocol) is how browsers and servers exchange web content. It follows a simple pattern: the client sends a request, the server sends a response.
What a request and response look like
A message has a start line, headers, a blank line, and an optional body. HTTP/1.1 messages are plain readable text:
GET /index.html HTTP/1.1
Host: example.com
Accept: text/html
HTTP/1.1 200 OK
Content-Type: text/html
Content-Length: 1256
<html> ... the page ... </html>
- The method says what you want:
GETfetches something,POSTsends data (for example a form), and there are others such asPUTandDELETE. - The status code says how it went. The first digit is the family:
1xxinformation,2xxsuccess,3xxredirect,4xxclient error (404 Not Found),5xxserver error (500). - Headers carry extra information, such as the host name, content type and cookies.
HTTP is stateless: each request stands alone, and the server does not automatically remember you. Websites add memory using cookies, small pieces of data the server asks the browser to send back with each request. That is how a site knows you are still logged in.
Versions in one paragraph
HTTP/1.1 (1997) added connection reuse and the Host header, which lets many websites share one IP address. HTTP/2 (2015) changed the format to binary and allowed many requests in parallel over one connection. HTTP/3 (2022) runs over QUIC, which uses UDP instead of TCP. In all versions the ideas are the same: methods, status codes and headers.
HTTPS
HTTPS is HTTP carried inside TLS (Transport Layer Security). The messages are the same; they are just wrapped in an encrypted channel. It uses port 443 by default, against 80 for plain HTTP.
TLS gives you three things:
- Encryption: others on the path cannot read the data.
- Integrity: others cannot change the data without being detected.
- Authentication: the server proves it is really the site you asked for.
That last one works through certificates. A certificate ties a website's name to its public key, and is signed by a trusted certificate authority (for example Let's Encrypt). Your browser has a list of authorities it trusts. If the certificate does not match the site name or is not trusted, you get a warning.
HTTPS protects against man-in-the-middle attacks, where someone sits between you and the server to read or change traffic. On plain HTTP, anyone on the path, such as someone on the same public Wi-Fi, can read what you send, including passwords.
What HTTPS does not do:
- It does not hide where you are connecting. The server's IP address and the amount of data are still visible to the network.
- It does not tell you the site is honest. A padlock means the connection is encrypted and the certificate matches that domain, not that the site is trustworthy. Criminals can get certificates for their own sites too.
8. Packets: what actually travels
Large data is never sent in one lump. It is split into small pieces, sent separately, and reassembled at the other end. This lets many conversations share a link and lets a lost piece be resent without sending everything again.
Names for the pieces
People say "packet" for everything, and in casual talk that is fine. Precisely, the name depends on the layer:
| Layer | Unit |
|---|---|
| Transport | Segment (TCP) or datagram (UDP) |
| Network | Packet |
| Data link | Frame |
| Physical | Bits |
What is inside
Each piece has a header that says where it came from and where it is going, then the payload, which is the data from the layer above. Headers are the "envelope" part of encapsulation.
Size limits
Each link has a MTU (maximum transmission unit), the biggest packet it can carry in one go. On standard Ethernet it is 1500 bytes. A larger IPv4 packet may be fragmented into smaller pieces, reassembled by the receiver. If any fragment is lost, the whole packet is lost, so fragmentation is avoided where possible.
The journey
A packet travels hop by hop. Each router reads the destination IP address, decides the next hop, subtracts one from the TTL, and forwards it. The IP addresses stay the same along the way, but the MAC addresses change at every hop, because each hop is a new local link with a new frame. (The exception is NAT, covered next.)
Try it:
ping 8.8.8.8 # is a host reachable? (ICMP)
traceroute example.com # macOS, Linux: shows each hop
tracert example.com # Windows
On Windows, ping sends four requests and stops (/n sets the number, /t keeps going until you press Ctrl+C). On macOS and Linux it keeps sending until you press Ctrl+C, unless you add -c 4 to stop after four.
9. Basic LAN concepts
A LAN (local area network) connects devices in a limited area such as a home, office or building. It stands in contrast to a WAN (wide area network), which covers large distances, and the internet is the biggest WAN of all. Today most LANs run on Ethernet (wired) and Wi-Fi (wireless), using TCP/IP.
The devices
- Switch: connects wired devices on the LAN. It works at the data link layer. It learns which MAC address is on which port, and then sends each frame only to the port where its destination is. If it does not know the destination yet, it sends the frame out of every port except the one it came in on. A hub, which is old technology, repeats everything to every port.
- Router: connects different networks and forwards packets between them using IP addresses. Your home router connects your LAN to the internet.
- Access point: provides Wi-Fi. At home it is usually built into the router.
- Modem: connects your line (cable, DSL) to your provider. At home, modem, router, switch and access point are often combined in one box.
A switch works with MAC addresses at layer 2. A router works with IP addresses at layer 3. This is the single most useful distinction in this section.
MAC addresses
A MAC address is a 48-bit hardware address for a network interface, written as six pairs of hexadecimal digits, such as 3C:22:FB:12:34:56. The first half identifies the manufacturer. The address FF:FF:FF:FF:FF:FF is the broadcast address, which means "everyone on this local network".
MACs are meant to be unique and are used only within the local network, not across the internet. They are not fixed forever: many devices can change them, and phones often randomise them on purpose for privacy.
ARP: finding the MAC for an IP
On a LAN a frame needs a MAC address, but applications only know the IP address. ARP (Address Resolution Protocol) bridges that gap. The sender broadcasts "who has 192.168.1.1?", and the owner replies with its MAC. The answer is remembered in an ARP cache. ARP works only within the local network. IPv6 uses a different mechanism (Neighbor Discovery).
ARP has no way of verifying who is answering, which is why attackers can fake ARP replies on a LAN. You will meet this later as ARP spoofing.
The default gateway: how a device decides where to send
When your computer sends a packet it asks one question: is the destination in my own network? (it uses its subnet mask to check)
- Yes: it finds the destination's MAC with ARP and sends the frame directly.
- No: it sends the frame to its default gateway, which is the router's address on the LAN. The router takes it from there.
That is why DHCP gives you a default gateway: without it, your device could talk to neighbours but never to the internet.
NAT: many devices, one public address
Your home devices have private addresses, which cannot be used on the public internet. The router solves this with NAT (network address translation), usually in the form called port address translation. When a device sends traffic out, the router swaps the private source address and port for its own public address and a port it picks, and remembers the pairing in a table. When the reply returns, the router uses the table to send it to the right device.
NAT was invented to save IPv4 addresses. It is not a firewall. Hiding private addresses is a side effect; security depends on what the router's firewall rules actually allow. Network Defence explains what firewalls do and which types exist.
Try it:
ipconfig /all # Windows: IP, mask, gateway, DNS, DHCP server
ip a # Linux
ifconfig # macOS
arp -a # Windows and macOS: see the ARP cache
ip neigh # Linux: the same table (ARP cache)
On Linux, ip is the current tool for both addresses and the ARP table. The older ifconfig and arp commands belong to a separate package called net-tools, which may not be installed.
10. Putting it all together: opening a website
Now you can follow a full journey. You type https://example.com and press Enter.
- Network settings: your device already has an IP address, mask, gateway and DNS server, given by DHCP when it joined the network.
- DNS: your computer asks its resolver for the address of
example.com. The resolver uses its cache or asks root, TLD and authoritative servers, and returns an IP address. - Local or remote? The destination is not in your subnet, so your computer will send traffic to the default gateway. It uses ARP to learn the gateway's MAC address.
- TCP handshake: your computer opens a connection to the server's IP on port 443: SYN, SYN-ACK, ACK. Your end uses a temporary dynamic port.
- TLS handshake: browser and server agree on encryption, and the server proves its identity with a certificate.
- HTTP request: the browser sends
GET /inside the encrypted channel. - Encapsulation: each message is wrapped as a TCP segment, then an IP packet, then a frame.
- Routing: your home router applies NAT and forwards the packet. Router after router reads the destination IP, reduces the TTL, and passes it on. The MAC addresses change at every hop.
- Response: the server sends back
200 OKand the page, which makes the same trip in reverse. - Display: your browser decodes the response and draws the page. If the page needs more files, it makes more requests, many of them over the same connection.
Every concept in this guide shows up in those ten steps. If you can explain each step in your own words, you understand the basics of how the internet works.
Closing
You started with a CPU running instructions and ended with a web page crossing the world. The pattern repeats at every level: split a hard problem into layers, give each layer one job, and let each one wrap what comes from above.
Three habits will serve you well from here:
- When something does not work, ask which layer the problem is at. Cable? Address? Name lookup? Port? Application?
- Keep the order of addressing in your head: port, IP address, MAC address, from the application outward.
- Do not trust slogans. HTTPS is not "safe", NAT is not a firewall, and a port number only tells you what is usually there.
The best next step is to try the commands in this guide on your own network and check that what you see matches what you read here.
Videos to watch alongside
These five videos are by TechTerms and cover the same topics as sections 2 to 7:
- OSI model explained
- IP addresses: IPv4 and IPv6
- TCP/IP model explained
- Web and HTTP protocol tutorial
- DNS: how it works