IPv4 Address consist of 4 numbers separated by dot(.). Each number ranges from zero to 255. Each number is an octet (each octet is of 8 bit) and that is why maximum range of each number is 255.
Since each Number is an octet and there are 4 numbers in IPv4 address so IPv4 Address is a 32 bit Address

Every device like computer, printer or router is assigned with IPv4 Address in order to uniquely identify in the network.
IPv4 address divided in to two parts
1) Network Part
2) Host Part

Left part of IPv4 Address is Network part and right part of IPv4 Address is Host part. Now the question is how much left part of IPv4 Address is Network part and likewise for Host part. Here comes the role of Subnet Mask or Mask.

Let us take an example to understand how Subnet Mask tells how much the left part of IPv4 address is Network and how much is Host.

In Subnet Mask, 255 is present for first 3 Number, so 10.8.12 becomes the network part of IPv4 Address and 9 becomes host part.
10.8.12.0 becomes the Network Address and 10.8.12. <1-255> can be the IP address assigned to the hosts in 10.8.12.0 network.
Above IP Address with Subnet mask 255.255.255.0 can be represented like 10.8.12.9/24 since first 24 bits(3 Octets) are masked as per the subnet mask.

Here zero in host part cannot be assigned as it represent in Network Address.

Let say if the subnet mask is 255.255.0.0, then IP Address will be represent as 10.8.12.9/16 and its Network address will be 10.8.0.0

There are some observations from above discussion
1. Subnet mask is all 255 and then 0. This is a property of mask. It should be contiguous i.e. all 1’s and then 0’s. It cannot be like 255.0.255.0. This is not a valid subnet mask.

2. IP Address will always be represented by below format:

Till now we have used simple subnet mask i.e. 24 or 16 bits mask and we can easily differentiate the Network and Host part of IP Address.
But what if the mask is of 20 bits ? How will we segregate the Network and Host part of IP Address?
if the mask is of 20 bits, the subnet mask will be:
255.255.240.0
255: represent all 1 8 bits( 1111 1111)
255: represent all 18 bits( 1111 1111)
240: remaining 4 bits(1111 0000)

For this you need to understand the Decimal to Binary and Binary to Decimal conversion i.e. how to convert 240 in to binary format 1111 0000.