This paper investigates the problem of optimal districting in the context of a simple model of legislative elections. In the model, districting matters because it determines the seat-vote curve, which describes the relationship between seats and votes. The paper first characterizes the optimal seat-vote curve and shows that, under a weak condition, there exist districtings that generate this ideal relationship. The paper then develops an empirical methodology for computing seat-vote curves and measuring the welfare gains from implementing optimal districting. This is applied to analyze the districting plans used to elect U.S. state legislators during the 1990s.