There were Marshals, City Marshals, and Constables who were employed by the local townspeople and whose authority was restricted to within the town or city limits. Then there were the County Sheriffs, who were elected by the citizens of the county, to keep the peace within the county. The United States Marshals were appointed by the President of the United States and had the authority to operate anywhere in the USA and deal with federal crime. Each of these law enforcement officers employed their own deputies, all of whom had the same powers of enforcement.
Some believed that former criminals would make the most effective lawmen. Consequently, in some cases notorious gunfighters were employed as town marshals to help bring law and order to some of the most lawless of towns. These lawmen dealt with the likes of the Dalton Gang and the James Brothers, who thought nothing of raping and murdering innocent people.
The requirements needed to be a peace officer in the Wild West were often determined only by the individual's skill with a gun, and their courage. At times judgment was needed with only seconds to determine it, and that also meant that there was the odd occasion where justice and law never quite meant the same thing. The expression "justice without law" was never truer than in the formative years of the West.