SDSystem DesignConcepts to case studies
System DesignDSA
x
0/311
Part 1: Foundations
  • OSI Model
  • IP Address
  • TCP vs UDP
  • HTTP / HTTPS
  • DNS
  • Proxy vs Reverse Proxy
  • Checksums
  • HTTP/1.1 vs HTTP/2 vs HTTP/3
  • Cookies and CORS
  • Subnets, CIDR and NAT
  • Firewalls and VPN
  • Ports and Sockets
Part 2: APIs and Communication
Part 3: Caching
Part 4: Data and Storage
Part 5: Architecture
Part 6: Distributed Systems
Part 7: Advanced Data Topics
Part 8: Operations and Security
Part 9: Estimation and Interview Method
Part 10: Case Studies
System Design/Foundations/Networking

IP Address

The street address of a device on a network. IPv4, IPv6, public, private and subnets.

⏱ 12 min readBeginnerMust KnowHas visualizer
SummaryConceptReal-Life ExampleWhy?Where?How It WorksStepsKey TermsPros & ConsMistakesReal WorldRead NextInterview Q&ACheat-Sheet

01Quick Summary

An IP address is the address of a device on a network. It tells data where to go and where it came from.

  • IPv4: 32 bits, written like 192.168.1.10. About 4.3 billion addresses.
  • IPv6: 128 bits, written like 2001:db8::1. An almost endless number of addresses.
  • Public addresses work on the internet. Private addresses work only inside a home or office network.
  • A subnet splits a network into smaller parts. CIDR (like /24) tells how big.

02Concept: What is it?

Every device that talks on a network (phone, laptop, server) needs an address, so replies know where to return. This is the Internet Protocol (IP) address. It works at the Network layer (layer 3) of the OSI model.

IPv4

An IPv4 address has 32 bits, split into 4 octets (8 bits each). Each octet is a number from 0 to 255. We write them with dots.

Anatomy of 192.168.1.10
19211000000
16810101000
100000001
1000001010
Network part (first 24 bits) Host part (last 8 bits)
Left part = which network. Right part = which device in that network. With /24 the first 24 bits are the network.

IPv6

IPv4 is running out. IPv6 has 128 bits, written as 8 groups of hex numbers, like 2001:0db8:0000:0000:0000:0000:0000:0001. We can shorten it: leading zeros can go, and one run of zero groups becomes ::. So that address becomes 2001:db8::1.

🧠How big?
IPv4: 2³² = about 4.3 billion addresses. IPv6: 2¹²⁸ = about 3.4 × 10³⁸ addresses.

03Real-Life Example

🍵House addresses and a big apartment building
Every house needs an address, so the post can reach it. An IP address is the same. A big apartment building has one street address but many flats inside. Your home network is like that: your whole home shares one public address, and each device inside gets its own private flat number.
Home network
Home (private)
💻Laptop192.168.1.10
📱Phone192.168.1.11
→↓
📶Router (NAT)public: 203.0.113.5
→↓
🌍Internet
→↓
🖥️Server198.51.100.7
Your router has one public IP. Devices at home use private IPs. The router translates between them (this is called NAT).
Post and addresses
Network
House address
IP address
City and street
Network part
House number
Host part
A big building with many flats
Router with NAT and private IPs
Post office sorting centre
Router
Your name, to pick the right person
Port number

04Why Do We Need It?

📍Find the destination
Routers use the IP to decide where to send each packet.
↩️Send the reply back
The source IP tells the server where to answer.
🧱Group and protect
Subnets split a network, so we can control traffic between parts.
🔒Control access
Firewalls allow or block by IP address.
🪙Save addresses
Private IPs and NAT let many devices share one public IP.
🎤Design systems
Cloud networks (VPCs) use subnets, so you must understand them.
Without IP addresses, data would not know where to go.

05Where Do We Use It?

🌐Every internet request
DNS gives the IP, then the browser connects to it.
☁️Cloud networks (VPC)
You pick an IP range and split it into subnets.
🔥Firewalls and allow-lists
"Only allow traffic from this IP range."
⚖️Load balancers
Hide many server IPs behind one.
🛡️Rate limiting
Limit requests per client IP.
🗺️Location (geo-IP)
Guess a user's country from the IP.

06Types / Parts / How It Works

Public vs private

Public IP
Works on the internet
  • Must be unique in the world
  • Given by your internet provider or cloud
  • Servers you want users to reach
  • Example: 203.0.113.5
Private IP
Works only inside a local network
  • Can be reused in many networks
  • Not reachable from the internet directly
  • Home, office and cloud networks
  • Example: 192.168.1.10
Private rangeCIDRSize
10.0.0.0 – 10.255.255.25510.0.0.0/8About 16.7 million
172.16.0.0 – 172.31.255.255172.16.0.0/12About 1 million
192.168.0.0 – 192.168.255.255192.168.0.0/1665,536

Special addresses

AddressMeaning
127.0.0.1Loopback (localhost). This computer itself.
0.0.0.0"Any address" or "unknown". Servers use it to listen on all interfaces.
169.254.x.xLink-local. A device gave itself an address because no DHCP answered.
255.255.255.255Broadcast to every device on the local network.
224.0.0.0 – 239.255.255.255Multicast. Sent to a group of devices.

Static vs dynamic

  • Static: set by hand and never changes. Good for servers.
  • Dynamic: given automatically by DHCP when a device joins. Good for phones and laptops.

Subnets and CIDR

A subnet is a smaller network inside a bigger one. CIDR notation writes the address followed by a slash and the number of network bits: 192.168.1.0/24 means the first 24 bits are the network and the last 8 bits are for hosts. That gives 2⁸ = 256 addresses, and 254 can be used for devices (the first is the network address, the last is the broadcast address).

CIDRSubnet maskTotal addressesUsable hosts
/8255.0.0.016,777,21616,777,214
/16255.255.0.065,53665,534
/24255.255.255.0256254
/28255.255.255.2401614
/30255.255.255.25242
💡Quick rule
Total addresses = 2^(32 − prefix). Usable hosts = total − 2. A bigger prefix number means a smaller network.
VisualizerBinary, decimal and subnetsFlip bits to change the address. Then open the subnet calculator and slide the prefix.
8 bits = 256 values
8 bits = 256 values
8 bits = 256 values
8 bits = 256 values
192.168.1.10

Click any bit to flip it, or type a number. Each box is one byte (an octet).

Type
Private
As one number
3,232,235,786
32 bits
Total IPv4 addresses
4.29 billion
2^32
Inside 192.168.0.0/16. Your home router probably uses this.

07How to Use It / Steps / Implementation

How an IP is used in a request

  1. 1
    You type a name
    For example, example.com.
  2. 2
    DNS finds the IP
    The name becomes an address like 93.184.216.34.
  3. 3
    Your device checks the subnet
    Is the target in my own network? If not, send to the router (the default gateway).
  4. 4
    Routers pass the packet along
    Each router looks at the destination IP and picks the next hop.
  5. 5
    The server replies
    It uses your public IP as the destination.

Plan a cloud network

  1. Choose a big private range, like 10.0.0.0/16.
  2. Split it into subnets: public (load balancers), private (app servers), data (databases).
  3. Leave room to grow. Do not use tiny ranges.
  4. Make sure ranges do not overlap with other networks you will connect to.
Example plan: 10.0.0.0/16
🌍Public10.0.1.0/24
🖥️App10.0.2.0/24
🗄️Database10.0.3.0/24
Three subnets for three jobs.

08Key Terms to Know

TermMeaning in easy words
IP addressA number that identifies a device on a network.
IPv432-bit addresses written in 4 dotted numbers.
IPv6128-bit addresses written in hex groups.
OctetOne group of 8 bits (a number from 0 to 255).
SubnetA smaller network inside a bigger one.
Subnet maskShows which bits are network and which are host (for example 255.255.255.0).
CIDRNotation like /24 that gives the number of network bits.
Default gatewayThe router your device uses to reach other networks.
DHCPA service that gives IP addresses automatically.
NATNetwork Address Translation. A router shares one public IP among many private devices.
Loopback127.0.0.1. Your own computer.
MAC addressA hardware address used inside a local network (layer 2).

09Pros, Cons and Trade-offs

✅ Pros
  • Simple, universal way to address devices
  • Subnets give structure and security
  • Private IPs and NAT save public addresses
  • IPv6 gives room for the future
⚠️ Cons
  • IPv4 addresses are nearly used up
  • NAT adds complexity and hides real clients
  • IPs can change (dynamic), so we use DNS names
  • Wrong subnet plans are hard to change later

Trade-offs

ChoiceWe gainWe lose
Big subnet (/16)Lots of room to growWastes addresses, bigger blast area
Small subnet (/28)Tight and neatRuns out of hosts quickly
NAT with private IPsSaves public IPs, hides devicesHarder to connect from outside
IPv6Huge address spaceNeeds support everywhere, people less familiar

10Common Problems and Mistakes

Common mistakes

  1. Overlapping ranges. Two networks that use 10.0.0.0/16 cannot be joined easily.
  2. Choosing a subnet that is too small. You run out of addresses.
  3. Hard-coding IPs. Server IPs change. Use DNS names.
  4. Forgetting the 2 reserved addresses. A /24 has 254 usable hosts, not 256. (Cloud providers may reserve a few more.)
  5. Trusting the client IP. Behind proxies, you must read the real IP from a header such as X-Forwarded-For, and not trust it blindly.
  6. Treating an IP as a person. Many people share one IP behind NAT, and one person can change IPs.
⚔️IP conflict
Two devices get the same address. Both break.
🧯IPv4 exhaustion
We ran short of addresses. NAT and IPv6 are the answers.
🎭IP spoofing
An attacker fakes the source IP.
🕳️Blocked shared IPs
Blocking one IP may block a whole office.

11Real-World Examples

🏠Home Wi-Fi
Your router gives devices 192.168.x.x addresses with DHCP.
☁️Cloud VPCs (AWS, Azure, GCP)
You choose a CIDR block and create public and private subnets.
🔥Firewall allow-lists
Offices share one public IP. Services allow only that IP.
📱Mobile networks
Many phones share a few public IPs through carrier-grade NAT.

12Related Topics to Read Next

OSI Model→

IP lives at layer 3.

DNS→

Turns names into IP addresses.

TCP vs UDP→

Run on top of IP and add ports.

HTTP / HTTPS→

Sent between IP addresses.

Proxy vs Reverse Proxy→

They hide or replace IP addresses.

Anycast Routing→

Many servers share the same IP.

What are Load Balancers?→

One IP in front of many servers.

13Interview Questions with Short Answers

14Quick Revision Cheat-Sheet

  • ✔IPv4: 32 bits, 4 octets, about 4.3 billion addresses.
  • ✔IPv6: 128 bits, hex groups, huge space.
  • ✔Private ranges: 10/8, 172.16/12, 192.168/16.
  • ✔Loopback: 127.0.0.1.
  • ✔CIDR: /n = n network bits. Total = 2^(32 − n). Usable = total − 2.
  • ✔/24 = 256 addresses (254 usable). /16 = 65,536. /28 = 16.
  • ✔NAT shares one public IP. DHCP hands out IPs.
  • ✔Tip: use DNS names, not hard-coded IPs.
← Previous
OSI Model
Next →
TCP vs UDP