What is the purpose of a subnet mask in IP networking?