How the internet works

Trying to understand the internet is overwhelming. The user experience is so abstracted, it’s hard to imagine what’s going on underneath the surface. But, if you’re interested in web development, I’m told it’s pretty important to get a feel for how it all works AND I was given the assignment of writing a blog about it. I’m by no means an expert (read: some of this might be wrong?) — but I’m hoping to provide a simplified mental model that isn’t totally off base. Ready to dig in?

Let’s give it a shot.

You might respond, “Well, you type a URL into your browser, and the browser looks up the address of the URL and sends a message request to that web server. Then the web server sends a response message back, and your browser interprets that message to show you a web page!”

“Hm. So the browser on my computer and the server just like… have a direct line? Aren’t servers totally full of info? How does the message even get to the right part of a server? And how does the response get back to my browser?”

“Great questions. There are lots of different applications that use the internet. Different applications and processes have different port numbers. Port numbers help the device figure out what process should receive a message and what type of message is being sent. When you type an address into a browser, the browser then sends a little envelope of info (called a segment) to the process at a given port number of a server, and asks if it wants to connect. The process at that port number is listening for segments, and when it receives the a segment it shoots back an acknowledgement. When the browser gets the acknowledgement, it knows that your browser and the web page have found each other and they can start sending messages (usually a whole bunch of numbered segments!). There’s lots of cool things in place to make message transfer more reliable. If the browser doesn’t get a response for a certain amount of time after sending a segment, it can send it again! Sometimes only some segments of a message arrive because they were dropped on the journey, or sometimes duplicates arrive because multiple copies were sent. The sequence numbers on the segments help the message recipient figure out what’s missing and throw out duplicates.”

“So basically the browser uses the URL to figure out a port number and that tells your computer where to send a message?”

“That’s part of it, but there’s more. As I said before, the port number helps devices figure out what application should receive and respond to messages. But to get a message from one network device to another, you need something called an IP address. Every time a device joins a network, they get an IP address. When you type a URL into a browser, it converts the URL into an IP address which tells it where to send the message. It figures out this IP address by making a request to a DNS server. DNS servers are a network of servers that store information about IP addresses. After your browser bundles message info into segment with a destination port and determines the IP address at a given URL, it then wraps each segment into a packet with a destination IP address, and uses the IP address to find a router in range that delivers to that address. It ships the packet off to that router, which then uses the IP address to find another router in its range that delivers to that address. The packet goes through a web of routers until it finally gets to the correct IP address. It’s a little like air travel. When I’m flying from Boston, MA to Madison, WI, I have to first get to the Boston airport, then fly from Boston to Detroit, then fly from Detroit to Madison, then make it to my parent’s house. I can’t go straight from my address to my parent’s house — I have to find an airport in between that can get me to my destination. After journeying through a hierarchy of routers, the message can finally get to the correct IP address, and message transfer can take place!”

“Got it! So the message goes from my computer to a bunch of routers and then to a server using IP addresses!”

“Yes, but there’s a little more to it. Packets sent to IP addresses actually need to travel across a physical network as binary data, literally moving across the globe from one physical destination to another. To send this binary data, your computer wraps each little packet into something called an ethernet frame. The ethernet frame consists of a bunch of structured bits that get sent along with a MAC address of the message recipient and the sender. As our message journeys across a network of routers, it’s really moving from physical device to physical device — each device with its own MAC address. (Devices are given unique MAC addresses when they are physically created.) When our ethernet frame is gets to a new device, the packet gets unwrapped, put into a new ethernet frame, and shipped off to another MAC address. The frames and addresses connect the logic of IP addresses to the actual physical network.”

“Okay so ports help identify the process on a device that is listening for data, and IP addresses get the data to the intended destination across networks, and MAC addresses let you send data from one physical destination to another. But there’s still some stuff I don’t get. How does the binary actually get delivered? If the message is just 1s and 0s, how do those 1s and 0s get sent around?”

“That all happens when the bits are converted to radio, light, or electrical signals! It’s a little like morse code — the 1s and 0s are just flashes of light moving through fiberoptic cables, or electricity moving through wires, or radio waves moving through the air!”

“Wait so the internet is just like… flashing lights?”

Me: “I guess that’s one way of putting it! On the user end, you just need to worry about your HTTP message and URL. The URL gets translated into an IP address through DNS servers, and your message gets broken into pieces and wrapped in numbered TCP segments (or UDP datagrams) with their associated port numbers, which get wrapped in IP packets with their associated IP addresses, which get packaged into ethernet frames with their associated MAC addresses, which get sent as light, radio, or electric signals from your device through a network of devices and routers to the destination host. The host verifies that the frames are in tact, then verifies that the packets are in tact, then assembles the various numbered segments, and then finally the assembled data is passed via port number to the process listening on the host.”

Whoa. That got complicated quickly.

In the Internet Protocol Suite Model, our protocol layers are:

Application

  • Data Unit: Message
  • Address: URL

Transport

  • Data Unit: Segment/Datagram
  • Address: Port/Socket

Internet

  • Data Unit: Packet
  • Address: IP Address

Link

  • Data Unit: Frame
  • Address: MAC Address

Why so many layers, you might ask? Simple. They all are used to address different aspects of communication. It’s like what goes on in your brain and body when you try to communicate with a friend. Your frontal lobe tells you the style and tone to use when you’re talking to your friend. Your Broca’s Area helps you structure the words into a sentence. Your cerebellum helps you put your thoughts into words. Your motor cortex tells your vocal tract how to produce the sounds. Your vocal tract makes and shapes the sound waves. And so on. All of these processes are just physical and chemical signals (neurons & sound waves), but they all are responsible for different parts of the communication. They follow different rules. Hence, multiple protocols.

There’s a lot more to the internet than this… but this is your basic overview. Hopefully it helps provide a useful mental model for the structure of the internet!

Thanks for reading.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store