Centralized sanctioning institutions are of utmost importance for overcoming free-riding tendencies and enforcing outcomes that maximize group welfare in social dilemma situations. However, little is known about how such institutions come into existence. In this paper we investigate, both theoretically and experimentally, the endogenous formation of institutions in a public goods game. Our theoretical analysis shows that players may form sanctioning institutions in equilibrium, including those where institutions govern only a subset of players. The experiment confirms that institutions are formed frequently as well as that institution formation has a positive impact on cooperation rates and group welfare. However, the data clearly reveal that players are unwilling to implement institutions in which some players have the opportunity to free ride. In sum, our results show that individuals are willing and able to create sanctioning institutions, but that the institution formation process is guided by behavioral principles not taken into account by standard theory.