Centralized sanctioning institutions are of utmost importance for overcomingnfree-riding tendencies and enforcing outcomes that maximize group welfare in socialndilemma situations. However, little is known about how such institutions come intonexistence. In this paper we investigate, both theoretically and experimentally, thenendogenous formation of institutions in a public goods game. Our theoretical analysisnshows that players may form sanctioning institutions in equilibrium, includingnthose where institutions govern only a subset of players. The experiment confirmsnthat institutions are formed frequently as well as that institution formation has anpositive impact on cooperation rates and group welfare. However, the data clearlynreveal that players are unwilling to implement institutions in which some playersnhave the opportunity to free ride. In sum, our results show that individuals arenwilling and able to create sanctioning institutions, but that the institution formationnprocess is guided by behavioral principles not taken into account by standard theory.