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, 255.0.0.0, 255.255.0.0, 255.255.255.0), 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 24.0.0.0/8 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 10.0.0.0/8 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.
21Class 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. – Fiasco Labs – 2012-02-27T03:19:47.867
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 – 2012-02-27T03:21:26.330
8The 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, 255.0.0.0, 255.255.0.0 and 255.255.255.0, so yes, it is necessary to use a subnet mask. – Fiasco Labs – 2012-02-27T03:33:42.247
VLSM - variable length sumbet masks, you can create a network or broadcast domain as big or as small as you would like! – Mark S. – 2012-02-27T10:25:33.110
3Even 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 – 2012-02-27T11:49:16.000