subnetting is to create a fast, efficient, and resilient computer network. As networks become larger and more complex, the traffic traveling through them needs more efficient routes.
IP addresses help to identify the pieces of hardware connected to your network. To locate a particular device you would need to organize the IP addresses in a logical way. This is where subnetting excels as a tool to help you maintain efficiency across your network.
There could be hundreds of thousands of devices that are connected within a network. This means that the corresponding IP addresses can create a complex route that traffic has to travel. Subnetting limits the IP address usage to within a few devices. This allows an engineer to use subnetting to create sub-networks, sorting data so that it can travel without touching every part of the more complex routers. In order to do this, an engineer needs to match each IP address class to a subnet mask.
More info @ How does subnetting work