Pebellslearn by building
0%
RoadmapsMatrixCoursesSandboxSign in
What Are Networks?  ›  Lesson

Protocols, Ports and Sockets

Port 14 minA protocol sets the rules of a conversation, a port number picks the program on a host, and a socket is an IP address plus a port.

Protocols, Ports and Sockets

The files box at 192.168.10.20 does three jobs at once: it shares folders, serves a small web dashboard and accepts remote logins for the IT person. Packets for all three arrive at the same IP address. How does the box know which program each packet is for, and how do both sides agree on what the bytes mean?

The rule

The protocol sets the rules; the port picks the program; the socket is the plug.

Protocol — an agreed set of rules for a conversation: who speaks first, what each message looks like, what counts as an error. HTTP is a protocol for web pages, DNS for name lookups, TCP for reliable delivery. Two devices can only talk if they speak the same protocol.

Port — a number from 0 to 65535 that identifies a program or service on a host. The IP address gets the packet to the right machine; the port gets it to the right program on that machine. Ranges to know:

Range Name Used for
0–1023 well-known standard services: 22 SSH, 53 DNS, 80 HTTP, 443 HTTPS
1024–49151 registered assigned to specific applications
49152–65535 dynamic (ephemeral) temporary ports that clients pick for their side of a conversation

Socket — one end of a conversation, written as an IP address plus a port, such as 192.168.10.20:443. A server program opens a socket and listens on it. A single connection is identified by both ends together with the transport protocol: source IP, source port, destination IP, destination port and protocol. Because the client's ephemeral port differs for each connection, one server socket can serve hundreds of connections at the same time.

The shortcut

Read any connection as "from IP:port to IP:port". The side on a well-known port is almost always the server; the side on a high, random port is the client.

Asha opens the dashboard on `files`Step 1 of 4
  1. Pick the protocol and port

    The address is https://192.168.10.20, so the protocol is HTTPS, and its well-known port is 443.

The trap is thinking a port is a physical socket on the back of the switch. Those are also called ports, but in this lesson a port is a number inside the packet that picks a program.

Drills

Answer fast — trust the rule.

quick drill

The IP address delivers a packet to the right machine. What delivers it to the right program?

quick drill

Which is a socket?

quick drill

A trace shows 192.168.10.57:50912 → 192.168.10.20:22. Which side is the server?

quick drill

How can one server socket on port 443 handle two tabs from the same laptop at once?

Remember

  • The protocol sets the rules; the port picks the program; the socket is the plug (IP:port).
  • Read connections as "from IP:port to IP:port" — well-known port = server, high random port = client.
  • Well-known 0–1023, registered 1024–49151, ephemeral 49152–65535.

Practice — level up

0/1 solved

Write your answer, then compare it with a rubric and a model answer.

ExplainRead a connection

A trace shows 192.168.10.57:51544 connecting to 192.168.10.20:443 and, a moment later, 192.168.10.57:51545 connecting to the same place. Explain which side is the server, what each number means, and how one server socket handles both.