Abstract: We argue that the gunpowder revolution in medieval Europe encouraged the amal- gamation of smaller polities into larger centralized states. The advance in military technology made existing fortifications obsolete and substantially raised the cost of defensive investments. Small polities lacked the fiscal capacity to make these invest- ments, so they had either to ally or merge with others. Alliances created prospects of free-riding by interior cities on border cities. In contrast, centralized, territorial states benefited from geographic and fiscal economies of scale, facilitating defensive invest- ments at the border that protected the interior while limiting free-riding and resource misallocation. Using a new dataset on fortifications in 6,000 European cities, we find that states made defensive investments in areas of territorial contestation, closer to borders, and farther from raw building materials. These findings are consistent with our theory that large centralized states arose in part as a consequence of changes in military technology.