What TCP/IP Is: Packets, Datagrams, Connections and Packet Switching
What a protocol suite is, why the Internet moves data in packets instead of reserved circuits, how datagrams differ from connections, why links can be shared on demand, and why TCP doesn't keep your message boundaries.
kvi5hnuCode Sprout team member16 min readOn this page
Every time a browser loads a page, a phone syncs mail or a server answers an API call, two programs agree on rules for exchanging data. A set of such rules is a protocol, and a family of protocols designed to work together is a protocol suite. TCP/IP is the protocol suite of the Internet. It's named after two of its members, the Transmission Control Protocol (TCP) and the Internet Protocol (IP), but it includes dozens more: UDP, ICMP, ARP, DHCP, DNS, TLS, QUIC and others you'll meet in this course.
The suite comes with an architecture, a set of decisions about which job each protocol does and how the protocols fit together. Those decisions were made in the 1970s and still shape everything: why the network is allowed to lose packets, why your laptop and not the network fixes those losses, and why a video call and a file download can share one link without either reserving anything. This article covers the most basic of those decisions: sending data as packets.
Where TCP/IP came from
In the late 1960s there were several separate computer networks, each with its own technology. The goal of the research that produced TCP/IP was to interconnect different networks so a computer on one could talk to a computer on any other, and to let many conversations run over the result at the same time. Devices called gateways (today we call them routers) joined the networks and passed traffic between them. A network of networks was called a catenet, later an internetwork, and the global one became the Internet.
The designers listed goals beyond simple interconnection, roughly in priority order:
- Communication must continue even if some networks or routers fail.
- The Internet must support several kinds of communication service, not just one.
- It must work over many different kinds of underlying network.
- Its resources must be manageable by many separate organizations.
- It must be cost-effective.
- Attaching a new host must take little effort.
- Resource use must be accountable.
The order matters. Surviving failures came first and accountability came last, which is one reason it's still hard today to bill for, or trace, individual packets on the Internet.
Circuits: the telephone model
Before packet networks, "network" meant the telephone network. Making a call set up a circuit: a path through the telephone switches that was reserved for that call alone until someone hung up. Reserving the path has real advantages:
- Once the call is set up, delay is predictable and capacity is guaranteed.
- The network knows who is talking and for how long, which makes billing simple.
It also has a big cost. The capacity stays reserved even when nobody is speaking. Computer traffic is bursty: a browser sends a request, then nothing for several seconds, then downloads a large file in a rush. Holding a reserved path for that pattern wastes most of it.
Reserving capacity is usually done with time-division multiplexing (TDM), which gives each connection fixed, repeating time slots on a link, or with similar static schemes. TDM is a good fit for constant-rate voice and a poor fit for bursts.
Packets: sharing links on demand
The key idea, developed in the early 1960s, was packet switching. Data is cut into chunks called packets, each carrying a few hundred to a few thousand bytes. Each packet travels through the network separately, from one switch to the next, and packets from many senders share the same links.

A packet switch, which on the Internet is a router, receives packets, keeps them in a queue (a buffer in memory) and sends them on one at a time. The simplest order is first in, first out (FIFO): packets leave in the order they arrived. No capacity is set aside for anyone in advance. Packets are mixed together based on when they actually arrive, which is called statistical multiplexing.
The benefit is efficiency. Whenever there is traffic to send and capacity to carry it, the link is busy. Nothing sits idle because it was reserved for someone who has gone quiet. The cost is predictability: how fast your packets get through depends on what everyone else sharing the link is doing at that moment.
You can see both effects in a real measurement. In the course lab, two transfers ran through a router whose outgoing link was limited to 20 Mbit/s. Transfer A ran alone for four seconds, then transfer B started, then B finished:

Three things are visible in the graph:
- The link was never idle. The dashed total stays near 19.5 Mbit/s the whole time. When B arrived, nothing had to be reserved for it, and when it left, A took the capacity back within a fraction of a second.
- Each transfer's speed depended on the other. A lost about a third of its rate while B was running. That is the lack of predictability that comes with statistical multiplexing.
- The split wasn't equal. A kept more than B for most of the overlap. A newly started TCP connection begins slowly and grows its rate, while an established one already has data in flight. Article 72 explains how TCP's congestion control shares a link, and why sharing is only roughly fair.
Virtual circuits: connections built from packets
Packet switching doesn't automatically mean "no connections". A network can send packets yet still behave like a circuit network. In a virtual circuit (VC) network, a signaling protocol first sets up a path, and every switch along it stores some per-connection state: an entry saying "packets labeled 17 go out port 3". Each packet then carries only a short label, not full addresses, and the switches look the label up.
X.25, used widely until the early 1990s, worked this way with a 12-bit channel number. Frame Relay and ATM (Asynchronous Transfer Mode) used similar labels. The same idea is alive today inside many provider networks as MPLS (Multiprotocol Label Switching), which forwards packets by short labels along paths set up in advance, carrying ordinary IP packets inside.
A VC network is called connection-oriented. Its switches must hold state for every active connection, and something must set that state up and tear it down.
Datagrams: every packet carries its full address
The alternative, which first appeared in the French CYCLADES network in the early 1970s, is the datagram: a packet that carries the complete source and destination addresses inside it. A switch can forward a datagram by looking only at that packet and its own routing table, a list that maps destination address ranges to the next link to send on. It doesn't need to know that a "connection" exists at all.
Datagrams have clear trade-offs:
| Virtual circuits | Datagrams | |
|---|---|---|
| Per-packet header | Short label | Full source and destination addresses |
| State in each switch | One entry per connection | None per connection, just a routing table |
| Setup before sending | Required (signaling) | None |
| If a switch fails | Every connection through it breaks | Packets take another route |
| Order of delivery | Same path, so usually in order | Packets may take different paths and arrive out of order |
The Internet's designers chose datagrams. IP is a datagram protocol: every IP packet carries a full source and destination address, and routers keep no per-connection state. That one choice led to much of what you'll learn later:
- Routers can fail and traffic can flow around them, because no connection was tied to them. This served the first design goal: keep working through failures.
- Because IP gives no guarantees, anything you want beyond "probably delivered", such as reliability, ordering or a steady rate, must be added by the hosts at the ends. That's TCP's job, as you'll see in article 2.
- "Connection" on the Internet means something that exists only in the two end hosts. A TCP connection is state in your computer and in the server, and the routers between them don't know it exists. (Firewalls and NAT (network address translation) devices, which do track connections, are the big exception, and article 34 shows how they break the pure model.)
Message boundaries: does the receiver see your writes?
One more distinction trips up nearly every programmer at some point. When an application sends several pieces of data one after another, does the receiver get them as the same separate pieces?
- A protocol that preserves message boundaries delivers each write as its own unit. Datagram protocols naturally do this: a datagram has a start and an end. UDP (the User Datagram Protocol, a thin layer over IP) preserves boundaries.
- A protocol that doesn't preserve message boundaries delivers a stream of bytes. The receiver can get the data in different-sized chunks than it was written. TCP is a byte stream and doesn't preserve boundaries.
Here's the difference measured in the lab. A small client program on client (192.0.2.10) sends three messages to a server program on server (198.51.100.10), first over UDP and then over TCP. The server program prints what each read returns. In the TCP case, the server waits half a second before its first read, which is ordinary for a busy program.
The programs use the standard socket calls: sendto() and recvfrom() send and receive one UDP datagram, while send() and recv() write to and read from a TCP connection. Each line shows how many bytes one call handled.
The UDP sender:
sendto() 13 bytes: b'first message'
sendto() 6 bytes: b'second'
sendto() 14 bytes: b'third and last'
What the UDP receiver read, one datagram per call:
recvfrom() returned 13 bytes: b'first message'
recvfrom() returned 6 bytes: b'second'
recvfrom() returned 14 bytes: b'third and last'
The TCP sender makes the same three calls:
send() 13 bytes: b'first message'
send() 6 bytes: b'second'
send() 14 bytes: b'third and last'
The TCP receiver gets all of it in one read:
recv() returned 33 bytes: b'first messagesecondthird and last'

TCP did nothing wrong: it delivered every byte, in order. It just doesn't remember where one send() ended and the next began. Depending on timing, a receiver could also get the bytes as 20 + 13, or 1 + 32. That's why every application protocol over TCP defines its own framing:
- HTTP/1.1 sends a
Content-Lengthheader or uses chunked encoding. - Many binary protocols put a length field in front of each message.
- Line-based protocols such as SMTP (the Simple Mail Transfer Protocol, used for email) end each command with a line break.
Common questions
Is TCP/IP just TCP plus IP?
No. It's the name of the whole suite, which includes UDP, ICMP, ARP, DHCP, DNS, TLS, QUIC and many other protocols. TCP and IP were the first two at its core, and the name stuck.
If the Internet is packet-switched, why do people say "TCP connection"?
The connection exists only at the two ends. Both hosts keep state (sequence numbers, buffers, timers) that makes a series of independent IP datagrams behave like a reliable, ordered stream. The routers in between forward each datagram on its own and know nothing about the connection.
Doesn't packet switching mean packets arrive out of order?
They can, and IP doesn't promise otherwise. In practice most packets of one flow follow the same path and arrive in order, but routes change, links get bonded together, and some packets are delayed. Reordering is common enough that TCP has to handle it, and article 67 shows how.
Why didn't the Internet use reserved capacity for voice and video?
Because statistical sharing is much more efficient for bursty data, and the Internet was built for data first. Real-time media works well today because links are fast and applications adapt their rate. Providers can still prioritize some traffic, as article 25 explains, but nothing is reserved end to end.
Is MPLS a step back to circuits?
Partly. MPLS forwards by labels along paths set up in advance, like a virtual circuit, and providers use it for traffic engineering (steering traffic onto chosen paths) and VPNs (virtual private networks, which carry a customer's private traffic across the provider). But it runs inside one provider's network and carries ordinary IP datagrams. Across the Internet as a whole, forwarding is still by IP destination address.
If TCP merges my messages, how do I send separate messages over it?
Add your own framing. The most common methods are a length prefix in front of each message, a delimiter such as a newline, or a protocol that already frames messages, such as HTTP, WebSocket or gRPC. Never assume one send() arrives as one recv().
Does UDP ever split or merge datagrams?
No. A UDP datagram is delivered whole or not at all. If it's bigger than a link can carry, IP may fragment it on the way, but the receiving host reassembles it before handing it to the application, or discards it if a piece is lost. Article 46 covers fragmentation.
Summary
- A protocol suite is a family of protocols designed to work together, and TCP/IP is the Internet's. Its architecture was driven first by connecting different networks and surviving failures.
- Circuit switching reserves capacity for each call. It gives predictable delay but wastes idle capacity.
- Packet switching sends data in independent packets that share links on demand (statistical multiplexing). Links stay busy, but each flow's performance depends on the others, as the lab graph showed.
- Virtual circuits are connections built from packets, with per-connection state in every switch. Datagrams carry full addresses and need no switch state. IP is a datagram protocol, so routers keep no per-connection state.
- Reliability, ordering and rate control are therefore done by the end hosts. A TCP connection exists only in the two endpoints.
- UDP preserves message boundaries and TCP doesn't. Applications over TCP must frame their own messages.
Practice questions
1. A link carries traffic for 50 users who are each active only 5% of the time. Why does packet switching use this link better than giving each user a reserved circuit?
Answer
With circuits, each user's share is reserved even while they're idle, so about 95% of the reserved capacity goes unused. With packet switching, capacity is used by whoever is sending at that moment. At any instant only a few users are active, so they can each get much more than a 1/50 share, and the link stays busy whenever anyone has data.
2. A router in the middle of a TCP connection reboots. The connection's packets find another route within a few seconds. Does the TCP connection survive?
Answer
Usually yes. The connection's state lives only in the two end hosts, and the router held none of it. While the route was broken, some segments were lost or delayed, and TCP retransmits them once a path is available again. The connection breaks only if the outage lasts longer than TCP is willing to keep retrying, or if a stateful device such as a firewall or NAT lost its record of the connection.
3. Name two pieces of state a virtual circuit switch must keep that an IP router doesn't.
Answer
An entry for each active connection that maps its incoming label (and port) to an outgoing port and label, and the signaling state for setting up and clearing those connections. An IP router has only a routing table keyed by destination prefix, which doesn't change when connections open or close.
4. A program sends the 4-byte message PING twice over TCP. The other side calls recv() once and gets PINGPING. Is something broken? What should the protocol do?
Answer
Nothing is broken. TCP delivers a byte stream and doesn't preserve the boundary between the two writes. The application protocol must add framing, for example by ending each message with a newline and splitting the stream on newlines, or by sending a length before each message.
5. Which of these preserve message boundaries: UDP, TCP, IP datagrams?
Answer
UDP and IP datagrams do. Each one is delivered whole or not at all. TCP doesn't: it's a byte stream.
6. Why was "communication must continue despite failures" a reason to choose datagrams over virtual circuits?
Answer
With virtual circuits, connection state lives in the switches, so a failed switch destroys every connection through it, and they must all be set up again. With datagrams, the switches hold no per-connection state. If one fails, packets are simply routed around it and the end hosts' connections continue.
Previous: TCP/IP Course Outline: From Ethernet Frames to TCP, DNS, TLS and QUIC
Next: The Design Principles of the Internet: End-to-End, Fate Sharing, Error and Flow Control

More in TCP/IP Course
Quiz: TCP/IP Delicate Details
Twenty-five questions on the details that catch out experienced engineers: sequence numbers for SYN and FIN, TIME_WAIT versus tcp_fin_timeout, Karn's algorithm, socket buffer doubling, even and odd ephemeral ports, IPv6 checksums and fragmentation, negative DNS caching, and capture filter traps.
Quiz: TCP/IP Interview Questions
Thirty-three networking questions of the kind asked in developer, SRE and network engineering interviews: what happens when you load a URL, TCP versus UDP, handshakes, closing and TIME_WAIT, subnetting, NAT, DNS, MTU problems, congestion, TLS and QUIC, and debugging slow or failing connections.
Quiz: TCP/IP Course Final Exam (All Parts)
The final exam for the TCP/IP course: thirty questions across all fourteen parts, from packets and addressing through Ethernet, ARP, IP, DHCP, NAT, ICMP, UDP, DNS, TCP connections, reliability, congestion control, security, QUIC and troubleshooting.
Quiz: Modern Transports and Troubleshooting (TCP/IP Part 14)
Review modern transports and troubleshooting: QUIC packets, handshakes, 0-RTT, streams and connection migration, HTTP/3, Multipath TCP, SCTP multihoming, and a layered method for diagnosing real network faults.
Discussion
Sign in to ask a question or share what you learned.