The subnet mask gives you all of the info you need to take any IP address and figure out a lot about the subnet it's on. Let's take an example question from subnettingquestions.com :
Which subnet does host 10.0.93.159 with a subnet mask of 255.255.240.0 belong to?
Let's start with the subnet mask. A binary 1 in the mask means that's a network number in the IP address and a binary 0 means that it's part of the host range. A 255 in decimal means that those parts are all 1s, so you can just copy over the IP address directly on those octets (groups of 8 bits between the periods). So right off the bat you know that the IP address for the network is 10.0.<something>.
We need to figure out what 240 is in binary. Once you know how many bits you have you can determine how many hosts are in the range. Decimal 240 translates to 11110000 in binary. A single bit can be on or off, so that can represent two numbers- in this case IP addresses. So every time you add a 1 or a 0 you double the amount of numbers you can get. Two binary digits can make a 0, 1, 2, or a 3. Three binary digits can give you those four plus 4, 5, 6, and 7- etc.
So to figure out the total amount of addresses you can get from a certain number of host bits (the zeros in the subnet mask) you just multiply by 2 for every 0. Since there are four 0s the number of hosts will be 2x2x2x2 or 16. It's important to remember that you count by 16 in the correct field. In our case we started in the 3rd octet with 240 so that's where we count by 16. We already know the address starts with 10.0, so we'll start there.
10.0.0.0, 10.0.16.0, 10.0.32.0, 10.0.48.0, 10.0.64.0, 10.0.80.0, 10.0.96.0
There, we went past the host's address of 10.0.93.159. Counting by 16 like that (which we got from the subnet mask) has given us our range for the subnet. 10.0.80.0 - 10.0.95.255 (the range goes all of the way to just before the start of the next subnet). Now, we know the Network number and we know the broadcast address for the network (the very last address is the broadcast address for a network).
We still need to figure out the number of hosts in the subnet. We can use the same multiply by 2 method from before, but we have to count the zeros from the last octet and remember the network address and the broadcast address. We have 4 zeros from the 3rd octer and 8 from the last octet, so 12 zeros in total. 2x2x2x2x2x2x2x2x2x2x2x2 or 4096. After subtracting 2 for the network and broadcast addresses that leaves 4094 valid host addresses.
Now we know a lot about that subnet by just using those 2 numbers.