Summary: Can communal heterogeneity explain persistent educational inequities in developing countries? The paper uses a novel data-set from rural Pakistan that explicitly recognizes the geographic structure of villages and the social makeup of constituent hamlets to show that demand for schooling is sensitive to the allocation of schools across ethnically fragmented communities. The analysis focuses on two types of social barriers: stigma based on caste affiliation and female seclusion that is more rigidly enforced outside a girl's own hamlet. Results indicate a substantial decrease in primary school enrollment rates for girls who have to cross hamlet boundaries to attend, irrespective of school distance, an effect not present for boys. However, low-caste children, both boys and girls, are deterred from enrolling when the most convenient school is in a hamlet dominated by high-caste households. In particular, low-caste girls, the most educationally disadvantaged group, benefit from improved school access only when the school is also caste-concordant. A policy experiment indicates that providing schools in low-caste dominant hamlets would increase overall enrollment by almost twice as much as a policy of placing a school in every unserved hamlet, and would do so at one-sixth of the cost.