Skip to main content

Command Palette

Search for a command to run...

TCP vs UDP

When to Use What, and How TCP Relates to HTTP

Updated
6 min read

What is the User Datagram Protocol (UDP/IP)?

Like all networking protocols, UDP is a standardized method for transferring data between two computers in a network. Compared to other protocols, UDP accomplishes this process in a simple fashion: it sends packets (units of data transmission) directly to a target computer, without establishing a connection first, indicating the order of said packets, or checking whether they arrived as intended. (UDP packets are referred to as ‘datagrams’.)

The User Datagram Protocol, or UDP, is a communication protocol used across the Internet for especially time-sensitive transmissions such as video playback or DNS lookups. It speeds up communications by not formally establishing a connection before data is transferred. This allows data to be transferred very quickly, but it can also cause packets to become lost in transit — and create opportunities for exploitation in the form of DDoS attacks.

What is the Transmission Control Protocol (TCP/IP) ?

The TCP/IP relationship is similar to sending someone a message written on a puzzle through the mail. The message is written down and the puzzle is broken into pieces. Each piece then can travel through a different postal route, some of which take longer than others. When the puzzle pieces arrive after traversing their different paths, the pieces may be out of order. IP makes sure the pieces arrive at their destination address. TCP can be thought of as the puzzle assembler on the other side who puts the pieces together in the right order, asks for missing pieces to be resent, and lets the sender know the puzzle has been received. TCP maintains the connection with the sender from before the first puzzle piece is sent to after the final piece is sent.


UDP vs TCP

UDP is faster but less reliable than TCP, another common transport protocol. In a TCP communication, the two computers begin by establishing a connection via an automated process called a ‘handshake.’ Only once this handshake has been completed will one computer actually transfer data packets to the other.

UDP communications do not go through this process. Instead, one computer can simply begin sending data to the other:

In addition, TCP communications indicate the order in which data packets should be received and confirm that packets arrive as intended. If a packet does not arrive — e.g. due to congestion in intermediary networks — TCP requires that it be re-sent. UDP communications do not include any of this functionality.

These differences create some advantages. Because UDP does not require a ‘handshake’ or check whether data arrives properly, it is able to transfer data much faster than TCP.

However, this speed creates tradeoffs. If a UDP datagram is lost in transit, it will not be re-sent. As a result, applications that use UDP must be able to tolerate errors, loss, and duplication.

(Technically, such packet loss is less a flaw in UDP than a consequence of how the Internet is built. Most network routers do not perform packet ordering and arrival confirmation by design, because doing so would require an unfeasible amount of additional memory. TCP is a way of filling this gap when an application requires it.)


What is UDP used for and practical examples

UDP is a fast, connectionless transport protocol that sends data without reliability guarantees. It is efficient for applications where speed is more important than accuracy.

  • Connectionless and lightweight

  • No guarantee of delivery or order

  • Low overhead and high speed

Applications of UDP

UDP is best suited for transferring a steady flow of live data. This allows many users to access data easily and quickly, if not in perfect condition. A good example is playing an online game. UDP can keep the action moving in spite of potential errors or data loss. Here are a few applications of UDP in real life.

  • Online gaming

  • Multicasting

  • Video chatting/conferencing

  • VoIP (in-app voice calling)

  • Domain Name Systems (which translates domain names into IP addresses)

What is TCP used for and practical examples

TCP is a reliable, connection-oriented transport protocol that ensures accurate and ordered data delivery. It uses control mechanisms to guarantee data correctness, which makes it slower but dependable.

  • Connection-oriented protocol

  • Reliable and ordered data delivery

  • Higher overhead but high accuracy

Applications of TCP

Most data transfers automatically use the best protocol option. But in certain circumstances — such as when using a VPN — you may need to choose a protocol to optimize your browsing experience. Enable TCP for the following activities:

  • Email and text messaging

  • Streaming pre-recorded content on sites like Netflix, Hulu, or HBO Max

  • Transferring files between apps and devices

  • General web browsing

  • Remote device or network administration

FactorTCPUDP
Connection typeRequires an established connection before transmitting dataNo connection is needed to start and end a data transfer
Data sequenceCan sequence data (send in a specific order)Cannot sequence or arrange data
Data retransmissionCan retransmit data if packets fail to arriveNo data retransmitting. Lost data can’t be retrieved
DeliveryDelivery is guaranteedDelivery is not guaranteed
Check for errorsThorough error-checking guarantees data arrives in its intended stateMinimal error-checking covers the basics but may not prevent all errors
BroadcastingNot supportedSupported
SpeedSlow, but complete data deliveryFast, but at risk of incomplete data delivery

HTTP: The Application, Not the Transport

A common point of confusion is whether HTTP (what you see in your browser) is the same thing as TCP.

What is HTTP?

HTTP (Hypertext Transfer Protocol) is an Application-level protocol. It defines what the message says (e.g., "Give me the image on the homepage"). It does not care how the message physically travels across the wires. HTTP is a protocol for fetching resources such as HTML documents. It is the foundation of any data exchange on the Web and it is a client-server protocol, which means requests are initiated by the recipient, usually the Web browser. A complete document is typically constructed from resources such as text content, layout instructions, images, videos, scripts, and more

The Relationship: HTTP runs on top of TCP

Think of the Internet like a building:

  • TCP is the Foundation and the Plumbing: It provides a solid, reliable pipe for data to flow through.

  • HTTP is the Living Room: It is the actual space you interact with.

HTTP does not replace TCP because they have different jobs. HTTP creates the request ("I want this website"), and it hands that request to TCP to ensure it gets delivered safely without any missing letters or broken images.

Is HTTP the same as TCP

  • TCP handles the "shipping and delivery" (making sure the box arrives).

  • HTTP handles the "contents of the box" (the actual website data).

Because a website would be broken if even a single line of code were missing, HTTP almost always uses TCP to ensure everything arrives perfectly. You wouldn't want to load a webpage where the text is out of order or the login button is missing—that is why HTTP relies on the "Safe and Reliable" nature of TCP.