The compound NaCl, which is table salt, is a molecule. It is made up of two different atoms, which are sodium, which is Na on the periodic table, and chlorine, which is Cl on the periodic table. One actual grain of salt is made of many molecules of sodium chloride, but the main structure is two atoms forming an ionic bond to produce sodium chloride or NaCl.
CH4 is one carbon atom and four hydrogen atoms making one molecule of CH4 gas. Mg, which is magnesium, is a pure element on the periodic table and is not combined with any other elements, so it is an atom.