In astronomy and physical cosmology, the metallicity or Z is the fraction of mass of a star or other kind of astronomical object that is not in hydrogen (X) or helium (Y). Most of the physical matter in the universe is in the form of hydrogen and helium, so astronomers use the word "metals" as a convenient short term for "all elements except hydrogen and helium". This usage is distinct from the usual physical definition of a solid metal. For example, stars and nebulae with relatively high abundances of carbon, nitrogen, oxygen, and neon are called "metal-rich" in astrophysical terms, even though those elements are non-metals in chemistry.
The distinction between hydrogen and helium on the one hand and metals on the other is relevant because the primordial universe is believed to have contained virtually no metals, which were later synthesised within stars.
Metallicity within stars and other astronomical objects is an approximate estimation of their chemical abundances that change over time by the mechanisms of stellar evolution, and therefore provide an indication of their age. In cosmological terms, the universe is chemically evolving. According to the Big Bang Theory, the early universe first consisted of hydrogen and helium, with trace amounts of lithium and beryllium, but no heavier elements. Through the process of stellar evolution stars first generate energy by synthesising metals from hydrogen and helium by nuclear reactions, then disperse most of their mass by stellar winds or explode as supernovae, dispersing the new metals into the universe. It is believed that older generations of stars generally have lower metallicities than those of younger generations, having been formed in the metal-poor early universe.