Comparative segregation analysis holds the potential to provide rich insights into urban socio-spatial dynamics. However, comparisons of the levels of segregation between two, or more, cities at the same point in time can be complicated by different spatial contexts as well as ethnic, racial, and class distributions. The extent to which differences in segregation between two cities is due to differences in spatial structure or to differences in composition remains an open question. This paper develops a framework to disentangle the contributions of spatial structure and composition in carrying out comparative segregation analysis. The approach uses spatially explicit counterfactuals embedded in a Shapley decomposition. We illustrate this framework in a case study of the 50 largest metropolitan statistical areas in the U.S.