The law, from an enforcement perspective, regulates the daily lives of the people within a society. There are certain rules - laws - which, for the most part, society has deemed good for itself: the protection of lives, property and freedom within society's constraints. When people break those laws, law enforcement officials, particularly police, arrest the perpetrator. If the infractions are minor, people can pay their fines and move on. If they are major, the court system comes into play and, following the law, judges and juries deal appropriate justice. This may include imprisonment, probation and even death.
The laws of the nation are designed to keep the balance of society and make the majority - law abiders - feel safe by placing the minority - law breakers - in jail, on probation or putting them to death.
It is not always fair. Someone who steals money might get more time than someone who kills another person. Or someone who uses drugs might get locked away in the system longer than someone who sells them.
In an ideal circumstance, the law always would both keep society's members safe while dealing fairly and justly with those who infringe upon it.