2182 words
11 minutes
Subnetting, DHCP, and Port Allocation

Introduction#

Subnetting, DHCP, and port allocation are three fundamental networking concepts that work together to make networks functional, organized, and secure. These topics are essential for understanding how devices communicate and how network administrators manage large networks.


Part 1: Subnetting#

What is Subnetting?#

Subnetting is the process of dividing one large network into smaller networks called subnets. It is done to make the network easier to manage, more secure, and more efficient.

IP Address Structure#

Every IP address has two parts:

PartPurpose
Network portionIdentifies the network
Host portionIdentifies the device inside that network

Subnet Mask#

A subnet mask is used to separate these two parts. For example:

  • 255.255.255.0 (traditional notation)
  • /24 (CIDR notation)

Both mean: the first 24 bits are for the network and the remaining bits are for hosts.

Key Benefit#

All devices in the same subnet can communicate directly without needing a router.


Important Subnetting Terms#

Core Concepts#

TermDefinitionExample
IP AddressUnique address of a device on a network192.168.1.100
Subnet MaskShows which bits are network, which are host255.255.255.0 or /24
CIDR NotationShortened form indicating network bits/24, /26, /30
Network AddressThe first address in a subnet192.168.1.0
Broadcast AddressThe last address in a subnet192.168.1.255
Usable Host RangeIP addresses available for devices192.168.1.1 to 192.168.1.254

Practical Example#

If you have 192.168.1.0/24:

Network address       = 192.168.1.0
Broadcast address     = 192.168.1.255
Usable host range     = 192.168.1.1 to 192.168.1.254
Total usable hosts    = 254 devices

Why Subnetting is Used#

Organizational Benefits#

Subnetting is used to organize networks properly:

  • A company may want separate subnets for HR, IT, students, guests, or servers
  • Keeps traffic organized and makes network control easier
  • Improves security by separating departments

Technical Benefits#

  1. Reduces broadcast traffic — Broadcast messages stay within a subnet
  2. Improves performance — Less unnecessary network traffic
  3. Increases security — Separate subnets can have different security policies
  4. Saves IP addresses — Assign exactly what you need instead of wasting addresses

Routing Benefits#

Routers use subnet information to decide where packets should go:

  • Without subnetting, a large flat network would be harder to control
  • Creates unnecessary traffic
  • Makes network scalability impossible

How Subnetting Works#

Borrowing Bits#

Subnetting works by borrowing bits from the host portion of an IP address and using them to create more network bits.

Key principle:

  • More subnet bits = more subnets (but fewer hosts per subnet)
  • More host bits = fewer subnets (but more hosts per subnet)

Examples of Subnet Sizes#

CIDRSubnet MaskHosts per SubnetUse Case
/24255.255.255.0254Standard small office/department
/26255.255.255.19262Smaller departments
/28255.255.255.24014Small workgroups
/30255.255.255.2522Point-to-point links (routers)
/16255.255.0.065,534Large enterprise network

Subnet Size Trade-off#

Borrowing more bits for network:
/24 → /26 → /28 → /30

More subnets created ↑
Hosts per subnet    ↓

Subnetting Examples#

Example 1: Basic /24 Network#

Network:     192.168.1.0/24
Mask:        255.255.255.0
First host:  192.168.1.1
Last host:   192.168.1.254
Broadcast:   192.168.1.255
Total hosts: 254

Example 2: Smaller /26 Subnets#

Original: 192.168.1.0/24 can be divided into four /26 subnets:

Subnet 1:    192.168.1.0/26     (1-62)
Subnet 2:    192.168.1.64/26    (65-126)
Subnet 3:    192.168.1.128/26   (129-190)
Subnet 4:    192.168.1.192/26   (193-254)

For router-to-router connections:

Subnet:      192.168.1.0/30
Hosts:       192.168.1.1 (Router A)
             192.168.1.2 (Router B)
Only 2 usable IPs needed

Part 2: DHCP (Dynamic Host Configuration Protocol)#

What is DHCP?#

DHCP means Dynamic Host Configuration Protocol. It is a network service that automatically assigns IP addresses and other network settings to devices.

Docker Architecture

Without DHCP#

Every device would need to be configured manually:

  • Network administrator assigns each IP manually
  • Time-consuming and error-prone
  • Changes are difficult to make
  • Not scalable for large networks

With DHCP#

DHCP automatically gives devices:

  • IP address — Unique address for the device
  • Subnet mask — Network configuration
  • Default gateway — Router for external traffic
  • DNS server information — For domain name resolution

Where DHCP is Used#

  • Homes with WiFi networks
  • Schools and universities
  • Office networks
  • Hotels and public WiFi
  • Any network where devices frequently join and leave

The DHCP Process (DORA)#

Four-Step Process#

The DHCP process usually follows four steps, remembered as DORA:

Step 1: Discover#

Client                              DHCP Server
   │                                    │
   ├──── DHCP Discover (broadcast) ────>│
   │    (looking for DHCP server)       │
   │                                    │

The client broadcasts a request looking for a DHCP server.

Step 2: Offer#

Client                              DHCP Server
   │                                    │
   │<──── DHCP Offer ─────────────────┤
   │      (IP: 192.168.1.105)          │
   │      (masks, gateway, DNS)        │
   │                                    │

The server offers an available IP address with network settings.

Step 3: Request#

Client                              DHCP Server
   │                                    │
   ├──── DHCP Request ─────────────────>│
   │      (accept offered IP)           │
   │                                    │

The client requests the offered address.

Step 4: Acknowledge (ACK)#

Client                              DHCP Server
   │                                    │
   │<──── DHCP ACK ────────────────────┤
   │      (IP lease confirmed)          │
   │      (lease time: 24 hours)        │
   │                                    │

The server confirms the lease and network settings.

DORA Summary Table#

StepSenderMessagePurpose
DiscoverClientBroadcast requestFind DHCP server
OfferServerOffer IP + settingsPropose configuration
RequestClientAccept offerRequest specific IP
ACKServerConfirm leaseComplete assignment

DHCP Lease#

What is a Lease?#

The IP address assigned by DHCP is usually not permanent. It is given for a certain period called a lease.

Lease Characteristics#

IP Address Assigned ──→ Lease Active ──→ Lease Expires
    │                      │                    │
  DHCP gives IP         Device uses IP      Device loses IP
                       for lease period    (if not renewed)

Lease Renewal#

When the lease ends, the client may:

  • Renew the same IP address
  • Get a new address from the DHCP server

Why Leases Exist#

  1. Reuse addresses — If device disconnects, address can be reassigned
  2. Efficient IP usage — Network administrators can reuse limited addresses
  3. Clean network — Old devices automatically lose IPs
  4. Flexibility — Addresses can be redistributed as needed

Typical Lease Times#

DurationUse Case
8 hoursShared public networks (libraries, cafes)
24 hoursOffice networks
7 daysHome networks
1 hourTemporary devices

DHCP Scope#

What is a DHCP Scope?#

A DHCP scope is the range of IP addresses the server can assign to devices.

Example#

DHCP Scope: 192.168.1.100 to 192.168.1.200
Available addresses: 101 IPs for devices

DHCP Server Manages#

ItemPurpose
Reserved addressesIPs for specific devices (printers, servers)
Excluded addressesIPs never to be assigned
Lease timesHow long each device keeps its IP
OptionsGateway, DNS, domain name, etc.

Multiple Subnets Need Multiple Scopes#

In a network with multiple subnets, each subnet usually needs its own DHCP scope.

Why? DHCP must assign addresses that match the correct subnet:

Subnet 1 (192.168.1.0/24)
└─ DHCP Scope: 192.168.1.100-200

Subnet 2 (192.168.2.0/24)
└─ DHCP Scope: 192.168.2.100-200

Subnet 3 (192.168.3.0/24)
└─ DHCP Scope: 192.168.3.100-200

DHCP Reservation#

What is a DHCP Reservation?#

A DHCP reservation means the server always gives the same IP address to a specific device based on its MAC address.

Example#

Device: Printer (MAC: 00:1A:2B:3C:4D:5E)
Always gets: 192.168.1.50

Server recognizes the MAC address
and assigns the same IP every time

Useful For#

  • Printers — Need consistent IP for drivers
  • Servers — Should maintain stable addresses
  • Important devices — Critical equipment needs reliable IPs
  • Scanners and copiers — Need known addresses for configuration

Benefits#

  1. Convenience — Automatic configuration (DHCP)
  2. Stability — Fixed address (no IP changes)
  3. Best of both worlds — Combines DHCP ease with static IP reliability

DHCP and Subnetting Relationship#

How They Connect#

DHCP and subnetting are closely connected:

  • A DHCP server must assign an IP address that belongs to the correct subnet
  • The IP must match the subnet mask of where the device is located

The Challenge#

If the device is on a different subnet from the DHCP server:

  • A relay agent or helper address is often needed
  • Forwards DHCP requests to the correct DHCP server
  • Ensures device gets an IP from its own subnet

Example#

Device on Subnet 2
(192.168.2.0/24)

     └─→ DHCP Relay Agent

            └─→ DHCP Server (on Subnet 1)

                    └─→ Assigns 192.168.2.X
                         (IP from Subnet 2 scope)

Planning Subnets and DHCP#

Subnetting design must be planned carefully:

Too SmallJust RightToo Large
Devices run out of addressesEnough IPs for growthNetwork becomes messy
Frequent conflictsOrganizedHard to manage
InefficientEfficientInefficient

Part 3: Port Allocation#

What is Port Allocation?#

Port allocation is the process of assigning port numbers to different services running on a computer. A port helps identify which application should receive network traffic on a machine.

The Concept#

ItemIdentifies
IP AddressWhich device on the network
Port NumberWhich service/application on that device

Example#

Server: 192.168.1.50

Services running:
├─ Web (HTTP)     → Port 80
├─ Web (HTTPS)    → Port 443
├─ SSH            → Port 22
└─ DNS            → Port 53

Packet to 192.168.1.50:80 → Web Server
Packet to 192.168.1.50:443 → Secure Web
Packet to 192.168.1.50:22 → SSH Server
Packet to 192.168.1.50:53 → DNS Server

Why Port Allocation Matters#

One server can have one IP address but many services. Ports distinguish between them.


Port Numbers and Categories#

Port Range#

Port numbers range from 0 to 65,535 (65,536 total ports).

Three Categories#

CategoryRangeUsageExamples
Well-known0–1,023Standard servicesHTTP(80), HTTPS(443), SSH(22)
Registered1,024–49,151ApplicationsCustom apps, databases
Dynamic/Private49,152–65,535Temporary, clientsClient applications

Common Well-Known Ports#

PortServiceProtocol
20, 21FTPTCP
22SSHTCP
25SMTPTCP
53DNSTCP/UDP
80HTTPTCP
110POP3TCP
143IMAPTCP
443HTTPSTCP
3306MySQLTCP
5432PostgreSQLTCP

Why Categories Exist#

  • Avoid conflicts — Standard ports are reserved
  • Organization — Clear structure for services
  • Security — Prevents accidental port conflicts
  • Scalability — Enough ports for any network

How Port Allocation Works#

Service Listening#

When a server application starts, it listens on a specific port:

1. Application starts

2. Binds to port (e.g., port 80)

3. Listens for incoming connections

4. When client connects, traffic goes to this application

Example Flow#

Browser                         Server (192.168.1.50)
   │                                    │
   ├─ Connect to 192.168.1.50:80 ─────>│
   │                          (port 80 is HTTP)
   │                                    │
   │<────── Web Server responds ────────┤
   │        (running on port 80)        │
   │                                    │

Port Conflicts#

If two services try to use the same port on the same IP address:

Service A: trying to bind to port 80
Service B: already using port 80

ERROR: Port already in use
Service A cannot start

Solution: Assign Service B to a different port (like 8080).


Importance of Port Allocation#

Multiple Services on One Computer#

Port allocation allows multiple services to run simultaneously:

Web Server
├─ HTTP  → Port 80
├─ HTTPS → Port 443
└─ Admin → Port 8080

Database
└─ MySQL → Port 3306

All running at same time
All using same IP address
Identified by different ports

Network Security#

Firewalls use ports to control access:

Allow port 80 (HTTP)
Allow port 443 (HTTPS)
Block all others

Only web traffic allowed
Other services protected

Real-World Uses#

Port allocation is important for:

UseBenefit
Separate servicesKeep different apps isolated
Secure accessFirewall can allow/block specific ports
Control trafficRouters direct traffic based on ports
Manage serversAdmin can run multiple services
Support communicationClient-server can use specific ports

Port Binding and Application Configuration#

How Applications Bind to Ports#

# Web server configuration
Server listens on 0.0.0.0:80
(any IP on this machine, port 80)

# When client connects to 192.168.1.50:80
Kernel directs traffic to listening application

Example Configurations#

Web Server    → Port 80
Web Server 2  → Port 8080
Database      → Port 3306
SSH Server    → Port 22
FTP Server    → Port 21

Port Mapping in Docker#

In containerized environments, ports are mapped:

Host Port : Container Port
8080 : 80

External: 192.168.1.50:8080

Container: localhost:80

Web server inside container

Subnetting, DHCP, and Ports Together#

How These Three Work Together#

These three topics are connected in real networking:

Subnetting

    └─→ Divides network into logical sections (192.168.1.0/24)

            └─→ DHCP assigns addresses in the subnet (192.168.1.105)

                    └─→ Port allocation identifies services (port 443, 80, 22)

Real-World Example#

Scenario: A user connects to work VPN

1. DHCP gives laptop an IP:        192.168.1.105
2. Subnet configuration is:         /24 (belongs to 192.168.1.0/24)
3. Laptop connects to web server via port 443 (HTTPS)
4. DNS server found via DHCP:      192.168.1.1:53

Everything works together!

Network Architecture#

┌─────────────────────────────────────────────────┐
│ Company Network: 192.168.0.0/16                 │
│                                                  │
│  ┌──────────────────┐  ┌──────────────────┐   │
│  │ Subnet 1: /24    │  │ Subnet 2: /24    │   │
│  │ DHCP Scope:      │  │ DHCP Scope:      │   │
│  │ 100-150          │  │ 100-150          │   │
│  └──────────────────┘  └──────────────────┘   │
│                                                  │
│  Services on each device:                      │
│  Port 80   (HTTP)                              │
│  Port 443  (HTTPS)                             │
│  Port 22   (SSH)                               │
│  Port 3306 (Database)                          │
└─────────────────────────────────────────────────┘

Comparison Summary#

Simple Comparison#

TopicMain RoleExample
SubnettingDivides a large network into smaller parts192.168.1.0/24
DHCPAutomatically gives IP configurationAssigning 192.168.1.105
Port AllocationIdentifies services on a deviceHTTP on 80, SSH on 22

What Each Solves#

ProblemSolutionHow
Network too largeSubnettingDivide into /24, /25, etc.
Manual IP configDHCPAutomatic assignment
Multiple services conflictPort AllocationUse different ports

Their Relationships#

Subnetting
    └─→ Defines network boundaries

            └─→ DHCP assigns IPs within boundaries

                    └─→ Ports allow multiple services per IP

Quick Reference Guide#

Subnetting#

ConceptKey Point
Network/Host splitSubnet mask determines which bits are network
/24 notation24 network bits, 8 host bits
BroadcastLast address in subnet (cannot assign)
Usable rangeFirst+1 to Last-1
ReasonOrganize, secure, and optimize networks

DHCP#

ConceptKey Point
DORADiscover, Offer, Request, Acknowledge
LeaseIP is temporary, not permanent
ScopeRange of IPs available to assign
ReservationAssign same IP to specific MAC address
RelayForward DHCP across subnets

Port Allocation#

ConceptKey Point
Port range0-65,535 total ports
Well-known0-1,023 for standard services
Registered1,024-49,151 for applications
Dynamic49,152-65,535 for clients
ListeningService binds to port to accept connections

Short Revision Notes#

Subnetting#

  • Subnetting splits a network into smaller subnets
  • Subnet mask separates network and host parts
  • /24 means 24 network bits, 8 host bits
  • Useful for organization, security, and IP efficiency

DHCP#

  • DHCP automatically assigns IP addresses and network settings
  • DHCP uses Discover, Offer, Request, and ACK
  • Lease means IP is temporary
  • Scope is the range of assignable IPs
  • Reservation gives same IP to specific device

Ports#

  • Port allocation assigns port numbers to services
  • IP address identifies the device, port identifies the service
  • Well-known ports (0-1023) are standard services
  • Prevents conflicts between multiple services

Easy Memory Tricks#

ConceptMemory Trick
SubnettingDivide the network into smaller pieces
DHCPGive the IP automatically, not manually
Port allocationChoose which service gets the traffic
DORADiscover → Offer → Request → Acknowledge
/2424 bits for network, 8 bits for hosts
Well-knownPorts 0-1023 are reserved for standard services
LeaseIP is borrowed, not owned
ReservationMAC address gets same IP every time

Decision Trees#

When to Use What?#

Subnetting Decisions#

Network too large?
└─ Yes → Need subnetting
         Divide by department, location, or function

How many devices?
├─ Few (< 30) → Use /26 or /27
├─ Medium (30-100) → Use /24
└─ Many (100+) → Use /22 or larger

DHCP Configuration#

Device needs IP?
├─ Many devices, frequently changing → Use DHCP
├─ Important device, needs same IP → Use DHCP + Reservation
└─ Must be absolutely fixed → Use static IP

Multiple subnets?
└─ Yes → Need DHCP relay agents

Port Selection#

Running a web server?
├─ Public HTTP → Port 80
├─ Secure HTTPS → Port 443
└─ Testing only → Port 8080

Custom application?
└─ Use port 1024+ (registered/dynamic)

Summary#

Subnetting, DHCP, and port allocation are the three pillars of network organization:

Subnetting#

  • Divides large networks into manageable pieces
  • Improves security and efficiency
  • Uses subnet masks and CIDR notation

DHCP#

  • Automates IP address assignment
  • Uses DORA process (4 steps)
  • Works with subnets through scopes

Port Allocation#

  • Enables multiple services on one device
  • Uses standardized port numbers
  • Prevents service conflicts

Working Together#

These three create a complete networking infrastructure where:

  • Networks are properly divided (subnetting)
  • Devices get IPs automatically (DHCP)
  • Services are accessible via ports (port allocation)

Key Takeaway#

All three must work together for a network to function properly. Subnetting creates the structure, DHCP fills it with devices, and ports make services accessible.

Subnetting, DHCP, and Port Allocation
https://ryo11blog.netlify.app/posts/subnetting-dhcp-port-allocation/
Author
Ranjung Yeshi Norbu
Published at
2026-03-06