This paper investigates endogenous network formation by heterogeneous agents. The agents' types determine the value of linking and we incorporate spillovers as utility from indirect connections. We provide sufficient conditions for a class of networks with sorting to be stable for low to moderate spillovers; with only two types these networks are the unique pairwise stable ones. We also show that this sorting is suboptimal for moderate to high spillovers despite otherwise obeying the conditions for sorting in Becker 1973. This shows that in our sorted networks a tension between stability and efficiency is present. We analyze a policy tool to mitigate suboptimal sorting.