Shampoo has a few common components: Surfactants, preservatives and a number of additives meant to give the product desirable properties.
When you wash your hair, you're removing debris and buildup in two steps; the polar components (such as salts and aerosols that land in your hair) are washed away by the water, and the non-polar by the surfactants.
Surfactants are molecules where one side is polar and the other is non-polar. Things with similar polarity like to group together, and the opposite happens with polar/non-polar pairs (I'll call this the 'Like attracts Like rule, it's very important to this particular problem).
These surfactants can group together with each other to form little spheres known as a micelle if there are enough around. This level is known as the critical micelle concentration.
micelle picture http://www.ekshiksha.org.in/images_carbon_its_compund_X/figure_12.JPG
Because the non-polar parts of the surfactants come together, the center of the micelle is also non-polar and can hold small droplets and pieces of other non-polar substances like the sebum that builds up on your hair naturally over time.
Almost all shampoos use a nearly identical set of surfactants. Common examples are sulfates (ammonium lauryl sulfate, Sodium laureth sulfate, sodium pareth sulfate, sodium lauryl sulfate) and/or polysorbates (PEG20 and PEG80).
There are also additives that thicken it up, keep it from going bad and make that rich wonderful lather that we've all come to know and love.
What you are paying for aside from the above is mainly botanical or synthetic additives meant to soothe or beautify. The best way is to look up these ingredients on a case by case basis and decide if they would benefit you. I would say "be wary"; a large number of ingredients provide virtually zero added benefit for your money. Some work extremely well for certain people; you never know until you try.
Always read your labels! If you don't know what something is, google it!