We study core-periphery structure in networks using inference methods based on a flexible network model that allows for traditional onionlike cores within cores, but also for hierarchical treelike structures and more general non-nested types of structures. We propose an efficient Monte Carlo scheme for fitting the model to observed networks and report results for a selection of real-world data sets. Among other things, we observe an empirical distinction between networks showing traditional core-periphery structure with a dense core weakly connected to a sparse periphery, and an alternative structure in which the core is strongly connected both within itself and to the periphery. Networks vary in whether they are better represented by one type of structure or the other. We also observe structures that are a hybrid between core-periphery structure and community structure, in which networks have a set of nonoverlapping cores that roughly correspond to communities, surrounded by a single undifferentiated periphery. Computer code implementing our methods is available.