Since a IPv4 address already gives the information of the network and and host, why do we still need a subnet mask?

The 1st Octet already specify the network class (1-127: A, 128-191: B, 192-223: C etc.). A, B, or C implies the number of octets for network (respectively,,,, which automatically tells you how many hosts is allowed for each class of network.

The IP gives all the information a subnet mask has, and more. Why do we need subnet mask in the first place? If the information a subnet contains is not entirely a subset of that inside an IP, then what else does it contain or what in addition does the subnet do, that require us to specify it independently?

  • 21
    Class A, B, C are so 1980's and long dead. As address exhaustion came into being, it was realized that a lot of assigned Class A and B space was totally wasted on the holders, hence CIDR and the given assignment of small, useable blocks of addresses throughout the whole address space. Feb 27, 2012 at 3:19
  • 2
    @FiascoLabs That does not answer his question dude. Did Routers still use those subnet masks? Yes with classful(if no further subnetting, which is perhaps unlikely), the subnet mask can be calculated from the address. But a)is it necessary to use a subnet mask with a logical AND, if you already know how many bits you want, and Why is that? Probably doen to CPU operations not being able to test for x bits of a byte, so others have to be zeroed out and the EQU operator is applied.
    – barlop
    Feb 27, 2012 at 3:21
  • 8
    The routers I've worked with don't assume that the first octet of Class A, B or C mean anything. I've always had to set a netmask or CIDR to let the router know the addresses where the net and broadcast were located. Of course Class address assignments have really easy netmasks,, and, so yes, it is necessary to use a subnet mask. Feb 27, 2012 at 3:33
  • VLSM - variable length sumbet masks, you can create a network or broadcast domain as big or as small as you would like!
    – Mark S.
    Feb 27, 2012 at 10:25
  • 3
    Even in the days of classes, you could have a large network subnetted (sic) into various other smaller ones. A workstation in a large university would still have an address in a class A network, but it could a subnet of a subnet of a subnet of the entire class A. So naturally routers made no assumptions.
    – Alexios
    Feb 27, 2012 at 11:49

10 Answers 10


We need a subnet mask for IPv4 addresses because the address doesn't give any information on the network size. Class sizes are not the network sizes. In practical networks all IPv4 networks are broken up into subnets that are smaller than the class size.

For example you could break up the class C network into two smaller networks (potentially at separate locations) and assuming neither needed more than 126 hosts. In reality most companies only get enough IPv4 addresses for the servers that need to be on the public Internet. I've personally seen set ups with 32,16, & 8 address networks (that would be masks of,, & respectively)

Having IP networks only in class size blocks was too restrictive in limited the number of networks that could be allowed - the 127 class A networks taking half of the space. Not to mention that having a 24 billion node network is completely unmanageable Instead in 1993 Classless Inter-Domain Routing (CIDR) was introduced to allow the networks to be split up.

Also to be clear the purpose of the subnet mask is to determine which hosts are on the local network and which are outside of the network. Hosts can talk directly to hosts on the same network, but they need to communicate with a router to talk to hosts on external networks.

  • when using CIDR you attaching a prefix to specific the number of bits used for network addressing, and the rest for host addresses. For example,, then automatically implies host address has to be 63 or lower. Again, the IP still tells you this piece of information, hence, persist my question...
    – KMC
    Feb 27, 2012 at 4:54
  • It's still an address and a netmask when all's said and done and that's what the underlying hardware uses to calculate it's netblock, does it not? Feb 27, 2012 at 5:31
  • My question is persist because the IP still contains all the information that a subnet mask necessary to have. I still find no reason for subnet mask to exist at all.
    – KMC
    Feb 27, 2012 at 6:05
  • 2
    @KMC: I do not really get your comment, a CIDR prefix is comparable to a subnet mask and software, thus, often uses either the prefix or the mask, as a matter of taste.
    – Legolas
    Feb 27, 2012 at 8:47
  • 22
    @KMC: /27 is the subnet mask, just written in a different notation.
    – Heinzi
    Feb 27, 2012 at 9:06

The 1st Octet already specify the network class (1-127: A, 128-191: B, 192-223: C etc.). A, B, or C implies the number of octets for network (respectively,,,, which automatically tells you how many hosts is allowed for each class of network.

Right, but if someone were to subnet that network, you'd need the subnet mask to know how big a subnet you were in. Yes, with classful addressing, the class tells you the size of the network and allows you to tell whether a host is in the same network as you, but if that network is subnetted, without the subnet mask, how would you know whether another node is in the same subnet as you?

Say you're on an Ethernet network. We use classful addressing with subnetting. Your IP address is and you want to reach Do you use ARP to reach that address? Well, it depends on whether and are in the same subnet. Even if they're in the same network, if there in different subnets, a router needs to be used. If they're in the same subnet, then ARP should be used.

So you need the subnet mask if subnetting is in use, even with classful networks.

I think you're confusing subnetting with CIDR, actually. Without CIDR, even with subnetting, you don't need the subnet mask between administrative regions. But you still need it inside the network!


A subnet mask is used to do a bit wise operations on an IP address, in conjunction with a network address. If my memory serves me well, you take an IP address and do a bit wise AND on it and the subnet mask for a given network. If the result equals the network address, then the IP address is on that particular network. Routers that have routing tables of network addresses and subnet masks can use simple binary maths (which is very fast, if not the fastest for computers to handle) to find out which interface to punt a packet out of.


Except for @Adrian's answer I'm not sure any of these actually mention WHY we use the mask instead of some simpler to understand solution--and he only touched on the fact that masking is FAST, I mean why not just specify that you are interested in addresses, or why not just use names like *.my.address.com for this, just naming each computer instead of assigning numbers?

You actually could now to some degree completely remove numbers from routing, most PCs could handle the kinds of traffic they are sent, but there is still a problem on the larger scale devices.

Filtering like this is happening all the time, and it's happening a LOT. Masking can be done in hardware, completely eliminating the need to waste time on uninteresting packets (which used to be 99% of the packets you'd have pass through your wire, now with switched hubs you shouldn't see any that aren't addressed to your machine, again making it less relevant).

For a solution that is so easy on the hardware it is also very flexible. The same hardware can route an entire class A network (10.x.x.x) or just one or two ip addresses with the same implementation.

This is not a replacement for any of the other answers, just a little more info.

  • "why not just use names like *.my.address.com for this, just naming each computer " - you mean, like, DNS? Feb 27, 2012 at 19:28
  • @Piskvor Exactly! DNS resolves to IP addresses, you could use DNS directly but the processing power used goes up. You could even sub-divide domains so that *.meh.com goes to one address except *.alt.meh.com goes to another...
    – Bill K
    Feb 27, 2012 at 20:57
  • That works, yes - that is, when it works (additional complexity); plus you need to know where the DNS server is; chicken-and-egg problem. Feb 28, 2012 at 6:16
  • @Piskvor I'm just saying that there are other possibilities that would work fine except for performance--still significant in some cases--and the fact that it would require re-writing EVERYTHING. (Do you really think the problem with a DNS server would be any different if you switched to a different addressing scheme?)
    – Bill K
    Feb 28, 2012 at 17:12
  • No, the problem would indeed persist. (and btw, the push for a simple networking stack is not going away - quite the contrary, getting stronger with the "internet of things": simple also means less power needed and longer battery life) Feb 28, 2012 at 17:25

"The 1st Octet already specify the network class (1-127: A, 128-191: B, 192-223: C etc.)."

There aren't many protocols in common use today that respect this anymore (see @Fiasco Labs comment - RIP is the only one I can think of). So, this statement in your question:

The IP gives all the information a subnet mask has, and more.

is not true for the great majority of protocols in use in the Internet today.

If you have a number of machines that are connected to each other, and only ever communicating with each other, with no router ever involved, then the subnet mask isn't really needed (although modern TCP/IP stacks insist you specify one).

Routers define the edges of (sub)networks. Anything needing to go through a router is on a different network - and vice versa: anything needing to go to a different network needs to go through a router.

The subnet mask is how all machines can tell whether traffic is for the current network or needs to be sent to a router to get to its destination. Your computer's TCP/IP stack will send its traffic directly to the destination if it's within the subnet mask, otherwise it consults its routing table, and the usual situation is that sends other traffic to the default gateway.


The 1st Octet already specify the network class (1-127: A, 128-191: B, 192-223: C etc.). A, B, or C implies the number of octets for network (respectively,,,, which automatically tells you how many hosts is allowed for each class of network.

While this was historically true. This hasn't been true for years. Years ago was given out in pieces to various ISPs. (I believe this was mostly to cable providers.)

Even when it was true for network assignments, netmasks were necessary for internal networks to simplify routing. Efficient routing of a network like requires subdivision into smaller networks. This may be a simple scheme using /16 and /8 subdivisions, but is more likely to be classless subdivision. Larger subnets make more efficient use of address space (over 99% of a /24 is available for devices, while only 50% of a /30 is available.

The local network is routed directly from the device, while other addresses are passed through a router. Hosts with multiple interfaces may be connected to networks of different sizes.

For sub-nets without multi-homed hosts a /24 contains more addresses than is required. Most routers I have worked with have 24, 48, or 96 ports and can be supported with /27, /26, or /25 sub-nets. This allows some extra addresses for DCHP and/or multi-homing. Organizations may standardize on allocating sub-nets of /24 or /23 for routing.

Since a IPv4 address already gives the information of the network and and host, why do we >still need a subnet mask?

Many devices use a default netmask of /24 which in many cases matches the size of the local subnet (localnet) assigned to the router. This is equally applicable to classes A, B, and C. Unless the subnet size matches the default subnet a netmask is required.

If addresses are specified using CIDR format, the netmask and network can be calculated from the address. If not the network can be calculated from the address and netmask. It is not possible to reliably calculate the netmask from the address and network.

Providing a gateway (router) address for a subnet allows the default route to be configured allowing routing to addresses outside the subnet.


There are already many things explained in other answers, but not the main thing.

You want to know, if IP address can already give you full address of the recipient, then why subnet masks exist. You know, in large organizations, sometimes departments need separate networks, so, for example, accountants are in a different subnet and cannot access marketing department's inner IP addresses. So, for example, an employee with the IP wouldn't be able to access the printer at, because it would be in a different subnet.


To date, there's still no answer as to why subnets (as opposed to CIDR) are still in use. There's two problems with subnet masks:

  1. you can specify non-contiguous masks, which are invalid.
  2. (also applies to CIDR) they introduce possible overlap - ISPs could give out the same IP address as part of different subnets. e.g.

    customer A: subnet mask
    customer B:   subnet mask

which isn't immediately visible as should be.



My study notes, it's my nth time trying to understand this topic:

  • I guess the last link answer my question why I couldn't play my LAN games if I set the wrong subnet mask 20 years ago.
    – Sida Zhou
    Jun 28, 2021 at 9:53

Noramally, subnet mask works as an indicator to the below subnetworks. usually a network contains several subnets and the subnet mask is the way, the router uses, to deliver traffic to the specific destination (in any subnet using the subnet mask) this link contains an introduction to Subnet masks

  • 1
    Please add the important information from the link to here, add the link as source.
    – avirk
    Mar 23, 2014 at 8:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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