I could simplify and say, “with experience”, but that’s not the whole story.
Understanding code requires understanding the language, the paradigm, the domain, and the owners. Let’s consider each of these:
- Language - The programming language consists of syntax, libraries, and best practices. The more you’ve worked in a language the easier it gets to understand other code. As you excel in one language though you’ll find you slowly gain the ability to read other languages with less work.
- Paradigm - Above the language are the various programming paradigms used in the software. If it’s a paradigm you’ve not seen before it will be harder to understand. Fortunately there are a limited number of fundamental approaches, so you can learn them all — though there are an unlimited number of variations, but those you can glean from the project itself.
- Domain - Different domains have different approaches to how software is used and written. Video games are quite different than business apps and system libraries. Reading code within a domain you know is obviously easier than one you don’t. In time, as you learn more domains you’ll find it easier to pick up on new ones quickly.
- Owners - This is the human element to the understanding. Projects have a lot of different managerial approaches and personality types, these reflect heavily on how the code looks. As you work with more people you’ll get a better insight into why some decisions are made, and how the software is structured.
The key to understanding code is in variety. Not the amount of experience, but the breadth of your experience, will determine how easy it is to grasp new project.
Taken from my answer to this question at Quora