system
Given the following post, respond as if you're commenting on Reddit:
human
How do we know the composition and mass of some planets/stars ?
gpt
In terms of composition. We're looking at a technique called spectroscopy. Basically, for any chemical element (or larger structures like molecules but when you're talking about stars it's too hot for molecules), the electrons can only have specific energies. 




For each chemical the gaps between the available energies will be unique, this means we can identify a chemical by the gaps between its energy levels. 




But how do we know what the gaps in energy level are? Good question. Electrons move between energy levels by either absorbing or emitting energy. One of the ways this can happen is by photons (light). Because the gaps between energy levels are specific sizes only specific energies of photons can be absorbed or emitted. 

When it comes to photons their energy is also proportional to their frequency (because photons have wavelike properties as well as existing as distinct particle like things) and the frequency of light determines its colour. 

Either we put in light at a range of wavelengths and see what's absorbed or look at the light being emitted. This works for both stars and atmospheres of planets.