The internet has been always a black box for users. We just click on buttons, or sending texts without actually think of the journey. However, when you start thinking how a text message is delivered across the world, you find out that there are layers of the internet and each has its own responsibilities to deliver your message.
The most current model to explain internet layer is called “Open Systems Interconnection Model” or OSI Model. It divides the internet into seven layers starting from clicking on a button to zeros and ones in cables.
Let’s talk about introductory definitions of those layers and protocols they have.
Layers
7: Application Layer
Application layer is the only layer that we directly interact with. So, protocols built at level 7 have a format for human-readabe content, let’s call them messages.
Popular protocols on this layer are: HTTP, Websocket, DNS, SMTP (Single Mail Transfer Protocol), FTP (File Transfer Protocol)
HTTP
Defines the format of network requests and responses between services over the internet. It provides a solid and clear structure of communication over the internet. We can have a look these formats:
HTTP Request:
- HTTP version
- Destination URL
- HTTP method
- Headers
- Body (Optional)
HTTP Response:
- HTTP status code
- Headers
- Body (Optional)
DNS
Basically the dictionary of the internet. It translates human-readable domain names to machine readable IP adresses.
For example:
google.com 275 IN A 172.217.17.238
Here we can see that when I visit google.com
, DNS translates this address to 172.217.17.238
for lower layers.
Also, we see that this is a A
type DNS record which is host adress records with IPv4 adresses. If there is a IPv6 host adress, it would use AAAA
type DNS record.
6: Presentation Layer
As if its name, layer 6 is responsible for presentation of data to either layer 7 or layer 4. It is responsible for compression, translation of messages. There is not much going on here. However, layer 6 also handles encryption/decryption of messages for secure transmissions such as HTTPS.
5: Session Layer
Layer 5 is responsible for establishing and closing connections between two devices over the internet. We call these time limited connections as sessions. Some resources argues that TLS/SSL protocols works on this layer however it is not an accepted argument.
4: Transport Layer
Transport layer is responsible for end-to-end communication between two devices. So, it is an important layer for the internet. It divides data into segments and transport to the other devicem, then reassemblies segments into data.
Transport layer has two more important features:
- Flow Control: Ensures that a sender with fast connection does not overwhelm a receiver with slow connection.
- Error Control: Ensures that there is no segment loss during transportation.
There are two integral protocols on this layer:
Transmission Control Protocol (TCP):
TCP has extensive error checking to retransmit lost segments and guarantee delivery and integration of data.
- Requires an established connection
- Retransmits lost data segments
- Able to sequence data segments
- Does not support broadcasting
Used by: HTTPS, SMTP, FTP
User Datagram Protocol (UDP):
UDP skips all error checking and just transports data. It is faster, simpler and more efficient than TCP. So, UDP:
- Does not require any connection
- Does not guarantee data delivery
- Cannot sequence data segments
- Support broadcasting
Mostly used by video conferencing, streaming, VoIP.
3: Network Layer
So we are going deeper. In this layer, we see a new term, packages. Packages are small chunks of segments. Network layer is basically responsible for delivery of packets between two networks. This delivery functionality requires finding the most optimal path from one network to another. So, routers rely on this layer. Network layer has a fundamental protocol which we all know it as IP (Internet Protocol).
Internet Protocol (IP)
Defines the set of rules for package and adress formats for routing and adressing of packages. IP adresses are unique identifiers for a device or a domain that connects to the internet, similar to a regular address.
IP packets consist of:
- Header length
- Data length
- TTL or the number of hops
- Transport protocol
- Headers
IPv4 and IPv6:
IPv4 is the currently used IP adress version and it has format of x.x.x.x
with four decimals, range between 0 and 255, and three dots. Since the number of devices and domains connected to the internet increasing fast, IPv4 shortage emerged.
IPv6 is not fully adopted all over the internet but it is the new solution for IPv4 shortage. It has format y:y:y:y:y:y:y:y
with eight hexadecimal segments, range between 0 and FFFF, and seven colons.
2: Data Link Layer
Similar to network layer but divides packets into frames and deliver them in the same network. So, network layer was responsible for delivering between two networks, but now we are delivering in a single network. This layer is also known as Ethernet Layer.
In this layer, we see MAC adresses, WiFi, ethernet. Also, most switches work on layer 2. Some of them work on layer 3 for virtual LANs currently.
1: Physical Layer
This is the layer of cables under ocean, electricity, zeros and ones.
More on HTTP
HTTPS
HTTPS is secure version of HTTP. It uses TLS to encrypt messages. HTTPS has an important role to prevent man-in-the-middle (MITM) attacks. Also, TLS uses asymmetric encryption so server provides a public key to clients but messages can be decrypted only with private key which is held by server only. This provides authenticity of both server and client.
HTTP/2
HTTP/2 is a new version of usual HTTP/1.1. Besides it is way more performant than HTTP/1.1, it enables a totally new communication called gRPC.
HTTP/3
This is still a draft, and instead of TCP, it uses QUIC. QUIC built on top of UDP and it resolves head-of-line blocking issue in HTTP/2, so it is faster than HTTP/2. HTTP/3 uses TLS 1.3, it acts as HTTPS.