Eli5: What is a protocol stack? How do you interpret a stack like this, for example a TCP/IP protocol stack?


Eli5: What is a protocol stack? How do you interpret a stack like this, for example a TCP/IP protocol stack?

In: 1

Computers do a lot of stuff to exchange data. If a programmer would try to write everything up to the “voltage in a wire” level, they would get stuck in all the details. So, there are several levels of protocols: standards for these operation. Each protocol has libraries that let you implement specific stuff in an easy way, and you don’t have to think about specifics: TCP connection over wifi and over fiber optics cable will look the same for you even though your computer does very different things in these two cases.

Library of each protocol uses lower level protocols. It looks kinda like that:

HTTP: “I need that web page, TCP, connect me to the server.”

TCP: “Okay, establishing connection. IP, send these messages at this address and hand me the responses, I’ll check if the server is available.”

IP: “This address… My network map says that it’s this way. MAC, send this message to that router nearby, it will pass it further.”

MAC: “Sending message… the router is connected via this cable. Ethernet, do your electric stuff with this port, here’s the packet.”

Ethernet: “10001010111101010010110101101011”

A protocol stack is a set of protocols (agreed upon ways of communicating) that depend on the ones they build upon.

For example, HTTP is a protocol to request webpages from a server, but it doesn’t know about servers or how to get data from them. So it depends on TCP to get that data from servers, but TCP doesn’t know how to set up a connection over the internet, so it depends on IP to handle that. IP can get data, but it cannot guarantee data is all from the same network connection, so it depends on Ethernet to take care of that. But Ethernet doesn’t know which how to ensure no other data gets in the way, so it depends on MAC to handle that.

I might have some details wrong, but the general idea is the same; the stack of HTTP/TCP/IP/Ethernet/MAC helps distribute different tasks in such a way that the higher layers (like HTTP) can make assumptions on the data they need to handle.

On the other side a computer and network handle the same stack in opposite order. So when I request a website, it goes down the stack from HTTP all the way to the MAC (and lower), and all the way up to HTTP on the server/network side, then the HTTP request is handled and a response formatted, this goes down from HTTP on the server side, through the network back to my machine and up to HTTP where the browser can then render the website for me.

If you want to send data from one place to another, you need to tell the other end that the data is for them, what they’re receiving and what to do with it once they have it all. That’s protocol, in a nutshell.

Think of it like snail-mailing a letter (I’m going to keep this as simple as I can). The data you want to send is the letter you’ve written, now you need to get it to Grandma’s house in Rustwater, Kansas. You put Grandma’s address on an envelope, your return address in the corner, slap a stamp on it, stick your letter in the envelope and drop it in the mailbox. The envelope and everything on it is the protocol for the letter you’ve sent. It tells the postal service where the letter is from, where it’s going, and the maximum size of the letter from the number of stamps you put on it.

That letter now goes to the post office. The post office looks at the your Grandma’s address, checks the stamp to make sure it’s the right amount, and puts the envelope into a box marked “Kansas” and off it goes to the airport. That box is the protocol for this part of the trip, and it’s “stacked” on top of the protocol that was already present, the envelope you addressed. If the box has to make multiple stops, it’ll probably end up in *another* box, which is another layer of protocol “stacked” on top of the previous one.

So now the box of Kansas mail arrives at the distribution center in Kansas, and everything is unpacked, revealing the original envelope and your Grandma’s address. Your Grandma’s address tells them which post office to transport your letter to, thanks to the Zip Code. That post office looks at the street address and gives the letter to the mail carrier for delivery to your Grandma. It shows up at your Grandma’s house, she looks at the address and verifies that, yes, the letter is for her. She then looks at the return address and sees that the letter is from you and she shouldn’t throw it out or send it back. She then removes the letter from the envelope and reads the letter.

That’s what a protocol stack is and how it works, broken down Barney-style. You (well, your software) gives the data you’re trying to send a source and destination address, tell them how much data is being moved, and any special handling instructions (like writing “fragile” or “do not bend” on an envelope or box). Once you pass it off to the network, it slaps it own protocol on top of yours that tells the next node in the network where your data is headed and how to get it there (Next Day Air, Ground, Certified, Insured, etc.). Each node gets the data, strips off the top layer of protocol and preplaces it with their own (takes out of one box, puts in another) and passes it to the next node, until it comes to the node that services your destination address. That node sends it through the various routers that get it to your destination (Zip Code, mail carrier, etc.), your destination strips off that layer of protocol and looks at your original to see if it’s really for it, and see if its from an address that hasn’t been blocked or designated as SPAM, then strips off the next layer of protocol and sends it to whatever application the data is meant for.

It’s a good deal more complicated than that, but that should give you an idea of what it is and how it works.

Imagine you’re an English speaker, and you’re attending a Japanese medical conference that’s giving a presentation on vaccines that affect the Covid-19 spike protein. To understand the presentation, you’d need to understand:

1. What vaccines work, and how they can be based on spike proteins
2. What spike proteins are, and how they affect virus transmissibility
3. What viruses are, and how they are a danger to our immune system
4. How the human immune system works
5. The Japanese language

Each one of those layers is a different protocol, requiring a different knowledge base. And they all build on top of the others; that’s the stack.

TCP/IP is is similar. It’s part of a protocol stack that’s known as the [OSI model](https://en.wikipedia.org/wiki/OSI_model). As /u/Verence17 explained, each layer calls the layer below it in turn.