OSI model – when you have two computers in some network (like, say, the internet) communicating with each other, multiple protocols are involved, most of them building off of each other. We organize these protocols into seven “layers”, with each layer serving a specific purpose:
* Layer 1 – physical – how does the computer interpret 1’s and 0’s from electricity or fiber signals?
* Layer 2 – data link – how does the computer know which machine *it is currently connected to* to send a packet to? (Example protocol: ethernet)
* Layer 3 – network – if the computer isn’t connected to the data’s destination, how does it know which machine to send the packet to so that the packet gets closer to its final destination? (Example protocol: IP)
* Layer 4 – transport – once the computer gets the packet, how does it know which process the data is intended for? (Example protocol: TCP)
* Layer 5 – session – maintains connections
* Layer 6 – presentation – ensures the data is in a readable format for whatever application it’s passed to.
* Layer 7 – application – the actual payload, which can have its own protocols based on what application you’re running. (An example is HTTP)
I’ll mention that since layers 5 and 6 don’t have many big example technologies, a lot of places teach the alternate [5-layer internet stack](https://www.educative.io/answers/what-is-the-five-layer-internet-protocol-stack) instead of the 7-layer OSI model.
TCP and IP are the two most common protocols used in the internet today. IP provides routing, pointing data to the right machine, and TCP names which process that data goes to. TCP is common because it also has the excellent benefit of *guaranteed delivery*. This is extremely difficult to write on one’s own, and TCP is a very complex protocol because of this. Though some applications opt to use UDP, which is a faster and simpler protocol, but which doesn’t guarantee delivery so packets are sometimes lost. Most applications that use UDP can handle a few packet drops.
The OSI model is a fiction that gets taught to students, which then everyone proceeds to mostly forget because it’s not quite accurate to the real world
The underlying idea is that you structure stuff in layers, and the upper layers don’t really care what’s going on below.
* Layer 1 is the physical layer. That determines how data is actually physically communicated. And this can be electrical pulses, or pulses of light (fiber), or electromagnetic radiation (wifi), or smoke signals. Nothing above really needs to care.
* Layer 2 is node to node communication — if you hook up a machine to another directly with a cable. Ethernet goes here.
* Layer 3 is networking — how stuff gets along a chain from A to B to C to D. The IP protocol goes here.
* Layer 4 is Transport — where you have the concept of a transferring arbitrary amounts of data from A to B. TCP goes here.
* Layer 5 is session — where you have the concept of a constant connection. TCP is also here.
* Layer 6 is presentation — concerned with formatting, compressing and encrypting data. For instance SSL.
* Layer 7 is application — which is whatever you run on top of all of this, like HTTP.
* Layer 8 is the user — not an actual layer, but something you might see people jokingly refer to.
In practice the layers that get talked about is 1, 2, 3 and 7:
* It’s a bad cable (layer 1)
* There’s two computers with the same MAC, or they’re not plugged into the same switch (layer 2)
* IP address is misconfigured (layer 3)
* Something is wrong with the application itself (layer 7)
Let’s say you want to play a game of chess with someone by mail. First, you’d write something like “I got your last move for Turn #3. Now I move my pawn from h7 to h5.” Then you’d put that piece of paper in an envelope with your opponent’s name and address on it. Then you’d take the envelope outside and put it in a mailbox. The postal worker would take it to a sorting facility, then to your opponent’s house, then your opponent would open it rather than another member of his family, and then he’d move the piece on his copy of the chessboard after reading your letter.
The postal worker is the physical layer, actually moving the data from one computing device to another. The sealed envelope itself represents the networking layer with information like the city, state, and postal code to guide the postman in where it should go. The information about the turn number and acknowledgement are the session layer, letting the person who opens the envelope know where this information fits into the overall series of messages, and whether a lost message needs to be re-sent. The text of the chess move is part of the presentation layer, representing a physical piece with a predetermined code for the locations on the board that needs to be interpreted by the reader. Finally, the piece is actually moved, doing something useful to the human player, which is the application layer.
TCP is represented by acknowledging the prior communication and numbering the present communication, so that if any packet is dropped, it will be noticed and re-transmitted. IP is just a means of transmitting packets to a particular destination, regardless of what their contents are, just like an envelope is in the mail system.
A computer is like a whole city of people and everyone has a job to do and relies on the others doing their job. So to get the internet on your screen, computers need to talk a lot to make sure everyone knows what needs to be done and when they should do it etc. But all that talking is very confusing if everyone is in the same room, so some smart people told everyone to go to a separate room, so those who need to talk to each other can do so without being distracted and confused by all the other things going on in the city.
So for OSI they decided to make 7 rooms but for TCP/IP they said 5 rooms are enough. (If you want to make a boomer OSI joke, say something like “I seem to have layer 8 issues, nothing gets done on my computer”, because the user in front of the screen is sometimes called layer 8)
As I said before it’s about getting the internet to your computer.
So you start with the lowest layer (1), being the actual cable. So all the cable people go to room 1.
Like the car mail gets delivered in.
That cable goes to your router. That connection is layer 2. So all the people who deliver mail only in your neighborhood but not further go to room 2. It could be enough to tell them to bring the mail to house number 7 and they wouldn’t need more to know where to deliver it. (MAC addresses)
Layer 3 is for delivering outside of the neighborhood. Now you need to write down the exact address, with zip code etc, because otherwise the mail service wouldn’t really know where to go with the letter. In room 3 people just talk about where things are and how to get there. They are really good at that. (IP)
In room 4 people start talking about how to deliver the mail. Is it important that you get a letter back once your letters arrived, so you can be sure they all arrived in good condition, or is it enough to just send it and hope for the best? (TCP/UDP)
The 5th room talks about the letter itself. What should we put in there? What language should the letter be written in so the recipient understands it as well? Should we use abbreviations, so we can fit more of what we want to say and show? Should we introduce ourselves first? Maybe we should ask if they can send us their favorite poem back, because we got told by the boss (you) that we need to get poems from the person we send our letters to.
In OSI they split up the 5th room/layer in 3 separate rooms.
Here you can see the names of those rooms (might be helpful to read more about specific layers that caught your interest): https://1.bp.blogspot.com/-brz99Xq77EY/WIi6f-eklDI/AAAAAAAAD_g/V1_zENy22dkofjfoYAyaKvj6Z5gYJxDOACLcB/s1600/tcp-ip-vs-osi.png
So next time you have no internet connection (no letters are arriving), you can take one of the models and use them for troubleshooting. You could start with layer 1 for example and check if the cable is actually plugged in. Then you could try to ping your router to see if that connection works, or open the settings page of the router in your browser. And so on.. (it’s probably the DNS server, if it’s not DHCP.. it’s always one of those two in room 5/7, so you might just start there if you don’t regularly unplug your computer)
If anyone finds mistakes, outdated knowledge or anything alike, let me know please, it’s been some time since I learned about those models. Learned that TCP/IP now has 5 layers while looking for pictures for example.
To get a bit more technical (since the other answers focus on definitions):
Say you want two electronic devices to communicate with each other. (we’ll assume digitally as analogue is another story) How? First you have to figure out the basic physical properties – serially, one bit at a time, or multiple bits at once (in parallel). What voltages are you going to use to represent the ones and zeroes (and is a high voltage a ‘1’ or a ‘0’?) what timings do you use, what rate should you expect the bits to be sent at? All these rules are make up the protocol of the first, physical layer.
How do you know when the data being sent starts, and ends? How do you know whether it’s been accurately transmitted, and how do you request a re-transmission if it wasn’t? What if you have multiple machines? How do you ensure they don’t “talk over” each other? This protocol is the ‘link layer’ defines a single link or a local network. These first layers are not really independent, since the link-layer protocol depends on the nature of the link.
Anyway, all you have at this point is a pipe to get data from A to B on a network. And for some applications that’s good enough (say, talk between different components within a device), but for computer networks you want something more general purpose and powerful. Since, at this level we’re no longer concerned with the details of how the data gets from A to B, we can add a ‘network layer’, a layer of abstraction allowing communication through _different_ local networks, by defining a protocol that puts all data into chunks (packets) that all contain the addresses of the sender, receiver and other information. The example of this would be the Internet Protocol, and IP addresses. This is an address which is independent of the type of network you’re on (as opposed to e.g. a MAC address, which is your address within an Ethernet network and only reachable within that Ethernet network)
Now that you can get data from A to B across a whole set of networks (and routers and whatnot in-between), _that_ data still needs to be wrapped in some form of packets, because you want to be able to have multiple programs talking at the same time, or a single one carrying on multiple ‘conversations’. And if you want to send data that doesn’t fit in a single IP packet, it needs to be broken up into chunks and sent as multiple packets and then reassembled. But not everything needs to do that either, so for this purpose you have the ‘transport layer’ protocols (such as UDP and TCP which both go over IP). In short, TCP gives you (from the program POV) a continuous ‘pipe’ of data, and under the hood it handles breaking that data up into chunks and rebuilding them in the correct order (since you don’t know how stuff is routed at this level, you don’t know that packet 1 will arrive before packet 2), retransmitting ones if necessary, confirming reception, maintaining the connection, and such. It’s like a phone conversation whereas UDP is a simpler protocol that just sends single packets (‘datagrams’) and does not retransmit, concern itself with the order or anything, it’s like sending a postcard. This may seem inferior but it’s useful for things like VoIP, where speed is more important than flawless transmisssion, because a packet’s data may have become irrelevant by the time it’s retransmitted.
The next two layers (Session, Presentation) are rather vaugely defined (and not as commonly used when people talk about this stuff anyway) and it gets fuzzier from here. I’ll skip ahead – the top layer is the application layer. And that’s the data the actual program concerns itself with. Now that it can get its data from A to B, doesn’t need to worry about retransmitting and all the stuff going on, it has its ‘pipe’ (if you’re talking TCP) where it’s talking to the right program on the right computer and all that, all that’s left is for the program to have decided a protocol for how it talks. For instance a TCP packet containing “GET /index.htm HTTP/1.1” (followed by a newline) is the HTTP protocol, with a request to retrieve the page “/index.htm” from a server. (protocols don’t have to be text-based though, many protocols are binary data) Client-server communication typically takes the form of some sort of request and response packets.
Now, there are some things that aren’t so application-specific yet higher level than TCP and UDP. For instance (nowadays) you have encryption through the TLS (also known as SSL) protocol. TLS communicates over TCP and is higher level than that, but it is only a means of getting encrypted application data from A to B, it doesn’t ‘know’ or care what the underlying data is once the encrypted connection is established. So this is session-layer.
As for presentation layer.. as said, an application may send binary data or text data or format that data however it wants. However, there exists _families_ of protocols for some purposes, where there’s a common standard of how data is to be sent, which contains metadata about what the format of the data is, so it can be parsed. This layer (if present) is the ‘presentation layer’, and the point then is that the application only needs to concern itself with checking the content, and not the format, of the data it was sent. But this is all a bit indistinct from the application layer.
So if you’re reading this it’s most likely via some modulated 2.4 GHz microwaves that decode (layer 1, WiFi) to form 802.11b Ethernet packets (layer 2) containing IP packets (3) containing TCP packets (4) containing TLS packets (5) containing an HTTP response (7).
I’ve used them nonstop for 25 years troubleshooting any “network” problem, from simple to complex. The value for me is that it helps break things down in to components that you can troubleshoot individually rather than everything all at once. When you finally narrow down a piece of shit label printer sending double SYN packets that has shut down a critical department, you find the worth. No amount of shotgun fix cable swaps, printer swaps, certificate updates, password rotations, or blaming a developer will get you to the answer. Learn to properly troubleshoot by learning how things work. Good on ya for seeking out the knowledge.
Latest Answers