You can calculate IPv4 subnet masks by hand if you so desire, but it is much easier to just use a SubnetCalculator!
I have coded this app to help IT colleagues. Basically it has very simple bit processes.
If you consider the subnet mask as one string then (all in binary):
Network Address AND Subnet Mask = Network ID
Network ID + 1 (binary) = First Host
Network ID + Available Hosts (binary) = Last Host
Network ID + Available Hosts (binary) + 1 (binary) = Broadcast
You can apply the mask under the Menu or just change the Number of Network bits in the combo box.
This is the first version(0.1) and coded in C#. Hope to add more features in the soonest time and would like to code in Python!
You can download it as portable app from this link