A subnet mask defines the range of IP addresses that can be used within a network or subnet. It also separates an IP address into two parts: network bits and host bits.
Subnet masks are used when subnetting, which is when you break a network up into smaller networks. By adjusting the subnet mask, you can set the number of available IP addresses within a network.
For example, a common subnet mask for simple home networks is
255.255.255.0. This subnet mask allows up to 254 usable IP addresses within the home network. In other words, up to 254 computers, phones, and other internet connected devices can connect to your router/network and access the internet.
Subnet masks break an IP address up into network bits and host bits. When a device sees the network and host bits of another device's IP address, it can figure out if the other device is part of the same network (home, business, etc.), or is somewhere else online
Check out this article for more information about subnets, subnet masks, and how they work.