Skip to main content

Communication Protocols

Communication protocols are rules that allow devices and applications to format, send, receive, and interpret data consistently over a network.

Application chooses how messages are structured

Transport layer delivers the data between devices

Receiving application interprets the message

One-line idea: Protocols give both sides the same communication rules so data can move and be understood correctly.

Core Concepts

Why Protocols Are Needed

Two systems can communicate only when they agree on rules such as:

  • message format
  • how communication begins
  • how data is transferred
  • how responses are represented
  • whether delivery must be reliable
  • whether communication must be encrypted

Without shared rules, one system would not know how to understand data sent by another.

Protocol Layers

The source groups the protocols into two main layers:

LayerMain responsibilityExamples
Application layerDefines messages used by applicationsHTTP, HTTPS, WebSockets, SMTP, FTP
Transport layerDelivers data between devicesTCP, UDP
Application Protocol
HTTP / HTTPS / WebSocket / SMTP / FTP

Transport Protocol
TCP / UDP

Network transmission

Application protocols define what the communication means. Transport protocols define how the data is delivered.

Application vs Transport Protocols

QuestionApplication protocolTransport protocol
What does it define?Request, response or message rulesDelivery behavior between devices
Who mainly uses it?Browsers, apps, mail clients and serversOperating systems and network stacks
Example decisionHow an HTTP request is structuredWhether packets need reliable delivery
ExamplesHTTP, SMTP, FTPTCP, UDP

Ports

A port identifies the application or service that should receive network traffic on a machine.

IP address -> identifies the destination machine
Port -> identifies the service on that machine

Common ports from the source:

ProtocolCommon or default port
HTTP80
HTTPS443
SMTP25, 465, 587
FTP21

Choosing Reliability or Speed

Transport protocols make different trade-offs:

Need reliable ordered delivery? -> TCP
Need low overhead and speed? -> UDP

The application chooses a protocol based on what matters most for its communication.

Protocols and Practical Flows

HTTP

HTTP stands for HyperText Transfer Protocol. It is the main request-response protocol used by the web.

The client initiates communication:

Browser -> HTTP Request -> Server
Browser <- HTTP Response <- Server

HTTP can transfer:

  • HTML documents
  • CSS stylesheets
  • JavaScript files
  • images and media
  • JSON API data

A response can contain the requested resource along with headers and a status code.

Simplified request:

GET /products HTTP/1.1
Host: example.com

Simplified response:

HTTP/1.1 200 OK
Content-Type: application/json

[{ "id": 1, "name": "Headphones" }]

HTTP Is Stateless

HTTP treats every request as an independent interaction. The server does not automatically remember an earlier request.

Request 1 -> independent
Request 2 -> independent
Request 3 -> independent

Applications use mechanisms such as these to maintain user state:

  • cookies
  • sessions
  • tokens

For example, a token can identify the logged-in user on later requests.

HTTP Versions and Transport

Earlier HTTP versions use TCP:

HTTP/1.1 -> TCP
HTTP/2 -> TCP

HTTP/3 uses QUIC, which is built on UDP:

HTTP/3 -> QUIC -> UDP

HTTP/3 and QUIC

HTTP/3 is designed to reduce latency and improve performance, especially on slow or unstable networks.

With older TCP-based HTTPS communication, connection setup involves:

  • a TCP handshake
  • a TLS encryption handshake

QUIC combines connection and security setup more efficiently.

HTTP/1.1 or HTTP/2
TCP connection + TLS setup

HTTP/3
QUIC connection with integrated secure setup

Another important difference is how streams react to packet loss.

TCP-based connection:
Lost packet can delay dependent stream delivery

QUIC:
Independent streams reduce delay between unrelated data streams

Key advantages mentioned in the source:

  • faster connection establishment
  • lower latency
  • better behavior on unreliable networks
  • fewer delays caused by packet loss

HTTPS

HTTPS stands for HyperText Transfer Protocol Secure. It is HTTP communication protected with TLS encryption.

HTTP + TLS security = HTTPS

Before application data is exchanged, the browser and server establish a secure connection through a TLS handshake.

Browser and server perform TLS handshake

Secure encrypted connection is established

HTTP requests and responses travel securely

HTTPS protects data such as:

  • login credentials
  • payment information
  • personal data
  • API requests and responses

TLS provides three important protections:

ProtectionMeaning
EncryptionOther parties should not be able to read the data
IntegrityData should not be modified unnoticed in transit
AuthenticationThe browser can verify the server's identity through its certificate

Default HTTPS port: 443.

HTTP vs HTTPS

FeatureHTTPHTTPS
EncryptionNoYes, through TLS
Default port80443
Sensitive dataUnsafe for unencrypted transmissionProtected during transmission
Request-response behaviorYesYes

HTTPS keeps the HTTP communication model while adding security.

WebSockets

WebSockets provide a persistent, bidirectional connection between a client and server.

HTTP request-response:
Client requests -> Server responds

WebSocket:
Client <-----------------> Server
Both sides can send data at any time

The connection begins as an HTTP request. The client asks the server to upgrade the connection.

Client sends HTTP Upgrade request

Server accepts the upgrade

Protocol switches to WebSocket

Persistent bidirectional connection remains open

Because the connection remains open, the client does not need to repeatedly create new requests to check for every update.

Common uses:

  • chat applications
  • live notifications
  • multiplayer games
  • real-time dashboards
  • stock market updates

Basic WebSocket Example

const socket = new WebSocket("wss://example.com/live");

socket.addEventListener("open", () => {
socket.send("Client connected");
});

socket.addEventListener("message", (event) => {
console.log("Received:", event.data);
});
Connection opens

Client or server sends a message

Other side receives it immediately

HTTP vs WebSockets

AreaHTTPWebSockets
CommunicationRequest-responseBidirectional
InitiatorClient starts each requestClient and server can send after connection
ConnectionUsed for requests and responsesPersistent connection remains open
Good forPages, files, APIsReal-time updates

SMTP

SMTP stands for Simple Mail Transfer Protocol. It sends and forwards email messages.

Email client
↓ SMTP
Sending mail server
↓ SMTP
Recipient mail server

SMTP sends mail but does not retrieve it.

SMTP      -> sending and forwarding email
IMAP/POP3 -> retrieving email

Common SMTP ports:

  • 25
  • 465
  • 587

FTP

FTP stands for File Transfer Protocol. It transfers files between a client and server.

Typical example:

Developer's FTP client

HTML, CSS, JavaScript, images

Web server

FTP uses two channels:

ChannelPurpose
Control channelSends commands and responses
Data channelTransfers file content

Default FTP port: 21.

Traditional FTP does not encrypt its communication. More secure alternatives such as FTPS and SFTP are commonly preferred.

Application Protocol Summary

ProtocolMain purposeCommunication styleTransport foundation
HTTPWeb resources and APIsRequest-responseTCP for HTTP/1.1 and HTTP/2
HTTP/3Faster modern web communicationRequest-response with independent streamsQUIC over UDP
HTTPSSecure web communicationEncrypted HTTP request-responseTLS with the underlying transport
WebSocketsReal-time messagesPersistent bidirectional connectionCommonly uses TCP
SMTPSending emailMail transfer between clients and serversTCP
FTPTransferring filesControl and data channelsTCP

TCP

TCP stands for Transmission Control Protocol. It is a connection-oriented transport protocol focused on reliable delivery.

TCP provides:

  • reliable data delivery
  • correct packet ordering
  • error detection
  • retransmission of lost packets
Packets sent:     1, 2, 3, 4
Packet 3 lost: TCP detects the problem
Retransmission: Packet 3 is sent again
Delivered order: 1, 2, 3, 4

Because TCP performs connection setup, ordering and retransmission, it has more overhead than UDP but provides dependable communication.

Protocols that use TCP include:

  • HTTP/1.1 and HTTP/2
  • HTTPS in TCP-based versions
  • SMTP
  • FTP

TCP Three-Way Handshake

TCP establishes a connection before transferring application data.

Client                         Server
| -------- SYN ------------> |
| <----- SYN-ACK ----------- |
| -------- ACK ------------> |
| Connection ready |

Step 1 — SYN

The client asks to establish a connection.

Client -> SYN -> Server

Step 2 — SYN-ACK

The server acknowledges the request and confirms readiness.

Client <- SYN-ACK <- Server

Step 3 — ACK

The client confirms the server's response.

Client -> ACK -> Server

After these steps, the connection is ready for data transfer.

UDP

UDP stands for User Datagram Protocol. It is a connectionless transport protocol focused on speed and low overhead.

UDP sends datagrams without first establishing a connection.

Sender -> Datagram 1 -> Receiver
Sender -> Datagram 2 -> Receiver
Sender -> Datagram 3 -> Receiver

UDP does not guarantee:

  • delivery
  • packet order
  • retransmission of lost packets
  • error correction

This makes UDP suitable when low latency matters more than perfect delivery.

UDP Packet Structure

A UDP header contains only a few fields:

  • source port
  • destination port
  • length
  • checksum

The small header keeps UDP lightweight and efficient.

Common UDP Uses

UDP is commonly used for:

  • video streaming
  • online gaming
  • DNS queries
  • voice calls through VoIP
  • live broadcasts

In these cases, receiving data quickly can be more important than retransmitting every lost packet.

TCP vs UDP

FeatureTCPUDP
ConnectionConnection-orientedConnectionless
ReliabilityGuaranteed through acknowledgements and retransmissionNo delivery guarantee
Packet orderPreservedNot guaranteed
Lost dataRetransmittedNot automatically retransmitted
OverheadHigherLower
SpeedGenerally slowerGenerally faster
Typical usesWeb, email, file transferStreaming, gaming, DNS, VoIP

How the Layers Work Together

Loading a page with HTTP/2:

Browser creates HTTP request

HTTP uses TCP for reliable delivery

Packets travel through the network

Server returns the HTTP response

Loading a page with HTTP/3:

Browser creates HTTP/3 request

HTTP/3 uses QUIC over UDP

Independent streams carry the data

Server returns the response

Receiving a live chat message:

HTTP upgrades to WebSocket

Persistent connection remains open

Server sends a new message immediately

Client updates the chat UI

Common Mistakes

MistakeCorrect understanding
HTTP and TCP are the sameHTTP structures web messages; TCP delivers data reliably
HTTPS is a different request modelHTTPS uses HTTP behavior with TLS security
HTTP automatically remembers usersHTTP is stateless; state uses cookies, sessions or tokens
WebSockets repeatedly poll the serverThey maintain a persistent bidirectional connection
SMTP receives emailSMTP sends mail; IMAP or POP3 retrieves it
UDP means packets always arrive faster and correctlyUDP has low overhead but does not guarantee delivery or order
HTTP/3 runs directly on TCPHTTP/3 uses QUIC over UDP
Traditional FTP is secureTraditional FTP does not encrypt its data

Interview Revision

Quick Revision Checklist

  • Protocols define how systems format, exchange and interpret data.
  • Application protocols include HTTP, HTTPS, WebSockets, SMTP and FTP.
  • Transport protocols include TCP and UDP.
  • HTTP follows a client-initiated request-response model.
  • HTTP is stateless; applications use cookies, sessions or tokens for state.
  • HTTP/1.1 and HTTP/2 use TCP.
  • HTTP/3 uses QUIC over UDP.
  • HTTPS protects HTTP communication using TLS.
  • WebSockets maintain a persistent bidirectional connection.
  • SMTP sends email; IMAP and POP3 retrieve it.
  • FTP uses separate control and data channels.
  • TCP is reliable, ordered and connection-oriented.
  • TCP begins with SYN, SYN-ACK and ACK.
  • UDP is connectionless, lightweight and does not guarantee delivery.
  • TCP suits reliable web, mail and file transfer.
  • UDP suits latency-sensitive streaming, gaming, DNS and voice traffic.

Frequently Asked Interview Questions

1. What is a communication protocol?

A communication protocol is a shared set of rules defining how systems structure, transmit, receive and interpret data.

2. What is the difference between application and transport protocols?

Application protocols define message behavior for services such as web or email. Transport protocols control how data is delivered between devices.

3. Why is HTTP called stateless?

Each HTTP request is treated independently. The protocol does not automatically remember earlier requests from the same user.

4. What is the difference between HTTP and HTTPS?

HTTPS uses the HTTP communication model but protects it with TLS encryption, integrity checks and server authentication.

5. Why are WebSockets useful?

They keep a persistent bidirectional connection open, allowing the client and server to send real-time messages without repeated polling.

6. What is the difference between TCP and UDP?

TCP establishes a connection and guarantees ordered, reliable delivery. UDP sends datagrams with lower overhead but does not guarantee delivery or order.

7. What is the TCP three-way handshake?

The client sends SYN, the server replies with SYN-ACK, and the client sends ACK to establish a TCP connection.

8. Why does HTTP/3 use QUIC?

QUIC reduces connection setup time, supports independent streams and handles packet loss without delaying unrelated streams in the same way as a TCP-based connection.

9. What is SMTP used for?

SMTP sends and forwards email between clients and mail servers. It does not retrieve email.

10. Why is UDP used for gaming and streaming?

These applications prioritize low latency. A small amount of packet loss may be preferable to waiting for retransmission.

Memory Trick

Meaning -> Delivery

Application protocols define the meaning:
HTTP, HTTPS, WebSocket, SMTP, FTP

Transport protocols control delivery:
TCP = reliable
UDP = fast and lightweight

One-Line Summary

Application protocols define how services communicate, while TCP, UDP and QUIC provide the delivery behavior required by those services.

Final Mental Model

Application needs to communicate

Choose message protocol
HTTP / HTTPS / WebSocket / SMTP / FTP

Choose delivery foundation
TCP for reliability
UDP for low overhead
QUIC over UDP for HTTP/3

Data travels across the network

Receiver interprets it using the same protocol rules