TCP/IP

Understand how IP moves packets and how TCP, UDP, ports, and application protocols carry communication between hosts.

4 min read 7 lesson sections
  • #TCP
  • #UDP
  • #IP
  • #ports
  • #network layers

TCP/IP is the family of protocols used to communicate across the Internet and many private networks. IP addresses packets and helps routers forward them; transport protocols such as TCP and UDP let applications exchange data between processes on different hosts.

A practical layered model

People often describe networking with link, internet, transport, and application layers. This is a useful teaching model, not a perfect one-to-one mapping to every protocol or to the OSI model. Each layer uses services below it and exposes services above it.

Interactive diagram

OSI reference model · 7 layersTCP/IP model · 4 layersApplicationApplicationosi-pres ↔ tcp-apposi-session ↔ tcp-apposi-transport ↔ tcp-transportosi-network ↔ tcp-internetosi-data-link ↔ tcp-linkosi-physical ↔ tcp-link7 · Application7 · Application6 · Presentation6 · Presentation5 · Session5 · Session4 · Transport4 · Transport3 · Network3 · Network2 · Data link2 · Data link1 · Physical1 · PhysicalApplicationApplicationTransportTransportInternetInternetLinkLink
Legend

Current step

OSI and TCP/IP models

Compare the seven-layer OSI reference model with the four-layer TCP/IP model and see how their responsibilities map.

The models are teaching tools, not separate stacks running on a wire. TCP/IP groups OSI application, presentation and session responsibilities together, and combines the physical and data-link responsibilities in its link layer.

Documentation example: addresses use the RFC 5737 ranges and ASNs use the reserved private range. Nothing here connects to a real network.

For a web request, a device resolves the server name with DNS, selects an IP route, and sends packets through one or more routers. A transport connection carries the application exchange. HTTPS commonly uses TLS over TCP; HTTP/3 uses QUIC over UDP. The exact path depends on the application and network.

TCP and UDP do different jobs

TCP establishes a connection with a handshake, then presents applications with a reliable, ordered byte stream. Sequence numbers, acknowledgements, retransmission, flow control, and congestion control help manage delivery. TCP does not preserve application message boundaries and does not encrypt data by itself.

UDP sends independent datagrams with less transport machinery. It does not guarantee delivery, order, or duplicate protection; an application that needs those properties must provide them or use a protocol such as QUIC. DNS can use both UDP and TCP, depending on the query and response.

Ports identify application endpoints on a host. For example, HTTPS commonly uses TCP port 443, while DNS commonly uses port 53 over UDP or TCP. A port number is a convention, not proof that the expected service is actually listening there.

Interactive diagram

One TCP sessionClient and serverClient and serverSYN from clientTCP · 443Client192.0.2.10Client — 192.0.2.10Server203.0.113.20Server — 203.0.113.20
Legend

Current step

SYN — the client asks to connect

The client picks a random initial sequence number and sends SYN with no data.

Flags
SYN
Sequence
1000
State
Connection requested
Both ends agree on an initial sequence number before any data moves, which is what makes TCP reliable and ordered. Teardown costs four messages because each direction closes independently, and a firewall that only permits the handshake still has to allow the closing messages to expire the session cleanly.

Documentation example: addresses use the RFC 5737 ranges and ASNs use the reserved private range. Nothing here connects to a real network.

Follow a connection

When a client opens an HTTPS page, it first needs an IP address for the name. It then uses routing to reach the destination, establishes TCP (unless the application uses another transport), negotiates TLS, and sends HTTP data. Firewalls, NAT, reverse proxies, and load balancers may participate, but each performs a different function.

If a connection fails, separate the layers: check name resolution, local address and route, reachability, transport/listening port, TLS, and finally the application response. Success at one layer does not prove that the next layer is healthy.

Interactive diagram

Client subnet 192.0.2.0/24Server subnet 203.0.113.0/24LAN segmentLAN segmentUplinkUplinkWANWANServer subnetServer subnetClient192.0.2.10Client — 192.0.2.10Access switch192.0.2.2Access switch — 192.0.2.2Edge router192.0.2.1Edge router — 192.0.2.1InternetInternetWeb server203.0.113.20Web server — 203.0.113.20
Legend

Current step

Data at the application layer

The application produces the payload. There is no network header of any kind yet.

PDU
Data
Addressing used
None
Layer
Application
Each layer wraps the layer above it. The switch only ever reads the frame, the router rewrites the frame at every hop but leaves the IP packet intact except for the hop limit, and the server unwraps everything back to the original data.

Documentation example: addresses use the RFC 5737 ranges and ASNs use the reserved private range. Nothing here connects to a real network.

Physical and wireless examples

The link layer includes more than one medium. A wired access path can cross optical and Ethernet interfaces, while a wireless client may reassociate between access points as signal and policy change.

Interactive diagram

Private LAN · 192.0.2.0/24provider ↔ ontont ↔ gatewaygateway ↔ switchswitch ↔ endpointProvider networkProvider networkONTONTGateway192.0.2.1Gateway — 192.0.2.1Access switch192.0.2.2Access switch — 192.0.2.2Wired endpoint192.0.2.25Wired endpoint — 192.0.2.25
Legend

Current step

From fiber handoff to a wired LAN

Trace a typical access path from the provider fiber handoff through an ONT, gateway and switch to a wired endpoint.

The ONT converts the provider optical signal to an Ethernet handoff. The gateway routes between networks; the switch forwards local frames. Actual equipment roles vary by provider and deployment.

Documentation example: addresses use the RFC 5737 ranges and ASNs use the reserved private range. Nothing here connects to a real network.

Interactive diagram

Coverage area ACoverage area BCurrent associationCurrent associationRe-associationRe-associationcontroller ↔ ap-acontroller ↔ ap-bApplication trafficApplication trafficWi-Fi frames802.11Mobile client192.0.2.80Mobile client — 192.0.2.80Access point AAccess point AAccess point BAccess point BWLAN coordinationWLAN coordinationNetwork service192.0.2.20Network service — 192.0.2.20
Legend

Current step

The client is associated to AP A

The client sends and receives traffic through the current access point.

Investigate a slow roam

A user reports a short interruption while walking between rooms. Which measurements would help distinguish weak coverage from a policy or backhaul issue?

Reveal diagnosis

Correlate client RSSI, reassociation and authentication times with access-point uplink and controller logs before changing radio settings.

The client typically makes the roaming decision based on signal and policy while the WLAN system coordinates access. A roam can briefly interrupt traffic; the diagram is conceptual and does not model vendor-specific timing.

Documentation example: addresses use the RFC 5737 ranges and ASNs use the reserved private range. Nothing here connects to a real network.

Inspect and practice

On Linux, ss -tn shows TCP sockets and ss -lun shows UDP listeners. On Windows, Test-NetConnection example.com -Port 443 tests a TCP connection to that host and port. These commands inspect connectivity; they do not prove that an application is secure or functioning correctly.

Draw a browser request and label DNS, an IP route, transport, TLS, and HTTP. Then compare a failed DNS lookup with a successful lookup followed by a refused TCP connection: which component should you investigate in each case?

Security and performance

TCP and UDP do not automatically provide confidentiality or user identity. Use TLS or another suitable security protocol for sensitive application data, restrict exposed services with host and network firewalls, and keep applications updated. Congestion, packet loss, latency, path MTU, and retransmission can all affect performance; measure the failing layer before changing network settings.

Trusted references