System Design Academy

Saving…

Lesson 3 of 10 in Module 10 of 54 lessons complete

IP Addresses, Ports & Packets

Module 1, lesson 3Concept10 min

Definition

IP address

In plain English
An IP address is a number that identifies a device on a network so messages can reach it.
Think of it like
It is like a street address for a building.

Port

In plain English
A port is a number that picks which program on a device should receive a message.
Think of it like
It is like an apartment number inside that building.

Packet

In plain English
A packet is a small chunk of data that travels across the network on its own.
Think of it like
It is like mailing a long letter as numbered postcards.

Why it exists

Your message needs to reach one destination among billions, then the correct program there. An address gets it to the machine; a port helps the receiving computer choose the program.

Large messages travel in packets so many conversations share the network. Resending missing pieces avoids restarting the whole message.

How it works

  • IPv4 has about 4.3 billion 32-bit addresses, such as 192.168.1.20. The pool of freely available addresses has run out.
  • IPv6 uses 128-bit addresses, such as 2001:db8::1. It provides far more addresses, though the number is still limited.
  • Public addresses work across the internet. Private addresses are reused inside local networks.
Common portService
53DNS
80HTTP
443HTTPS
5432PostgreSQL database
6379Redis data store
  1. Split data

    The computer splits data into packets and adds addresses. It also adds port numbers to identify the programs.

  2. Forward

    Routers pass packets toward their destination using the IP address.

  3. Reassemble

    The receiving computer delivers data to the right program. TCP puts the data back in order.

The app splits data into packets that cross Router A and Router B. Server 203.0.113.7 receives them on port 443 and reassembles the data.

Packets cross routers before the receiving computer reassembles data.

The app splits data into packets that cross Router A and Router B. Server 203.0.113.7 receives them on port 443 and reassembles the data.

TCP

In plain English
TCP is a protocol that delivers data reliably and in order by resending any packets that get lost.
Think of it like
It is like a tracked courier who needs a signature for every parcel and resends any that go missing.

UDP

In plain English
UDP is a protocol that sends packets quickly without checking whether they arrived or arrived in order.
Think of it like
It is like shouting across a field and hoping you are heard.
PropertyTCPUDP
Reliable and orderedYes, or connection failsNo guarantee
DelayLoss can delay later dataUDP does not resend missing packets
Connection setupRequired for a connectionUDP needs none
Typical useFiles and commandsLive media and game positions

Examples

Keep game positions fresh

Your game needs dependable login and matchmaking plus fresh in-match positions.

Use TCP for login and matchmaking, where missing information matters. During a match, send positions with UDP 60 times per second. A newer position arrives about 16.7 milliseconds later, making an old position less useful.

Different messages can use different transports in one game.
Text
TCP: login -> accepted -> match assigned
UDP: position 100 -> position 101 lost -> position 102

The insight

Ask "is a late packet worse than a lost one?"

Trade-offs

Pros

  • Resend lost data.
  • Deliver data in order.

Cons

  • Connection setup adds delay.
  • Missing data delays later bytes.
  • A disconnected computer still stops the conversation.

Use when

  • Transfer files or payment instructions.
  • Send commands whose order matters.

Avoid when

  • Fresh voice or video matters more than every sample.
  • New game positions replace missing old ones.

Quick check

One server runs a website and a database. How does an incoming message reach the database, not the website?
Which data fits UDP best?

Takeaways

  • IP finds the machine, port finds the program.
  • Data travels as packets.
  • TCP delivers data reliably in order or reports failure; UDP guarantees neither.

Try the quick check above whenever you feel ready.

Previous: Clients and Servers