For instance, if switch A has hosts with mask /25 and switch B has hosts with /26. Will a ping from Host A to host B be successful?

How does the situation change if:

  1. Both switches are connected to a router and a default gateway is provided to all hosts.

  2. The subnets are of different classes altogether (/10 and /25)

  • Sorry if the question is too noobish or silly !
    – john
    Sep 24, 2016 at 1:21
  • You might try to re-title the question to "IP connectivity between hosts with differing subnet masks?" Sep 24, 2016 at 4:02
  • You changed the question, and that is very bad form. You have answers to the original question, and those answers can now be orphaned because they answered a different question. If you intend to ask a different question, you should start a new question.
    – Ron Maupin
    Sep 24, 2016 at 4:34
  • I do not intend to ask another question, i have changed just the title of the question because another member prompted me to do so, I thought he suggested this because that would be the normal convention to frame questions on this site and my title wasnt clear enough. No other reason. !
    – john
    Sep 24, 2016 at 4:51
  • @john You did not change the question, you refined it. Refining questions is not bad form. Most of all, know that this particular SE is low traffic volume which enhances the negative experience many have here. However, all in all, you can learn things here. Your question is not a bad one and does not deserve a downvote. You got trolled. Just don't respond to trolling and they go away. Sep 24, 2016 at 14:15

2 Answers 2


For instance, if switch A has hosts with mask /25 and switch B has hosts with /26. Will a ping from Host A to host B be successful?

That depends.

Normally each host will check the desintation address for it's packets against the "network" defined by it's IP and mask. If they are within that network they get sent "directly", otherwise they do to the default gateway.

So if host A is within what host B thinks is it's network and host B is within what host A thinks is it's network the ping will succeed.

Further complicating matters some operating systems will try and send packets directly if no default gateway is configured or the default gateway is set to the clients own IP.

IF a router is introduced and packets are sent to it it may router the packets between the hosts. If the router knowns the hosts are on the same network it may may also issue ICMP redirects to tell the clients they can talk directly.


Answer to your original question:

If two switches are a part of different subnets, will they exchange messages if directly connected?

Switches don't look beyond the layer-2 frame to the layer-3 addresses to make decisions on where to switch frames, so the switches play no part in your scenarios, other than to switch frames to the ports where the destination layer-2 addresses are connected.

What you need to look at is how the hosts are configured. A host will compare its network with the network of the destination address to see if they are the same. If they are in the same network, according to the mask configured on the interface, the host will ARP for the destination layer-2 address, or get it from its ARP cache. If the destination address is on a different network, the host will send the packet to its configured gateway.

Answer to your new question (please, do not change your question after you have answers to the original question):

IP connectivity between hosts with differing subnet masks?

If one of the networks is contained within the other network, there are two possible answers:

  1. If both host addresses fall within the range of the smaller network, then there will be no problem communicating from either host to the other. A ping from one host to the other will succeed.
  2. If one of the host addresses is not within the smaller network, then the host from the larger network can send something to the host in the smaller network, but the host in the smaller network will send anything destined for the host in the larger network to its configured gateway because it knows that it is in another network. By default, a ping from one host to another will fail because the host in the smaller network will send a ping request or ping reply to its configured gateway, but a router may possibly be configured to send an ICMP redirect to tell the host in the smaller network to send it directly to the other host.

If you have hosts in two completely separate networks, any packets destined from one host to the other will be sent to the configured gateway of the sending host.

  • So, if they are in the SAME network, The host will send the an ARP request for the destination. Assuming that it got the response from the Server, the net hop of the packet will still be the router or the switch it is connected to, so does the host already know the MAC address of the switch or the router ?
    – john
    Sep 24, 2016 at 1:39
  • The switch is a transparent device, so the host does not need to know the layer-2 address of the switch. A router (gateway) is just another host on the network, so a host will treat it as such as far as ARP. It all depends on whether or not the host discovers that the destination address is on the same network, or not, as to which layer-2 address the host finds to put on the frame. The switches deliver frames based on the layer-2 destination addresses on the frames.
    – Ron Maupin
    Sep 24, 2016 at 1:44
  • I m sorry I didnt completely understand the last part, for simplicity lets say they are in the same network, assigned contiguous addresses without any subnets. What happens in this case ?
    – john
    Sep 24, 2016 at 2:02
  • Switches don't care about layer-3, including IP, addresses. A switch will only look at the layer-2 address on a frame, and it makes its decision where to deliver the frame based on that. End of story about the switch. A host needs to build a layer-2 frame for each layer-3 packet. To do that, it needs to resolve the layer-3 address to a layer-2 address. It uses ARP (Address Resolution Protocol). If the destination IP address is in the same network as the host, it will find the layer-2 address of the destination host, otherwise it will find the layer-2 address of its configured gateway.
    – Ron Maupin
    Sep 24, 2016 at 2:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.