Some human groups are organized hierarchically and some are distributed. Both types of groups occur in economic, political, and military domains, but it is unclear why hierarchical organizations are favored in certain contexts and distributed organizations are favored in others. I propose that these different organizational structures can be explained by human groups having different constraints on their ability to foster cooperation within the group. Human within-group cooperation is often maintained by monitoring and punishment. In hierarchical groups, monitoring and punishment are organized into tree-like command-and-control structures with supervisors responsible for monitoring the cooperation of their subordinates and punishing non-cooperators. By contrast, in distributed groups, monitoring is diffuse and punishment is collective. I propose that the organization of cooperative human groups is constrained by the costs of monitoring and punishment. I formalize this hypothesis with a model where individuals in a group cooperate to produce public goods while embedded in a network of monitoring and punishment responsibilities. I show that, when punishment costs are high and monitoring costs are low, socially-optimal monitoring and punishment networks are distributed. The size of these distributed networks is constrained by monitoring costs. However, when punishment costs are low, socially-optimal networks are hierarchical. Monitoring costs do not constrain the size of hierarchical networks but determine how many levels of supervision are required to foster cooperation in the hierarchical group. These results may explain the increasingly large and hierarchical groups throughout much of human history. They also suggest that the recent emergence of large-scale distributed organizations has been possible because new technologies, like the internet, have made monitoring costs extremely low.