Introduction to computer network basics and TCP/IP protocol

This tutorial will help you start from scratch and easily understand the "universal language" of computer networks - the TCP/IP protocol suite. We will talk about IP addresses, ports, how TCP ensures reliable transmission, and some new trends in modern networks. After reading this article, you will be able to understand the basic logic of most network communications.


1. A brief history of computer networks: from “dialect” to “Mandarin”

Before the Internet became as ubiquitous as it is today, the online world was actually an era of dialects:

  • The giants (IBM, Apple, Microsoft, etc.) have their own network protocols, just like people in different countries speak completely different languages;
  • An IBM mainframe that simply couldn't "talk" directly to Apple's Macintosh network;
  • This siled situation makes "global computer interconnection" seem out of reach.

The turning point occurred with the birth of the Internet Protocol Suite. It is like the "Esperanto" of the Internet, allowing various heterogeneous networks to communicate seamlessly, thereby building today's behemoth composed of countless interconnected sub-networks - Internet.


2. Internet Protocol Suite: Connecting “Networks of Networks”

The word "Internet", when broken down, is inter (mutual) + net (network). In fact, the Internet is a network of countless private/dedicated networks (enterprises, schools, homes) around the world that are connected together through a set of unified communication rules to form a "super network."

The official name of this set of rules is Internet Protocol Cluster. It contains hundreds of protocols, each performing its own duties, and the two names we hear most often are the core combination of this protocol cluster-TCP/IP.


3. The core division of labor of TCP/IP: IP is responsible for "errands" and TCP is responsible for "signing"

To understand the nature of network communication, it is enough to remember the division of labor between these two protocols:

3.1 IP Protocol (Internet Protocol)

The core task of the IP protocol is: find the address of the target device, and then send the data there in chunks. Its working style is more "Buddhist":

  • No connection: There will be no "handshake" to confirm whether the other party is online before departure;
  • Unreliable: Data packets (what we often call IP datagrams) may be lost, delayed, duplicated, and out of order;
  • Analogy to the postal system: Just like when you send a regular letter, the post office only delivers it according to the address on the envelope, and there is no guarantee that the other party will receive it.

3.2 TCP Protocol (Transmission Control Protocol)

TCP is like a conscientious courier who specializes in solving the "unreliable" problem of the IP protocol:

  • It is a protocol built on IP, and data is still transported by IP;
  • But it provides reliable, orderly, no loss, no duplication transmission guarantee;
  • Just like sending "registered mail + logistics tracking", every step has a confirmation and retry mechanism.

Simple summary: IP manages "send", and TCP manages "send, send well".


4. IP address: the “house number” of the online world

4.1 What is an IP address?

An IP address is a unique numerical identifier assigned to every internet-connected device (computer, mobile phone, server, router, etc.). Just like "Room XX, No. XX, Road XX" in the real world, only if the address is correct can the data packet be delivered accurately.

There are currently two mainstream versions:

  • IPv4: e.g.192.168.1.1, consisting of 4 groups of numbers from 0 to 255, with.separate; separate
  • IPv6: e.g.2001:0db8:85a3::8a2e:0370:7334, consisting of 8 groups of hexadecimal characters (09, af), with:Separated, consecutive zeros can be abbreviated as::

Tips: If a device is connected to both Wi-Fi and wired networks, or is a router itself, it will often have multiple IP addresses.

4.2 Comparison between IPv4 and IPv6

TypeNumber of binary digitsHow many addresses can be allocated?Current situation and characteristics
IPv432-bitAbout 4.3 billionTraditionally mainstream, but addresses were officially exhausted in 2019
IPv6128 bitsAbout "Assign an address to every grain of sand on the earth"A new generation standard, widely supported by domestic and foreign operators and new equipment

4.3 What are the three main things that the IP protocol does?

  1. Data chunking: Large files will be cut into small IP packets to facilitate transmission;
  2. Routing: forward through the router (the "express transfer station" in the network) station by station until it reaches the destination;
  3. Best effort: Only responsible for the delivery itself, and more advanced reliability guarantees are handed over to upper-layer protocols (such as TCP).

5. TCP protocol: How is reliable transmission achieved?

5.1 Core capabilities of TCP

TCP upgrades the IP ordinary mail model of "only responsible for sending, not responsible for arrival" to a high-quality express delivery service of "signing for confirmation + packet loss reissue + order sorting":

  • Three-way handshake: Before officially transmitting data, first confirm that "both parties can send and receive normally";
  • Data number: Each IP packet has a sequence number to ensure that the receiver can restore it in the correct order;
  • Packet loss retransmission: If a certain piece of data is not confirmed for a long time, it will be automatically resent;
  • Flow Control: Dynamically adjust the sending speed to prevent "speak too fast and the other party cannot hear".

5.2 "TCP-based protocol" that is indispensable every day

Many applications that require data not to be lost and in correct order use TCP at the bottom layer:

- HTTP / HTTPS    → 网页浏览、App 接口(HTTPS = HTTP + 加密)
- SMTP            → 发送电子邮件
- FTP / SFTP      → 文件传输(SFTP 加了 SSH 加密)
- SSH             → 远程登录服务器,开发者必备

6. Port number: "Room number" on the same device

6.1 Why do we need a port?

The IP address can only help you find which device, but if this device is running a web browser, WeChat, and email client at the same time... IP alone cannot distinguish these applications. At this time, you need the port number to further locate: "Send it to this device, which program will it specifically send to?"

  • The combination of IP address + port number is called a network communication endpoint.

6.2 Classification of ports

The port number is a 16-bit integer in the range0~65535, divided into three categories according to use:

TypeScopeDescription
Well-known ports (Well-known)0 ~ 1023The system is reserved for standard services, such as HTTP=80, HTTPS=443, SSH=22
Registered port (Registered)1024 ~ 49151Users/software can be registered for use, such as MySQL=3306, Redis=6379
Dynamic port (Dynamic/Private)49152 ~ 65535The system temporarily allocates when the client initiates a connection and releases it when used up

6.3 What does a complete network connection look like?

It can be expressed as a quadruple:

源 IP : 源端口  →  目标 IP : 目标端口

Give a practical example: your computer (192.168.1.100) Use the browser temporary port52341Visit Baidu homepage (110.242.68.66of443port), then this connection is:

192.168.1.100 : 52341  →  110.242.68.66 : 443

This four-tuple uniquely identifies a communication process at the network layer.


7. Some new changes in modern network protocols

Although TCP/IP is the absolute cornerstone, technology is always evolving. Here are a few cutting-edge trends to help you quickly understand:

7.1 IPv6 is being fully rolled out

  • With the exhaustion of IPv4 addresses, the broadband and mobile networks of the three major domestic operators have basically turned on IPv6 by default;
  • IPv6 not only manages enough addresses, but also simplifies the packet header and improves router forwarding efficiency;
  • Built-in IPsec security mechanism makes end-to-end encryption easier;
  • Extremely friendly to Internet of Things (IoT) devices - after all, there will be far more devices than humans in the future.

7.2 New transmission protocol

  • QUIC: Developed by Google, based on UDP (another connectionless transmission protocol with more port functions than IP), integrating the reliability of TCP with the low latency of UDP;
  • HTTP/3: A new generation of HTTP protocol based on QUIC, which mainstream browsers and many major manufacturers (Bilibili, Douyin, etc.) have begun to support;
  • MQTT: A lightweight protocol tailored for the Internet of Things. It has low transmission overhead and saves power. It is very suitable for restricted devices such as sensors.

8. From theory to practice, what can you learn next?

After understanding the core concepts of TCP/IP, IP address, and port, you can happily enter the world of network programming:

  1. Socket Programming Using Pythonsocketlibrary or Javajava.netPackage, write a simple TCP client/server, and intuitively experience the three-way handshake and data transmission.

    # 一个简陋的 TCP 客户端示例(Python)
    import socket
    
    client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    client.connect(("www.example.com", 80))
    client.send(b"GET / HTTP/1.1\r\nHost: www.example.com\r\n\r\n")
    response = client.recv(4096)
    print(response.decode())
    client.close()
  2. Protocol Analysis Tool Install Wireshark, grab a package and see the original data of the real TCP three-way handshake, HTTP request and response, and the theory will be "visualized" immediately.

  3. Learn the basics of network security Understand concepts such as port scanning, firewalls, and TLS encryption, and know how to protect your network applications.

  4. Build applications using advanced frameworks In actual development, we mostly use encapsulated frameworks, such as Python’s Flask/django and Node.js’ Express. The bottom layer of these tools helps you figure out the details of TCP, but when you encounter performance bottlenecks or weird bugs, your understanding of TCP/IP principles will become a powerful tool for troubleshooting.


💡 The most important reminder Now when writing network applications, although high-level libraries shield a lot of low-level details, understanding the core principles of TCP/IP is always one of the key capabilities for diagnosing network anomalies, optimizing application performance, and designing reliable systems. I hope this tutorial can help you lay a clear and solid foundation. come on!