Protons have a +1 charge and electrons have a -1 charge. The overall charge on an atom is 0, therefore there must be an equal number of protons and electrons in an atom so that the charges cancel out. So in chlorine, we can see that the atomic number is 17. This means that each chlorine atom has 17 protons and therefore must also have 17 electrons.
The nucleus of an atom contains protons and neutrons. The nucleus is the main contributor to the mass of the atom, meaning that the mass number can tell us the number of protons and neutrons in an atom. Each proton and neutron has a relative mass of 1 unit. Therefore we can subtract the number of protons from the atomic mass number in order to work out the number of neutrons. Chlorine has a mass number of 35, minus the 17 protons means that chlorine has 18 neutrons.