We show that fractality in complex networks arises from the geometric self-similarity of their built-in hierarchical community-like structure, which is mathematically described by the scale-invariant equation for the masses of the boxes with which we cover the network when determining its box dimension. This approach - grounded in both scaling theory of phase transitions and renormalization group theory - leads to the consistent scaling theory of fractal complex networks, which reveals a collection of scaling exponents and different relationships between them. The exponents can be divided into two groups: microscopic (hitherto unknown) and macroscopic, characterizing respectively the local structure of fractal complex networks and their global properties. Interestingly, exponents from both groups are related to each other and only a few of them (three out of seven) are independent, thus bridging the gap between local self-similarity and global scale-invariance of fractal networks. We successfully verify our findings in real networks situated in various fields (information – the World Wide Web, biological – the human brain, and social – scientific collaboration networks) and in several fractal network models.