IP Addresses, Ports & Packets
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 port | Service |
|---|---|
| 53 | DNS |
| 80 | HTTP |
| 443 | HTTPS |
| 5432 | PostgreSQL database |
| 6379 | Redis data store |
- Split data
The computer splits data into packets and adds addresses. It also adds port numbers to identify the programs.
- Forward
Routers pass packets toward their destination using the IP address.
- 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.
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.
| Property | TCP | UDP |
|---|---|---|
| Reliable and ordered | Yes, or connection fails | No guarantee |
| Delay | Loss can delay later data | UDP does not resend missing packets |
| Connection setup | Required for a connection | UDP needs none |
| Typical use | Files and commands | Live 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.
TCP: login -> accepted -> match assigned
UDP: position 100 -> position 101 lost -> position 102The insight
Ask "is a late packet worse than a lost one?"
Apply rail commands in order
A rail controller receives commands to set a signal red and then green.
The controller receives commands on a fixed port. TCP keeps RED and GREEN in order. The controller must confirm each action, enforce deadlines, and leave signals safe if communication fails.
The control centre sends SET RED and receives confirmation from the signal controller. It then sends SET GREEN and receives confirmation.
The insight
Safety-critical commands pay for reliability.
Connect lockers through a router
Forty locker banks share a building router and one public IPv4 address.
NAT
- In plain English
- NAT is a router feature that lets many devices with private addresses share one public address.
- Think of it like
- It is like a company switchboard with one public phone number and many internal extensions.
Forty locker banks use private 192.168.x.x addresses. Without router rules allowing incoming connections, each locker must connect outward first. The server sends messages back through that connection.
Lockers connect through a NAT router and the internet to the locker server.
The insight
Addressing decides who can start a conversation.
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
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.