Build the mental model
The Internet isn't one single thing — it's a global network of networks connecting millions of devices.
A device connects to a local network through a router, and that router connects onward to an ISP. ISPs connect to each other, which is how a device on one side of the world can reach a server on the other.
- Device — an endpoint on the network: a computer, phone, or server
- Router — connects devices to a local network and onward
- ISP — the company that connects you to the wider Internet
- IP Address — a device's own address on the network
- Packet — a small piece data is broken into before traveling
Data isn't sent as one giant chunk — it gets broken into packets, sent separately, and reassembled at the destination, so no single transmission hogs the whole network.
This lesson deliberately stays shallow
TCP/IP internals, subnetting, and routing algorithms are genuinely deep, specialized topics on their own. This lesson only builds the mental model: data always travels through real infrastructure, even though it feels instant.
- IP Address
- A device's unique address on the network — similar to a postal address, it tells the network exactly where data should be delivered.
- Packet
- A small piece that data is broken into before traveling across the network — reassembled at the destination using sequencing information.
A REQUEST'S ROUND TRIP
----------------------
YOUR COMPUTER
|
v (request leaves as packets)
ROUTER
|
v
ISP
|
v
INTERNET (many networks in between)
|
v
SERVER
|
v (response comes back the same way)
... ISP -> ROUTER -> YOUR COMPUTER
|
v
RESPONSE ARRIVESConnect it to a real scenario
The code example splits a message string into fixed-size packets, then reassembles them after they arrive out of order — an honest illustration of the packet concept, not real networking machinery.
Splitting
"HELLO FROM THE WEB" is split into four 5-character packets, each carrying a sequence number (seq).
Arriving out of order
Real packets don't always arrive in order, so the example simulates them arriving as 2, 4, 1, 3.
Reassembling
Sorting by seq and joining the pieces back together recovers the exact original message.
Try the working example
function splitIntoPackets(message, packetSize) {
const packets = [];
for (let i = 0; i < message.length; i += packetSize) {
packets.push({
seq: packets.length + 1,
data: message.slice(i, i + packetSize),
});
}
return packets;
}
function reassemblePackets(packets) {
const ordered = [...packets].sort((a, b) => a.seq - b.seq);
return ordered.map((p) => p.data).join("");
}
const message = "HELLO FROM THE WEB";
const packets = splitIntoPackets(message, 5);
console.log("Original message:", message);
console.log("Packets sent:");
for (const p of packets) {
console.log(` packet #${p.seq}: "${p.data}"`);
}
// Simulate real networks: packets don't always arrive in the order sent.
const arrivalOrder = [2, 4, 1, 3];
const shuffled = arrivalOrder.map((seq) => packets.find((p) => p.seq === seq));
console.log(
"Packets arrived out of order:",
shuffled.map((p) => p.seq).join(", ")
);
const rebuilt = reassemblePackets(shuffled);
console.log("Reassembled message:", rebuilt);
console.log("Matches original:", rebuilt === message);Original message: HELLO FROM THE WEB
Packets sent:
packet #1: "HELLO"
packet #2: " FROM"
packet #3: " THE "
packet #4: "WEB"
Packets arrived out of order: 2, 4, 1, 3
Reassembled message: HELLO FROM THE WEB
Matches original: true5-minute try-it
Change packetSize from 5 to 3 and predict how many packets result. Note that you'll also need to update the arrivalOrder array to match the new packet count.
One important caution
Thinking of the Internet as a single network, rather than a collection of thousands of interconnected networks
Not realizing packets can arrive out of order and still be correctly reassembled using sequencing information
MDN Web Docs — How does the Internet work? — How the Web Works