Computer Networking Fundamentals

Computer Networking Fundamentals: A Complete Guide to Networks, IP Addresses, Subnets, VPNs and Gateways
Introduction
Have you ever wondered how your laptop communicates with another computer? How does your mobile phone connect to the internet? How does a Java application running on one server communicate with a database running on another server?
All these operations are possible because of Computer Networking.
Networking is one of the fundamental concepts in information technology. Whether you are developing web applications, working with Java, building microservices, managing cloud infrastructure, or deploying applications using AWS, understanding networking is essential.
For example, consider an e-commerce application:
- A customer opens an application using a mobile phone.
- The mobile phone sends a request over a network.
- The request reaches the application server.
- The application server communicates with a database.
- The database returns the requested information.
- The application server sends the response back to the mobile phone.
This entire communication process depends on networking.
In this tutorial, we will understand networking from the fundamentals, using real-world examples.
1. What is a Host?
Before understanding networks, we need to understand the term Host.
A host is any device connected to a network that can send or receive data.
In simple words, whenever a device participates in network communication, we can call it a host.
Examples of Hosts
- Desktop computers
- Laptops
- Smartphones
- Printers
- Servers
- Smart TVs
- Smartwatches
- IoT devices
- Network-connected cameras
For example, consider your home Wi-Fi network.
You may connect the following devices:
- One laptop
- Two smartphones
- One smart TV
- One printer
- One smartwatch
All these devices can participate in network communication. Therefore, they are hosts.
Types of Hosts
Hosts generally perform two important roles:
1. Client
A client is a device or application that initiates a request to access a service or resource.
Example:
- A browser requesting a webpage.
- A mobile application requesting customer details.
- A Java application calling a REST API.
2. Server
A server is a device or application that provides services or resources to clients.
Example:
- A web server providing webpages.
- A database server providing stored information.
- A Java Spring Boot application providing REST APIs.
Real-time Example
Imagine opening Amazon using your mobile browser.
- Your mobile phone acts as a client.
- Amazon’s application infrastructure processes your request as a server.
- The server returns the requested information.
Remember: Client and server describe communication roles. A physical computer can act as both a client and a server.
2. What is a Network?
A network in information technology is a group of interconnected devices that communicate with each other to share resources and exchange data.
In simple words:
A network connects multiple devices so that they can communicate and share information.
Real-world Example: Home Network
Consider a house with multiple devices connected through a Wi-Fi router.
- A laptop accesses the internet.
- A smartphone shares files with another device.
- A printer receives printing requests.
- A smart TV streams videos.
All these devices communicate through the network.
Why Do We Need Networks?
Networks are important because they allow us to:
- Share files between computers.
- Share hardware resources such as printers.
- Access applications hosted on remote servers.
- Communicate through email and messaging applications.
- Access the internet.
- Connect databases and application servers.
- Build distributed applications and microservices.
Types of Networks Based on Accessibility
Networks can be broadly understood as private networks and public networks.
Private Network
A private network is used within a restricted environment, such as a home, office, or organization.
Example:
An organization may have an internal network connecting:
- Employee laptops
- Application servers
- Database servers
- Printers
- Internal business applications
Only authorized users and devices should access these resources.
Public Network
A public network is available for communication beyond a restricted private environment.
The Internet is the most common example.
When you access Google, YouTube, or another publicly accessible website, your device communicates through the public internet.
Private Network vs Public Network
| Private Network | Public Network |
|---|---|
| Used within a restricted environment | Used for public communication |
| Access is controlled | Public connectivity is available |
| Common in homes and offices | Example: Internet |
| Supports internal communication | Supports external communication |
3. What is an IP Address?
IP stands for Internet Protocol.
It defines rules for addressing and delivering data across interconnected networks.
An IP address is a logical address assigned to a network interface. It helps identify the source and destination of network communication.
Think of an IP address like a postal address.
If you want to send a parcel to somebody, you need their address. Similarly, when one device sends data to another device, network communication uses IP addresses to identify the source and destination.
For example:
192.168.10.59
This is an IPv4 address.
Why Do We Need IP Addresses?
Imagine an office with 100 computers connected to a network.
If one computer wants to communicate with another computer, the network needs to identify the destination.
IP addresses help the network determine where data should be delivered.
Structure of an IPv4 Address
An IPv4 address contains 32 bits.
It is divided into four groups of 8 bits each.
Each group is called an Octet.
Example:
192.168.10.59
The four octets are:
- First octet: 192
- Second octet: 168
- Third octet: 10
- Fourth octet: 59
Each octet contains 8 bits.
Therefore:
8 + 8 + 8 + 8 = 32 bits.
An IPv4 address is represented in decimal notation for readability, but computers process the underlying binary values.
Binary Representation of an IP Address
Computers work with binary numbers, which contain only 0 and 1.
For example:
192.168.1.152
Its binary representation is:
11000000.10101000.00000001.10011000
Let’s understand how one octet is converted.
Binary positions:
| Bit position | 128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |
|---|---|---|---|---|---|---|---|---|
| Binary value | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 |
Calculation:
128 + 64 = 192.
Therefore:
11000000 = 192
Similarly:
10101000 = 168
This is how an IPv4 address is represented using four decimal octets.
4. What is IPv4?
IPv4 stands for Internet Protocol Version 4.
It is one of the most widely used IP addressing systems.
IPv4 uses 32-bit addresses.
Example:
192.168.10.59
Since each bit can have two possible values (0 or 1), the total theoretical address combinations are:
2³² = 4,294,967,296.
This is approximately 4.3 billion addresses.
Why is IPv4 Limited?
The main problem is that the number of available IPv4 addresses is limited.
Today, billions of devices are connected to the internet.
These include:
- Computers
- Smartphones
- Servers
- Smart TVs
- IoT devices
- Cloud infrastructure
As the number of connected devices increased, IPv4 address availability became a major challenge.
Technologies such as private addressing and Network Address Translation (NAT) help conserve public IPv4 addresses.
However, IPv4’s address space remains limited.
5. IPv4 Address Classes
Traditionally, IPv4 addresses were divided into five classes: A, B, C, D, and E.
This classification is known as classful addressing.
Each class originally had a different default network and host division.
| Class | First octet range | Default subnet mask | Traditional usage |
|---|---|---|---|
| A | 1–126 | 255.0.0.0 | Large networks |
| B | 128–191 | 255.255.0.0 | Medium-sized networks |
| C | 192–223 | 255.255.255.0 | Smaller networks |
| D | 224–239 | Not applicable | Multicast |
| E | 240–255 | Not applicable | Reserved/experimental |
Note: The ranges above describe traditional classful addressing. Certain addresses are reserved for special purposes.
Understanding Network ID and Host ID
An IPv4 address can be logically divided into two parts:
- Network ID
- Host ID
Network ID
Identifies the network to which a device belongs.
Host ID
Identifies a particular host within that network.
For example, in a traditional Class C network:
192.168.10.59
The default subnet mask is:
255.255.255.0
Here:
- Network portion: 192.168.10
- Host portion: 59
The first three octets identify the network, while the last octet identifies the host within that network.
The division depends on the subnet mask or prefix length, not simply on the IP address itself.
Important: Classful addressing is mainly a historical concept. Modern networks use CIDR (Classless Inter-Domain Routing), which allows more flexible network and host divisions.
6. What is IPv6?
IPv6 stands for Internet Protocol Version 6.
IPv6 was introduced to overcome the address-space limitations of IPv4.
While IPv4 uses 32-bit addresses, IPv6 uses 128-bit addresses.
Example IPv6 address:
2001:db8::1
Why Do We Need IPv6?
Consider the growth of internet-connected devices.
We now have:
- Smartphones
- Smartwatches
- Smart home devices
- Cloud servers
- IoT sensors
- Connected vehicles
A 32-bit address space is not sufficient to support the long-term growth of internet-connected devices without additional address-sharing mechanisms.
IPv6 provides a significantly larger address space.
| Feature | IPv4 | IPv6 |
|---|---|---|
| Address size | 32 bits | 128 bits |
| Address format | Decimal | Hexadecimal |
| Example | 192.168.10.59 | 2001:db8::1 |
| Address space | Approximately 4.3 billion | 2¹²⁸ addresses |
| Address notation | Four octets | Eight groups of hexadecimal digits |
IPv6 provides approximately 3.4 × 10³⁸ possible addresses.
This is an enormous address space designed to support the future growth of networking.
7. What is a Public IP Address?
A Public IP address is an IP address that is globally routable on the internet.
It is generally assigned to an internet-facing connection by an Internet Service Provider (ISP), or allocated through an organization that manages IP address resources.
Example:
A company hosts an application on a cloud server and makes it accessible to customers over the internet.
The internet-facing infrastructure uses public IP addressing.
Characteristics of Public IP
- Globally routable.
- Used for communication over the internet.
- Public IPv4 addresses must be globally unique.
- Usually allocated through an ISP or cloud provider.
- Requires appropriate security controls.
8. What is a Private IP Address?
A Private IP address is used for communication within private networks.
For example, your home Wi-Fi router may assign private IP addresses to your devices.
Example:
- Laptop: 192.168.1.10
- Mobile: 192.168.1.11
- Smart TV: 192.168.1.12
- Printer: 192.168.1.13
These devices can communicate within your local network.
Private IPv4 addresses are not directly routable over the public internet.
Private IPv4 Address Ranges
There are three standard private IPv4 address ranges.
| Range | Starting address | Ending address |
|---|---|---|
| Class A private range | 10.0.0.0 | 10.255.255.255 |
| Class B private range | 172.16.0.0 | 172.31.255.255 |
| Class C private range | 192.168.0.0 | 192.168.255.255 |
These are commonly used in:
- Home networks
- Office networks
- Enterprise infrastructure
- Cloud virtual networks
Public IP vs Private IP
| Feature | Public IP | Private IP |
|---|---|---|
| Usage | Internet communication | Internal network communication |
| Scope | Globally routable | Local/private network |
| Assignment | ISP or address allocation provider | Router, DHCP server, or administrator |
| Uniqueness | Globally unique while allocated | Can be reused in different private networks |
| Internet access | Can be directly addressed from the internet, subject to routing and security | Requires routing/NAT for public internet access |
Real-time Example: Home Wi-Fi
Imagine your internet connection works like this:
- Your ISP provides an internet-facing public IP address to your router.
- Your router assigns private IP addresses to connected devices.
- Your laptop accesses a website.
- The router performs Network Address Translation (NAT).
- The request is sent through the public internet.
NAT allows multiple devices using private IP addresses to share a public IPv4 address.
9. What is a VPN?
VPN stands for Virtual Private Network.
A VPN creates a secure connection over an untrusted network, such as the public internet.
It commonly uses encryption to protect network traffic between your device and a VPN endpoint.
Why Do We Need a VPN?
Imagine you are working remotely from home.
Your company has internal applications that are accessible only through its private network.
You need to access those applications securely.
A VPN can establish an encrypted tunnel between your device and the company’s network.
After establishing the connection, you can access authorized internal resources.
How Does a VPN Work?
- You connect to a VPN service.
- The VPN establishes an encrypted tunnel.
- Your network traffic travels through the VPN connection.
- The VPN endpoint forwards permitted traffic to its destination.
- Responses travel back through the connection.
Benefits of VPN
- Protects network traffic through encryption.
- Helps employees securely access corporate resources remotely.
- Can protect traffic on untrusted networks.
- Can change the public IP address visible to destination services.
A VPN does not make a user completely anonymous or guarantee protection against every security threat.
10. What is Subnetting?
Subnetting is the process of dividing a larger IP network into smaller logical networks called subnets.
In simple words:
Subnetting means dividing one large network into multiple smaller networks.
Why Do We Need Subnetting?
Imagine an organization with 500 computers.
If all 500 computers are placed in one large network, managing communication, access control, and network traffic can become difficult.
Instead, the organization can divide its network into smaller subnets.
For example:
- Subnet 1: Development team
- Subnet 2: Testing team
- Subnet 3: Production servers
- Subnet 4: Administration team
Each subnet has its own IP address range.
Benefits of Subnetting
- Better network management.
- Improved network segmentation.
- Easier access control.
- Efficient IP address allocation.
- Reduced broadcast traffic within each subnet.
What is a Subnet Mask?
A subnet mask is a 32-bit value used with an IPv4 address to identify which bits represent the network portion and which bits represent the host portion.
Example:
IP Address:
192.168.10.59
Subnet Mask:
255.255.255.0
Binary subnet mask:
11111111.11111111.11111111.00000000
The binary 1s represent the network portion, and the binary 0s represent the host portion.
In this example:
- Network portion: 192.168.10
- Host portion: 59
The subnet mask tells devices how to determine whether another IP address belongs to the same local subnet.
Understanding CIDR Notation
CIDR stands for Classless Inter-Domain Routing.
Instead of writing the complete subnet mask, we can represent it using a prefix length.
Example:
192.168.10.0/24
Here, /24 means that the first 24 bits represent the network portion.
The remaining 8 bits are available for host addressing.
The corresponding subnet mask is:
255.255.255.0
This notation is widely used in modern networking and cloud infrastructure.
Practical Subnetting Example
Suppose we have the network:
192.168.10.0/24
We want to divide it into four smaller subnets.
We can divide it using a /26 prefix.
Each /26 subnet contains 64 total IPv4 addresses.
| Subnet | Network address | Usable host range | Broadcast address |
|---|---|---|---|
| 1 | 192.168.10.0/26 | .1 – .62 | .63 |
| 2 | 192.168.10.64/26 | .65 – .126 | .127 |
| 3 | 192.168.10.128/26 | .129 – .190 | .191 |
| 4 | 192.168.10.192/26 | .193 – .254 | .255 |
Each subnet contains:
- 64 total addresses.
- 1 network address.
- 1 broadcast address.
- 62 traditionally usable host addresses.
This is how subnetting helps divide a large network into smaller networks.
11. What is a Broadcast Address?
A broadcast address is a special IPv4 address used to send a packet to all hosts within a particular subnet.
For example:
Network:
192.168.10.0/24
Broadcast address:
192.168.10.255
When a device sends a broadcast packet to this address, the packet is intended for all hosts on that subnet.
Broadcast communication is useful for certain network operations, including discovering devices and services.
Note that routers normally do not forward ordinary subnet-directed IPv4 broadcasts between networks.
12. What is a Default Gateway?
A default gateway is the network device, commonly a router, that forwards traffic from a local network to destinations outside that network when no more specific route is available.
In simple words:
A default gateway is the exit point through which a device communicates with other networks.
Real-world Example
Consider your home network:
- Laptop IP: 192.168.1.10
- Mobile IP: 192.168.1.11
- Router IP: 192.168.1.1
Here, the router address 192.168.1.1 is configured as the default gateway.
Suppose your laptop wants to access Google.
- The laptop identifies that Google’s IP address is outside its local subnet.
- It sends the packet to the default gateway.
- The router forwards the packet towards the internet.
- The response returns through the network path.
What Happens Without a Default Gateway?
Devices may still communicate with other devices within their local subnet.
However, they generally cannot communicate with destinations outside their local subnet unless another appropriate route is configured.
13. How Do These Concepts Work Together?
Let’s understand everything through one practical scenario.
Imagine a company hosting an online application.
Its infrastructure contains:
- Employee laptops
- Application servers
- Database servers
- Network routers
- Internet-facing services
The communication works as follows:
- Every network-connected device acts as a host.
- Hosts communicate through a network.
- Each network interface uses an IP address.
- IPv4 or IPv6 identifies the source and destination.
- Private IP addresses are used for internal communication.
- Public IP addresses support internet-facing communication.
- Subnetting separates different network segments.
- Subnet masks determine the network and host portions.
- Broadcast addresses support communication with hosts in a subnet.
- Default gateways forward traffic to other networks.
- VPN connections provide secure remote access when configured.
These concepts form the foundation of modern IT infrastructure.
14. Why Should Java Developers Understand Networking?
Networking is not limited to network administrators.
Java developers work with networking concepts every day.
Consider a Spring Boot microservices application.
Suppose we have three services:
- User Service
- Order Service
- Payment Service
Each service may run in a separate container or on a different server.
When the Order Service needs customer information, it sends an HTTP request to the User Service.
For this communication to work, the underlying infrastructure must provide:
- Network connectivity.
- IP addressing or DNS-based service discovery.
- Appropriate routing.
- Port accessibility.
- Firewall permissions.
Similarly, when a Java application connects to a database, it uses network communication if the database is hosted remotely.
Understanding networking helps developers troubleshoot issues such as:
- Connection refused.
- Connection timed out.
- Unknown host.
- DNS resolution failures.
- Database connectivity problems.
- Service-to-service communication failures.
This knowledge is particularly important when working with Docker, Kubernetes, AWS, and microservices.
15. Important Networking Interview Questions
- What is a computer network?
- What is a host?
- What is the difference between a client and a server?
- What is an IP address?
- What is the difference between IPv4 and IPv6?
- Why is IPv4 address space limited?
- What is the difference between public and private IP addresses?
- What are the three private IPv4 address ranges?
- What is a subnet?
- Why do we need subnetting?
- What is a subnet mask?
- What is CIDR notation?
- What is the difference between a network ID and a host ID?
- What is a broadcast address?
- What is a default gateway?
- What is NAT?
- What is a VPN?
- How does a device communicate with another device outside its local network?
- What happens when a device does not have a default gateway?
- How do microservices communicate with each other over a network?
Conclusion
Computer networking is the foundation of communication between devices, applications, and servers.
Understanding hosts, networks, IP addresses, IPv4, IPv6, public and private IP addresses, VPNs, subnetting, broadcast addresses, and default gateways gives us a strong foundation for working with modern IT infrastructure.
For developers, networking knowledge becomes especially important when building distributed applications, REST APIs, microservices, and cloud-based systems.
Start with the fundamentals, practise IP addressing and subnetting, and gradually explore advanced networking concepts.
Remember: Every application that communicates with another application depends on networking.