Vindicating a sophisticated but non-rigorous physics approach called the cavity method, we establish a formula for the mutual information in statistical inference problems induced by random graphs and we show that the mutual information holds the key to understanding certain important phase transitions in random graph models. We work out several concrete applications of these general results. For instance, we pinpoint the exact condensation phase transition in the Potts antiferromagnet on the random graph, thereby improving prior approximate results (Contucci et al., 2013) . Further, we prove the conjecture from Krzakala et al. (2007)  about the condensation phase transition in the random graph coloring problem for any number q≥3 of colors. Moreover, we prove the conjecture on the information-theoretic threshold in the disassortative stochastic block model (Decelle et al., 2011) . Additionally, our general result implies the conjectured formula for the mutual information in Low-Density Generator Matrix codes (Montanari, 2005) .