A subnet mask is a way of splitting a network up into smaller mini networks without wasting IP addresses.
In a standard home/small office network your router can normally support up to 250 devices and you can use subnetting to separate parts of the network from each other, whilst still allowing all devices to access the internet.
Why do we need subnet masks?
Subnet masks break up networks into smaller mini sub-networks without wasting IP addresses.
Also Breaking a large network up into smaller network reduces the network traffic because network broadcasts only go out other parts of the subnet, not the whole network. Without this a large network would be susceptible to a broadcast storm, where large amounts of broadcasts can seriously impede the performance of a network.
Having subnets of a larger network is more secure and also easier to troubleshoot as only part of a network would be affected by network issues.