
Reprint | Learn Algorithms in Five Minutes
Introduction
Computer networks are a fundamental course, but what teachers teach only serves as a starting point. However, for those who need to self-study, it is undoubtedly more challenging. The road ahead is long~~
Computer networks are inherently dull, and the article contains a lot of content. I recommend readers to patiently read through this article, hoping that everyone can gain something from it. First, let’s outline the general structure of this article.

Prerequisites
“Computer Networks” by Xie Xiren is a textbook chosen by many universities. The first chapter is an overview, discussing the development of computer networks, which can be considered common knowledge that everyone must understand. Here, I will summarize and generalize this as preparatory knowledge for studying computer networks.
A Brief History of the Internet
- Phase 1: 1950s, research on data communication technology and network theory fundamentals
- Phase 2: 1960s, ARPANET and packet switching technology
- Phase 3: Mid-1970s, standardization of network architecture and network protocols
- Phase 4: 1990s, development of the Internet, high-speed networks, wireless networks, mobile Internet, and network security technologies
Development of the Internet
The development of computer networks has mainly gone through the following seven stages.
Batch Processing: In order to allow more people to use computers, batch processing systems emerged. Batch processing refers to the pre-loading of user programs and data onto tapes or cards, which the computer reads in a certain order.

-
Time-Sharing Systems: After batch processing systems, time-sharing systems emerged. This refers to multiple terminals being connected to a computer simultaneously, allowing multiple users to use the computer at the same time.

-
Computer Communication Technology: In time-sharing systems, we see the connection between terminals and computers, but this does not mean that computers are interconnected. With the proliferation of computers, the ease of data exchange between computers has become increasingly important. Initially, the data exchange process between two hosts was quite cumbersome, which led to the emergence of computer communication technology (where computers are connected by communication lines). People can easily read data from another computer, greatly shortening the time to transmit data.
-
The Emergence of Computer Networks: In the 1970s, experiments began on computer networks based on packet switching technology, and research was initiated on technologies for intercommunication between different vendors’ computers. By the 1980s, a network capable of interconnecting various computers emerged. Network communication technology entered a fast lane of development.
-
The Popularization of the Internet: Entering the 1990s, with the decline in computer prices and the enhancement of performance, various applications began to emerge, leading to an increasing degree of computer popularization. In response to this trend, manufacturers not only had to ensure the interoperability of their products but also worked hard to ensure that their network technologies were continuously compatible with Internet technologies (TCP/IP).
-
The Internet Era: With the popularization of the Internet, people have become increasingly reliant on it. Life, study, and work all depend on network information; the era of the Internet of Everything has long arrived.
-
The Era of Network Security: The Internet has brought disruptive changes to the world, providing great convenience to people’s daily lives. The Internet presents a highly convenient information network environment to modern people, becoming as essential a resource for countries as water, electricity, and gas. With the Internet of Everything, network security is undoubtedly the most important part of national security. In the early days of Internet popularization, people focused more on pure connectivity, emphasizing unrestricted connections. But now, people are no longer satisfied with “pure connectivity” but are more in pursuit of “secure connectivity.”
Performance Metrics of Networks
-
Bit: A bit is the unit of data volume in computers, and it is also the unit of information quantity used in information theory. The English word bit comes from binary digit, meaning a “binary number.” The rate in network technology refers to the speed at which hosts connected to a computer network transmit data over a digital channel, also known as data rate or bit rate.
-
Bandwidth: In computer networks, bandwidth is used to indicate the capacity of the communication line to transmit data, so network bandwidth indicates the “highest data rate” that can be transmitted from one point in the network to another in a unit of time. The unit of bandwidth in this sense is bits per second.
-
Throughput: Throughput represents the amount of data that passes through a network (or channel, interface) in a unit of time, indicating the current data transmission capacity of the network.
-
Latency:
- 1. Transmission Delay: Refers to the time required for a host or router to send a data frame, which is the time from the first bit of the data frame being sent to the last bit of that frame being sent.
- 2. Propagation Delay: Refers to the time required for electromagnetic waves to propagate a certain distance in the channel.
-
Delay-Bandwidth Product: The delay-bandwidth product indicates the number of bits that can be accommodated in a link, so the delay-bandwidth product of a link is also known as the link length in bits.
-
Round-Trip Time (RTT): Round-trip time (RTT) represents the total time from when the sender starts sending data until the sender receives confirmation from the receiver (the receiver immediately sends confirmation after receiving data). Round-trip time generally includes various delays of packets in the network.
-
Utilization: Utilization can be divided into channel utilization and network utilization. Channel utilization indicates what percentage of time a certain channel is utilized (data is passing through). The utilization of a completely idle channel is zero. Network utilization is the weighted average of the channel utilization across the entire network. Channel utilization is not always better when it is higher, because according to queuing theory, as the utilization of a channel increases, the delay caused by that channel will also increase rapidly. Excessively high utilization of a channel or network can result in significant delays.
Essential Knowledge You Should Know
Classification of Computer Networks
Classified by geographical coverage, computer networks can be divided into three parts:
- Local Area Network (LAN): Common networks in offices, dormitories, or internet cafes are local area networks, typically within a few meters to 10 km. Their characteristics include narrow connection range, few users, easy configuration, and high connection speed.
- Metropolitan Area Network (MAN): Used to connect the local area networks of enterprises, agencies, or schools within a city or region, enabling resource sharing within the area.
- Wide Area Network (WAN): Also known as remote networks, WANs interconnect LANs or MANs in different cities. Due to the large distances, information attenuation is significant, so this type of network generally requires rented dedicated lines and connects through special protocols to form a mesh structure. Because WANs connect many users, the connection speed for each user is generally lower.
Topology of Computer Networks
-
Bus Topology
:
-
Advantages: Low cost, easy to expand, high line utilization;
Disadvantages: Low reliability, difficult maintenance, low transmission efficiency.

-
Ring Topology
:
- Advantages: Token control, no line competition, strong real-time performance, easy transmission control;
- Disadvantages: Difficult maintenance, low reliability

- Star Topology
- Advantages: High reliability, easy management, easy to expand, high transmission efficiency.
- Disadvantages: Low line utilization, the central node requires high reliability and redundancy.
What Types of Computers Are There?
There are three different layered models of computer networks:
-
OSI Seven-Layer Model

-
Five-Layer Structure Model

- TCP/IP Layered Structure Model

The TCP/IP protocol is the protocol followed by the current Internet. It is not simply composed of TCP or IP, but consists of protocols from various layers, forming what we commonly refer to as the TCP/IP protocol stack. However, for better understanding, the subsequent articles will also be written according to the five-layer protocol.
Physical Layer
Here is a suggestion: when studying computer networks, one should not study each network protocol in isolation but should understand its reasons for existence and its role in the entire computer network.
Digital Signals and Analog Signals
Their role is to shield the differences between different transmission media and communication methods. We all know that there are essentially two types of signals in nature: one is the digital signal, and the other is the analog signal. So what is an analog signal? What is a digital signal?
Simply put, an analog signal is a continuously varying physical quantity. The characteristic of an analog signal is that its amplitude is continuous (the continuity means that within a certain range of values, it can take infinitely many values). The waveform of an analog signal is also continuous over time, thus it is also a continuous signal. Sampling continuous signals will yield sampled signals, but abstract signals are discrete (talking about signals leads us back to the topic of signal systems; it seems that the makeup exam has had an impact on me). On the other hand, digital signals differ from analog signals in that they are discrete in the time domain, and they have two different states of physical quantities represented by “0” and “1.” This is similar to a light switch, which also has two different states.
Of course, digital signals and analog signals can be converted into each other. Analog signals are usually quantized and converted into digital signals using PCM (Pulse Code Modulation) methods, which correspond different ranges of analog signals to different binary values. Generally, digital signals are obtained from analog signals through carrier phase modulation.
Transmission Media of the Physical Layer
We all know that the media for transmitting data at the physical layer vary, and the device working at the physical layer is a hub. However, they can be broadly classified into two categories:
- Guided Transmission Media: Guided transmission media can be further categorized, such as coaxial cables, optical fibers, and twisted pairs, where twisted pairs can be further subdivided based on whether they are shielded.
- Unguided Transmission Media: Unguided transmission media refer to the propagation of radio waves in space, where different frequency bands can transmit different signals.
Channels
Speaking of channels, the previous basics mentioned channel utilization, but a more detailed introduction to channels was not provided. Let’s take a closer look at them. According to the transmission media, channels can be divided into three categories:
- Wired Channels: Wired channels use wires as the transmission medium, and signals are transmitted along the wires. The energy of the signals is concentrated near the wires, so the transmission efficiency is high, but deployment is not flexible enough. This type of channel uses transmission media such as overhead lines for transmitting electrical signals, telephone lines, twisted pairs, symmetrical cables, and coaxial cables, as well as optical fibers for transmitting modulated light pulses.
- Wireless Channels: Wireless channels mainly include radio channels that radiate radio waves and underwater channels that propagate sound waves. Radio signals are broadcast into free space by the antenna of the transmitter. Different frequency bands of radio waves have different propagation methods.
- Storage Channels: In a sense, storage media such as tapes, disks, and optical discs can also be considered as communication channels. The process of writing data to storage media is equivalent to the process of a transmitter sending signals to a channel, while the process of reading data from storage media is equivalent to a receiver receiving signals from the channel.
Channels are the means of transmitting information, and channel capacity describes the maximum capacity of a channel to transmit information without error, which can be used to measure the quality of a channel.
Another important parameter regarding channels is the signal-to-noise ratio. The greater the signal-to-noise ratio, the larger the channel capacity. Here, I will provide the famous Shannon formula:

Where C is the channel capacity, B is the bandwidth, and S/N is the signal-to-noise ratio.
Channel Multiplexing
We know that when no data is being transmitted, the channel is very idle. However, during times of high data requests on the network, such as during recent sales events, the speed of information transmission can be obstructed. So what is channel multiplexing? Multiplexing means reusing. Channel multiplexing can be divided into the following aspects:
- Time Division Multiplexing (TDM): Time division multiplexing means dividing the entire channel into different time slots. When using time division multiplexing, all users occupy the same frequency bandwidth at different times (time is divided, not frequency).
- Frequency Division Multiplexing (FDM): Frequency division multiplexing means dividing signals into different frequencies. When frequency division multiplexing technology is used, all users occupy different bandwidth resources at the same time.
- Statistical Time Division Multiplexing: The so-called statistical time division multiplexing system can also be referred to as an asynchronous time division multiplexing system. It has a buffer-like mechanism that only forwards data when a certain amount of data arrives, greatly improving channel utilization.

Data Link Layer
Ethernet Frame

The data link layer receives IP datagrams from the network layer and encapsulates them so that IP datagrams can be transmitted at the data link layer. The encapsulated IP datagram is called an Ethernet frame, also known as a MAC frame. A MAC frame consists of the following important parts:
- Destination MAC Address: The destination address of the MAC frame occupies 6 bytes, marking the address of the target host.
- Source MAC Address: Like the destination address, the source address also occupies 6 bytes, marking the address of the source host.
- Type: The type occupies 2 bytes, recording the protocol used by the upper layer, with 0X0800 indicating the IP protocol.
- Data Section: The data section naturally comes from the upper layer’s IP datagram.
- FCS: FCS occupies 4 bytes and is used for error detection. If a MAC frame encounters an error, it cannot be sent to the destination host.
Error Detection
Why is error detection necessary?
Real communication links are not ideal. This means that bits may encounter errors during transmission: 1 may turn into 0, and 0 may turn into 1, which is called a bit error. The ratio of erroneous bits to the total number of bits transmitted over a period is called the Bit Error Rate (BER). The Bit Error Rate is closely related to the signal-to-noise ratio, and it is impossible to reduce the Bit Error Rate to zero in actual communication. Therefore, to ensure the reliability of data transmission, various error detection measures must be adopted in the transmission of data over computer networks.
Errors will inevitably occur during the propagation of MAC frames. As mentioned earlier in the Ethernet frame section, based on the FCS, we can determine whether this MAC frame encountered an error or was lost during transmission.
When we talk about the transport layer, we will also mention error detection. So what is the difference between the two? In summary, it can be encapsulated in one sentence:
- The purpose of error detection at the data link layer is to achieve “no bit errors.”
- The purpose of error detection at the transport layer is to achieve “no transmission errors,” that is, to compensate for frame loss, frame duplication, and frame out-of-order.
The main methods for error detection are parity check (PCC) and cyclic redundancy check (CRC). PCC is very simple and is not the focus of this article, so I will mainly discuss CRC cyclic redundancy check.
Cyclic redundancy check is a method that generates a fixed-length check code based on the data being transmitted or stored, mainly used to detect or verify errors that may occur during data transmission or storage. The generated number is calculated before transmission or storage and attached to the data, and then the receiving end performs verification to determine whether the data has changed.
Through CRC, we can calculate the FCS redundancy check code, which is located at the end of the MAC frame. Through the FCS, we can determine whether this MAC frame was sent with errors.
Adapters
Speaking of adapters, one can easily relate it to the adapters in our daily lives. For example, when charging a phone, we need a power adapter, which serves merely as a converter or carrier for energy transfer. In fact, the adapters in computers function similarly. Understanding this with the following diagram:

We all know that data is transmitted serially in external media, while computers process internal instructions in parallel. How to convert serially transmitted data into parallel transmission? This is where adapters come into play. Adapters act as a bridge, allowing for easy conversion of data transmission methods.
CAM Table
We all know that a switch is a multi-port bridge that forwards data using MAC addresses at the data link layer. Switches actually store a table called the CAM table. This table records the MAC addresses of hosts and their corresponding interfaces. Take a look at the diagram below:

There are three hosts A, B, and C connected to the switch. Initially, the CAM does not store any information.
One day, host A (source MAC) wants to send a message to host B (destination MAC). At this point, the switch will check its CAM table for host A’s information. Seeing that there is no information for A, the switch writes A’s information into its CAM table. Now the switch’s CAM table looks like this:

At this point, the CAM table has stored host A’s information, but host A wants to send a message to host B. What should we do? First, the switch checks its CAM table to see if B’s information exists. If it exists, it directly forwards the message to B. If it does not exist, what should be done? After some hesitation, the switch comes up with an idea: it broadcasts the message from host A to all the hosts connected to it. Host C also receives this message, but upon checking the destination address, it finds that it is not meant for itself, so it discards the message. Host B receives the message and checks the recipient (destination address), finding that it is indeed for itself, so it accepts the message. After that, the switch updates its CAM table, adding a new entry:

In this way, the CAM table now stores the information for both host A and host B. The next time host A wants to send a message to host B, the switch does not need to broadcast.
CSMA/CD Protocol
As of now, the use of CSMA/CD is quite rare, and it is used in the following two places:
- Used in wired networks
- Applied in 10M/100M half-duplex wired networks
The networks using the CSMA/CD protocol have the following three characteristics:
- The network is a bus structure, where all computers are connected to the same bus, and only one computer is allowed to send (or receive) messages at the same time, which is half-duplex communication.
- Carrier Sensing: Before and during transmission, continuous monitoring of the channel is required; messages can only be sent when the channel is idle.
- Collision Detection: The host continuously checks the channel before and during message transmission. If two hosts send messages simultaneously, the transmission is immediately halted. A random wait time is then initiated before attempting to send the message again, which is known as the backoff algorithm.
Here are the characteristics of the backoff algorithm:
- Non-persistent CSMA: If the line is busy, wait for a period before listening again; if idle, send immediately; this reduces conflicts but lowers channel utilization.
- 1-persistent CSMA: If the line is busy, continue listening; if idle, send immediately; this increases channel utilization but raises conflict.
- p-persistent CSMA: If the line is busy, continue listening; if idle, send with a probability of p, while the probability of 1-p is to continue listening (p is a specified probability value).
Network Layer
IP Protocol
Overview of IP
The IP protocol corresponds to IP addresses. So, what is an IP address?
According to Wikipedia:
❝
An IP address (Internet Protocol Address) is assigned to a device when it connects to a network, serving as an identifier. Through the IP address, devices can communicate with each other; without it, we would not know which device is the sender and which is the receiver. IP addresses have two main functions: identifying devices or networks and addressing (location addressing).
❞
The above text essentially explains two points, summarized as follows:
- The IP address is used to mark the address of a host; without an IP address, the host cannot be identified (marks the host).
- Because it uniquely marks the host, it can be used to locate the host within the network (addressing).
Now think about what we mentioned earlier regarding MAC addresses. A MAC address is the identity symbol of a host. Once a host leaves the factory, its MAC address is uniquely determined and cannot be changed (of course, it can be modified through software, but it must ensure that no two hosts have the same MAC address within the same local area network).
So, why do we need an IP address if we already have a MAC address? Or why do we need a MAC address if we already have an IP address?
This is actually a classic question, and there are many answers online. Here are two articles I recommend:
- Why do we need a MAC address if we have an IP address?
- Why do we need an IP address if we have a MAC address?
After reading the above two articles, I summarize the reasons as follows:
- Historical Reasons: Ethernet was born before the Internet, and MAC addresses were already in use before IP addresses. The combined use of both is to avoid affecting existing protocols.
- Layered Implementation: After layering the network protocol, the implementation of the data link layer does not need to consider the forwarding of data, and the implementation of the network layer does not need to consider the influence of the data link layer.
- Division of Labor: IP addresses can change as hosts connect to different networks, while MAC addresses generally do not change. Thus, we can use IP addresses for addressing, and when the datagram and the destination host are in the same network, the MAC address is used for data delivery.
IP Datagram
The appearance of IP data is as follows:

Several important aspects need to be explained:
- Version Number: Occupies 4 bits, indicating the version of the IP protocol used by this IP datagram. The main version used in the Internet is IP version 4 from the TCP/IP protocol suite.
- Header Length: Occupies 4 bits. This field indicates the length of the entire header (including options), measured in units of 32-bit words. The receiving end can use this field to calculate where the header ends and where to start reading data. The value of this field for a standard IP datagram (without any options) is 5 (i.e., a length of 20 bytes).
- Type of Service: Occupies 8 bits, used to specify the handling of this datagram.
- Time to Live (TTL): Occupies 8 bits, specifying the maximum time the datagram can be transmitted in the network. In practical applications, the TTL field is set to the maximum number of routers the datagram can pass through. The initial value of TTL is set by the source host (usually 32, 64, 128, or 256), and once it passes through a router that processes it, its value is decremented by 1. When this field reaches 0, the datagram is discarded and an ICMP message is sent to the source host, thus preventing the datagram from being transmitted endlessly in a loop.
- Upper Layer Protocol Identifier: Occupies 8 bits, as the IP protocol can carry various upper-layer protocols; the destination end can use the protocol identifier to send the received IP datagram to the upper-layer protocols such as TCP or UDP for processing.
For a relatively detailed article on IP datagrams, you can refer to this article: Detailed Explanation of IP Datagram Format
Subnet Mask and IP Address
Earlier, when discussing the composition of IP addresses, we mentioned network numbers. Common IP addresses consist of a network address and a host address. So what is a network number? The network number is the name of the network where the computer currently resides, which consists of many hosts. How to calculate the network number? This is where the subnet mask comes into play.
Usually, the IP address and subnet mask of a computer appear in pairs. By comparing the subnet mask with the IP address, one can determine the host number and network number. For convenience of representation, the subnet mask is typically represented with consecutive 1’s in the front and consecutive 0’s in the back, without alternating 0’s and 1’s.
See the example below.

Now that we know the IP address and subnet mask of host A, we convert them into binary form. By comparing the binary representation, the parts of the subnet mask with 1’s correspond to the network number of the IP address, while the parts with 0’s correspond to the host number. The following diagram illustrates this clearly:

ICMP Protocol
We know that the IP protocol is an unreliable transport protocol, and the TCP protocol is responsible for reliable transmission in the network, which will be discussed later in the transport layer. So how does the network layer handle cases where messages do not arrive? This is where the ICMP protocol comes into play. What is the ICMP protocol? ICMP stands for Internet Control Message Protocol.
Its role is to more effectively forward IP datagrams as part of the data in the IP datagram. It can be divided into ICMP error messages and ICMP query messages. Error messages are used to report errors simply; how to handle errors is the responsibility of higher-layer protocols. Additionally, error messages are always sent to the original data source (this is because the only usable fields in ICMP data packets are the source IP and destination IP), while query messages always appear in pairs.
ARP Protocol
Earlier we mentioned that IP addresses are used for addressing, and when the destination address and datagram are in the same network, MAC addresses are used for delivering datagrams. Now there is a problem: when host A wants to send a message to host B, the message has been forwarded through a series of steps, and finally, host A has found host B’s IP address. However, we know that data transmission at the link layer requires MAC addresses, and knowing only host B’s IP address is insufficient for communication. See the diagram below:

At this point, the ARP protocol comes into play. ARP stands for Address Resolution Protocol, and its basic function is to query the MAC address of the target device through its IP address to ensure smooth communication. It is an indispensable protocol in IPv4’s network layer.
Just as switches work at the data link layer, routers operate at the network layer. Switches have CAM tables, and routers have routing tables as well.
Now, when a router wants to send a message to host B, it must know host B’s MAC address to communicate. At this point, the router will send an ARP request, which is broadcasted. Every host connected to the router will receive this message. However, only host B checks its IP address and finds it matching the request. Thus, host B sends an ARP response back to the router, providing its MAC address. The following diagram illustrates this:

Each time a router sends an ARP request, it adds a new entry that records the MAC address corresponding to the IP address. This way, when the router sends a message to that host again, it does not need to broadcast. Of course, just like the data in the CAM table has a lifespan, data in the routing table also has a lifespan. Imagine if data persisted indefinitely, the router would need to use a lot of storage space to cache outdated data.
Interior Gateway Protocol
The main routing selection protocols on the Internet are RIP and OSPF. Below are detailed introductions to these two protocols.
First, let’s introduce the RIP protocol:
- Routing Information Protocol (RIP) is the first widely used protocol among Interior Gateway Protocols (IGP). RIP is a distributed distance-vector routing protocol and is the standard protocol of the Internet. Its main advantage is its simplicity and low overhead.
- Basic Algorithm: The vector distance algorithm (V-D algorithm) works as follows: gateways periodically broadcast path refresh messages, mainly consisting of several (V, D) pairs; the V in the (V, D) pair indicates the reachable destination (gateway or host), and D indicates the distance to that destination, measured by the number of hops. Other gateways receive the (V, D) messages from a certain gateway and refresh their routing tables according to the shortest path principle.
- It is only suitable for small networks (the limit is 15 hops). If the network is too large, when a fault occurs, it may take a long time for this information to reach all routers.
Next, let’s discuss OSPF:
- Basic Definition: OSPF (Open Shortest Path First) is an Interior Gateway Protocol (IGP) used for routing decisions within a single autonomous system (AS).
- Basic Algorithm: Dijkstra’s algorithm. It mainly establishes neighbor relationships by sending HELLO packets to neighbors and selecting DR, etc.
Reference article: Comparison of RIP and OSPF in Computer Networking Principles
NAT Protocol
NAT technology is quite simple. So what is the role of NAT?
NAT (Network Address Translation) was proposed in 1994. When some hosts in a private network have already been assigned local IP addresses (which are only used within that private network), but now want to communicate with hosts on the Internet (without the need for encryption), NAT methods can be used.
This method requires the installation of NAT software on the router connecting the private network to the Internet. A router with NAT software is called a NAT Router, and it must have at least one valid external global IP address. This way, all hosts using local addresses must convert their local addresses to global IP addresses on the NAT router to connect to the Internet. Additionally, this method of using a small number of public IP addresses to represent a larger number of private IP addresses helps to alleviate the exhaustion of available IP address space.
In simple terms, NAT technology is a protocol for enabling communication between a local area network and the Internet. NAT can be divided into three different types:
- Static NAT: Static NAT is the simplest and easiest to implement, where each host in the internal network is permanently mapped to a certain valid address in the external network. Static NAT is used when an internal host must be accessed by a fixed external address.
- Dynamic NAT (Pooled NAT): Dynamic NAT defines a series of valid addresses (address pool) in the external network and maps them to the internal network using dynamic allocation. The process of dynamic NAT is as follows: when an internal host needs to access the external network, it takes an available address from the public IP address pool for use. After communication is complete, the public IP address is released back to the address pool. The public IP address cannot be reassigned to another internal host while it is allocated to an internal host for communication.
- Network Address Port Translation (NAPT): NAPT maps multiple internal addresses to different ports on one external network IP address. NAPT allows multiple internal addresses to be mapped to one valid public address, but with different protocol port numbers corresponding to different internal addresses, i.e., the conversion between and .
Reference article: NAT: Network Address Translation in Computer Networking
IPv6 Protocol
The IP addresses we mentioned earlier are IPv4. So why do we need IPv6 when we already have IPv4? The reason is that back in the last century, people anticipated the day when IPv4 addresses would run out, and thus began the development of IPv6.
IPv6 (IP version 6) was standardized to fundamentally address the exhaustion of IPv4 addresses. IPv4 addresses are 4 bytes long, i.e., 32 bits. In contrast, IPv6 addresses are four times longer at 128 bits, typically written as 8 groups of 16 bits. It can be seen that IPv6 addresses are practically inexhaustible. So why don’t we switch all IPv4 addresses to IPv6 now?
Switching from IPv4 to IPv6 is extremely time-consuming, as it requires resetting the IP addresses of all hosts and routers in the network. When the Internet becomes widely popular, replacing all IP addresses will be an even more daunting task.
In existing networks, both IPv4 and IPv6 coexist. So how do they communicate? There are two technologies: dual-stack and tunneling technology, which will be introduced below:
- Dual-Stack: This involves changing the header of the IP address, where some information from the IPv6 header is lost during the conversion process, and this loss is unavoidable.
- Tunneling Technology: What is tunneling technology? It can be understood literally. Below is a diagram to help everyone understand. Tunneling technology essentially means that data is encapsulated and unencapsulated in a different way during transmission. For example, when data enters the IPv4 network from the IPv6 network, the IPv6 data packet is encapsulated within the IPv4 data packet.

Transport Layer
Stop-and-Wait Protocol
What is the stop-and-wait protocol? You may understand it better after looking at the diagram below.

The stop-and-wait protocol can be composed of the following three parts:
- No Error Scenario: Just like the diagram above, to ensure no errors, host A must continue sending messages to host B until it receives a reply from host B.
- Error Occurrence: If an error occurs, for example, if host A does not receive a reply from host B, there is a mechanism that causes host A to resend the message to host B. This involves choosing a retransmission time, which should not be less than RTT (the time it takes for host A to send a message to host B and for host B to send a message back to host A).
- Confirmation Loss and Confirmation Delay: For confirmation delays and losses, see the diagram below, which may help you understand.

During transmission, data may be lost or delayed. For lost data, retransmission occurs; for delayed data, no action is taken. Since we are discussing the stop-and-wait protocol, I must also mention the ARQ protocol. What is the ARQ protocol?
The ARQ protocol allows the sender not to wait for confirmation of the previous message. It can send multiple packets at once, which increases the utilization of the channel and allows for a sufficient amount of data to be transmitted at a given time.
UDP
UDP protocol is relatively simple compared to TCP protocol, and the focus of the transport layer is naturally on TCP protocol. Below is a brief explanation of UDP protocol.
UDP has the following characteristics:
- Connectionless protocol that performs unreliable transmission
- Datagram-oriented
- No congestion control
- Small header overhead for UDP datagrams
- Supports one-to-one, one-to-many, many-to-one, and many-to-many data transmission
TCP
Overview of TCP
TCP is another protocol of the transport layer, and it has the following characteristics:
- TCP is a connection-oriented transport layer protocol
- Provides reliable delivery
- Uses full-duplex communication
- Byte stream-oriented
TCP Datagram
Please refer to the image below (image source from the internet).

Here, I will explain some fields of the datagram:
- Source Port: The port number of the sending host
- Destination Port: The port number of the receiving host
- Sequence Number: Every byte in the byte stream transmitted in a TCP connection is numbered sequentially. The starting sequence number must be set when the connection is established. The value of the sequence number field in the TCP datagram header indicates the sequence number of the first byte of data being sent in this segment.
- Acknowledgment Number: This indicates the expected sequence number of the first data byte of the next segment from the other party. If the acknowledgment number is N, it indicates that all data up to sequence number N-1 has been correctly received.
- Data Offset: This indicates how far the data in the TCP segment starts from the beginning of the TCP segment.
- Window: The window field specifies the amount of data the other party is allowed to send. The window value often changes dynamically. The window refers to the receiving window of the party sending this segment (not its own sending window).
- Checksum: The checksum field includes both the header and the data. When calculating the checksum, a 12-byte pseudo-header (like UDP) is added to the front of the TCP segment.
- ACK: The acknowledgment number field is only valid when ACK=1. When ACK=0, the acknowledgment number is invalid. TCP stipulates that all transmitted segments after the connection is established must set ACK to 1.
- PUSH: When two application processes are interacting, sometimes the application process on one end wants to receive the other side’s response immediately after typing a command, rather than waiting for the entire buffer to fill up before delivering it. At this time, the sending TCP sets PSH to 1 and immediately creates a segment to send. The receiving TCP quickly delivers the segment to the receiving application process when it receives a segment with PSH=1.
- RESET (RST): When RST=1, it indicates a serious error in the TCP connection (such as due to a host crash or other reasons), which requires the connection to be released and then re-established.
- SYN: Used to synchronize sequence numbers when establishing a connection. When SYN=1 and ACK=0, it indicates a connection request segment.
- FIN: Used to release a connection.
Sliding Window
To improve data transmission efficiency, TCP uses a mechanism called sliding window for data transmission.
The following is a diagram of the sliding window at the sending end. The size of the sliding window is the length of the sequence of the green and red parts. Its working mechanism is that once the sending end receives an acknowledgment, the sliding window moves to the right.

Flow Control
Flow control can be summarized in a short sentence.
❝
The receiving end provides negative feedback to the sending end, which can control the size of the sending end’s sliding window.
❞
Below, you can see how Zhihu explains this. I found a description that is the most vivid, which can help with understanding.


Zhihu: How does TCP’s sliding window control flow?
Congestion Control
- Slow Start: Slow start means that when a TCP link is first established, it should not send a large amount of data at once, causing network congestion to spike, but rather increase the congestion window gradually based on feedback.
- Congestion Avoidance: Congestion avoidance means that the sliding window increases slowly, rather than growing exponentially like in slow start.
- Fast Retransmit: If the sender receives three duplicate acknowledgments in a row, it should immediately retransmit the segment that the other party has not yet received, without waiting for the set retransmission timer to expire.
- Fast Recovery: Fast recovery has the following two characteristics:
- When the sender continuously receives three duplicate acknowledgments, it executes the “multiplicative decrease” algorithm, halving the slow start threshold to prevent network congestion. Note that the slow start algorithm is not executed next.
- When executing the fast recovery algorithm, the sliding window value is changed, and then the congestion avoidance algorithm is started, allowing the congestion window to increase slowly.
Three-Way Handshake
The three-way handshake and four-way handshake are common knowledge points often tested in interviews. However, before introducing the three-way handshake, I think it is necessary to understand the commonalities of ideal transmission conditions:
- The transmission channel does not produce errors
- No matter how fast the sender sends data, the receiver can always receive the data in time.
Ideal conditions are ultimately ideal. The above two situations cannot occur in actual environments. So, let’s discuss how to make our actual situation closer to ideal; this is what we will discuss next regarding the three-way handshake.
First, the three-way handshake and the subsequent four-way handshake are both for TCP. UDP is a connectionless protocol, so it cannot have three-way or four-way handshakes. The three-way handshake and four-way handshake are designed for more reliable transmission. First, let’s look at the flowchart of the three-way handshake.

Since it aims to ensure reliable transmission, it is necessary to ensure the normal sending and receiving of data between the client and server.
- First Handshake: Client cannot confirm anything; Server confirms that Client’s sending is normal.
- Second Handshake: Client confirms: it can send and receive normally; the other party can send and receive normally; Server confirms: it can receive normally, and Client can send normally.
- Third Handshake: Client confirms: it can send and receive normally; the other party can send and receive normally; Server confirms: it can send and receive normally; the other party can send and receive normally.
Why do we need the third handshake? In a nutshell, it mainly prevents previously invalid connection request packets from being sent to the server again, which could lead to errors.
Through the above three steps, the Client and Server can achieve reliable transmission, and none of the steps can be omitted.
Four-Way Handshake
Since we have understood the three-way handshake, the four-way handshake should not be difficult. First, let’s attach the flowchart.

Just like the three-way handshake, the four-way handshake is also aimed at reliable transmission. The four-way handshake is the process of disconnecting the connection between the Client and Server. You may wonder why it takes four steps to disconnect a connection when three steps are sufficient to establish one. Can’t it be done in one or two steps?
The reason is that just as the three-way handshake requires confirmation from both the sender and receiver, the four-way handshake also requires confirmation from both ends.
- First Wave: Client sends a request to the Server to disconnect the connection.
- Second Wave: Server sends a confirmation of the disconnection to the Client. After receiving this, the TCP enters a half-connection state, and the channel for sending data from Client to Server is closed.
- Third Wave: Server sends a disconnection request to the Client.
- Fourth Wave: Client sends a confirmation of the disconnection to the Server. After receiving this, the TCP connection is completely terminated.
This can also be considered in terms of the issues mentioned earlier. If during the second wave, the Server sends an ACK while simultaneously sending a FIN request, and the Server is still receiving data from the Client, it could fail to receive the data due to the next ACK from the Client, resulting in a failed reception as illustrated below.

Here, I recommend an article that helps everyone better understand the establishment and disconnection process of TCP connections: Two Animations – Thoroughly Understand TCP’s Three-Way Handshake and Four-Way Handshake
Application Scenarios of TCP and UDP
As for the relationship between TCP and UDP, you may understand better after looking at the diagram below (image source from the internet):

TCP is reliable transmission, while UDP is unreliable transmission. So why do we still need to use unreliable UDP for data transmission?
We know that UDP does not require a connection to be established before data transmission. The remote host does not need to provide any acknowledgment upon receiving a UDP packet. Although UDP does not provide reliable delivery, it can be the most effective working method in certain situations (generally used for real-time communication), such as QQ voice, QQ video, live streaming, etc.
TCP provides connection-oriented services. A connection must be established before data transmission, and the connection must be released after data transmission is completed. TCP does not provide broadcast or multicast services. Due to the need for TCP to provide reliable, connection-oriented transport services (the reliability of TCP is reflected in the fact that it establishes a connection through three-way handshakes before transmitting data, and during data transmission, it has mechanisms for acknowledgment, flow control, timers, and connection management, and after data transmission, it disconnects to save system resources), this inevitably adds many overheads, such as acknowledgments, flow control, timers, and connection management. This not only significantly increases the size of the protocol data unit’s header but also consumes many processing resources. TCP is generally used in scenarios such as file transfers, sending and receiving emails, and remote logins.
Application Layer
HTTP Protocol
Regarding the definition of HTTP, you can look at how Wikipedia describes it:
❝
HTTP is a standard for request and response between a client (user) and a server (website), typically using the TCP protocol. By using a web browser, web crawler, or other tools, the client initiates an HTTP request to the server on a specified port (default port is 80). We call this client a user agent. The responding server stores some resources, such as HTML files and images. We refer to this responding server as the origin server.
❞
The HTTP protocol is now widely used on the World Wide Web. I will discuss HTTP in a separate article later, but now I must mention HTTPS.
In fact, HTTP and HTTPS are the same protocol, except that HTTPS is encapsulated with SSL (Secure Socket Layer) or TLS (Transport Layer Security). From these two protocols, we can see that HTTPS is secure, while HTTP is not secure.
FTP Protocol
FTP (File Transfer Protocol) is an application layer protocol that runs on top of the TCP protocol in the TCP/IP protocol suite. It is a reliable transmission protocol mainly used for file distribution and sharing between users, as well as for network administrators to perform operations such as device version upgrades, log downloads, and configuration saving.
DNS Protocol
Earlier, we mentioned that IP addresses are used to locate hosts, but in our daily lives, it is quite difficult to remember these irregular IP addresses; we only know the domain names of websites. So what should we do?
This is where the DNS protocol comes into play.

DNS is the Domain Name System, which resolves domain names to IP addresses. If we know a domain name but do not know the server’s IP address, we need to use the DNS protocol.
DHCP Protocol
What is the DHCP protocol? Let’s look at the definition on Wikipedia:
❝
The Dynamic Host Configuration Protocol (DHCP) is a communication protocol that enables network administrators to centrally manage and automatically assign IP network addresses. In IP networks, each device connected to the Internet needs to be assigned a unique IP address. DHCP allows network administrators to monitor and allocate IP addresses from a central point. When a computer moves to another location in the network, it can automatically receive a new IP address.
❞
Wikipedia has explained it very clearly; the role of DHCP is to dynamically assign IP addresses to hosts, greatly reducing the workload of network administrators.
Recommended Reading: Complete Organization | Directory of 365 High-Quality Technical Articles Algorithms of Beauty: Stacks and Queues The 10 Algorithms That Dominate This World Thoroughly Understanding Cookies, Sessions, Tokens A Brief Discussion on What Recursion Algorithms Are Focused on Summarizing Knowledge of Server Backend Technology Stack Welcome to Follow and Communicate for Mutual Progress Coders Have a Way Coding Coders Have a Way provides you with easy-to-understand technical articles, making technology simpler.