We present a full description of the nonergodic properties of wave functions on random graphs without boundary in the localized and critical regimes of the Anderson transition. We find that they are characterized by two critical localization lengths: the largest one describes localization along rare branches and diverges with a critical exponent ν∥=1 at the transition. The second length, which describes localization along typical branches, reaches at the transition a finite universal value (which depends only on the connectivity of the graph), with a singularity controlled by a new critical exponent ν⊥=1/2. We show numerically that these two localization lengths control the finite-size scaling properties of key observables: wave-function moments, correlation functions, and spectral statistics. Our results are identical to the theoretical predictions for the typical localization length in the many-body localization transition, with the same critical exponent. This strongly suggests that the two transitions are in the same universality class and that our techniques could be directly applied in this context.