Look for the hutongs (traditional, alley-based neighborhoods) which are not too far from the wealthy areas, but not right on top of the wealthy areas either. At the outer “lip” of those hutongs there will be numerous small restaurants and food stands, serving a mix of hutong residents and passers-by. A typical small restaurant of this kind might have five to ten tables, plus there may be some larger establishments, comparable in size to small restaurants in the United States. There also will be dumpling, kebab, fish, and other stands facing onto the street. Eat in these places and sample as much as you can. There will be superb snacks for less than a dollar, and in the small restaurants superb main courses for less than two dollars, and in the larger restaurants superb main courses for less than five dollars.
Try an expensive place in a fancy hotel. Eat Yunnan food, preferably at a place with a fixed price menu. “Dali” is a very good one. Eat “Chinese Muslim food.” Eat Sichuan and Hunan. Don’t worry too much about duck, the classic Beijing dish is a little boring. Dumplings are better here but dumplings get only so good (which is very good indeed but the gradient isn’t that steep). Don’t neglect breakfast as an important meal.
That is how you eat well in Beijing.