How did we differentiate lights from stars? I got this question while watching the COSMOS TV series. I couldn't find the right answer in google.  

I read about Stellar classification and it states that we can classify the stars based on their spectral characteristics. My question is how can we be sure of which particular star the light is coming from. Since Earth is getting light from so many stars How the the light is classified?  Even if we can get different spectra then how can find their exact sources?
If two lights are shining in your room, one red and one blue, how do you know which one is red and which is blue?  

If you look at the two lights, the lens in your eye will focus the red light at a different place from the blue light, so you can see two lights in different places. Even though the light that reaches your eye is mixed, the lens can separate the light.

Telescopes have lenses (or curved mirrors that do the same thing). The light from different stars is focused by the telescope, to form an image, and so the light from different stars is separated. The light from individual stars can then be split into colours. This is the star's spectrum. 

The job of the telescope is two-fold: collect a lot of light and then focus it so that individual objects can be seen and analysed individually.

There are many ways of classifying a spectrum, Stars have continuous spectra crossed by dark lines. The temperature of the star changes the spectrum, the stars are classified in order O B A F G K M from hottest to coolest. Nebula sometimes have emmission spectra which looks mostly dark, crossed by bright lines.