The number of electron shells in an atom is determined by the number of energy levels that the electrons occupy. Each energy level can hold a maximum of 2n^2 electrons, where n is the energy level number. The first energy level (n = 1) can hold up to 2 electrons, the second energy level (n = 2) can hold up to 8 electrons, and so on.
Oxygen has 8 electrons. The first two electrons fill the first energy level, and the next six electrons fill the second energy level. Therefore, oxygen has two electron shells.