Much recent work has focused on community detection, or the task of identifying sets of similar nodes from network topology. Underlying this work is the implicit assumption that inferred communities inform node attributes or function in a meaningful and useful sense. We investigate these ideas by phrasing community detection as Bayesian inference, which gives rise to a scalable and efficient variational algorithm for fitting and comparing network models. We show how several existing methods for community detection can be described as variant, special, or limiting cases of our work, and how the method overcomes the "resolution limit" problem, accurately recovering both the structure and scale of modular networks. We apply the resulting algorithm to several real networks and study the relationship between identified topological communities and known node attributes.