Networks vs Subnetworks

ipip addressipv4networkingsubnet

Can a computer with an IP address of class C like 192.168.0.1 and subnet mask 255.255.255.0 communicate and share resources with another computer having the IP 192.168.1.1 and the same subnet mask 255.255.255.0 ? I'm asking this because the first 3 octets in this case tell us that these IPs are running on different networks (network 192.168.0.0 and network 192.168.1.0).
Also, does "network" mean the same thing as "subnetwork" (or "subnet") in this context?
Thank you!

Best Answer

To fully understand how computer networks work, you need to take a look at OSI model (or in practice - TCP/IP or DoD model. For your question you need to look at first three layers: physical, data link and network.

Physical connection is self explanatory, and represents direct connection via some medium (copper, glass, air).

When a host A tries to send a packet to host B first thing it will do is look at the destination IP address and based on it's own IP configuration determine if host B is in the same subnet as a host A. This is done as Eugen Rieck explained to you already: subnet mask bits are used to mask the bits of the IP address (logical AND operation). Now, we have two cases:

  1. Host A and B are in the same subnet.
  2. Host A and B are not in the same subnet.

You should note that on layer 2, which network adapters use to send and receive frames, there is no IP addresses (which are present on layer 3) but instead the communication between devices is done by using MAC addresses. Because of that, host can directly communicate only with hosts in their subnet (1st scenario). For sending a frame host A needs the MAC address of host B. So host A first looks up the MAC address mapped to the IP address of host B in his ARP table. If he can't find it, it sends broadcast ARP request asking all host on the subnet who has that specific IP. If he gets a response it adds the MAC address of the host he got the reply from and builds a packet with destination MAC address of that host and IP address of that host.

If both hosts are not in the same subnet (2nd scenario) the packet is sent to default gateway which is responsible for finding a route to the destination. The crucial point to make here is that even if the destination MAC address in this case is the MAC address of the router (default gateway), the destination IP address is still the IP address of host B as in the first scenario. As the packet flows from router to router the source and destination MAC addresses will change, as they are locally significant, but the source and destination IP address will stay the same. This is how every layer provides a service (so to speak) to upper layers, and upper layers use it transparently without needing to know what is happening below.

So you have:

1st scenario.

----------------
L2:
Src MAC: host A
Dst MAC: host B
----------------
L3:
Src IP:  host A
Dst IP:  host B
----------------

2nd scenario:

----------------
L2:
Src MAC: host A
Dst MAC: router
----------------
L3:
Src IP:  host A
Dst IP:  host B
----------------

To sum it up (the answer @Eugen Rieck already gave you):

Two hosts which are not in the same subnet as in your example (192.168.0.1/24 and 192.168.1.1/24) will not be able to communicate on layer 2, and will require a L3 capable device such as router to act as a default gateway and to route the traffic between two networks (broadcast domains) for layer 3 connectivity.

Related Topic