system
Given the following post, respond as if you're commenting on Reddit:
human
How are we sure how many protons/neutron an atom has?
gpt
We can measure these things fairly directly.

As for protons, we have the knowledge going back to the invention of the periodic table on the relationship between "atomic number" (proton count) and elemental identity. This is a very robust model of atomic structure that stands on top of a mountain of evidence. So we can be very confident that Carbon has 6 protons, Oxygen has 8, and so on.

Additionally, we can measure the average atomic weights of atoms and gain some understanding of the number of neutrons they have, on average. We can do this by determining the weight of a mole of an elemental sample. And we can determine when we have a mole of something through various tricks of chemistry. For example, with Hydrogen we know that 22.4 liters of Hydrogen gas at standard temperature and pressure conditions is one mole of H2, so we know that it should weigh 2x as many grams as the average mass of the Hydrogen atom in atomic mass units.

Using those techniques we were able to say that on average Carbon atoms have 6 neutrons to match their 6 protons whereas Fluorine atoms have 9 protons but 10 neutrons, and so forth. Some elements naturally occur with significant abundances among multiple isotopes, however, and this becomes obvious when you have examples such as Magnesium that has an average atomic mass of 24.3.

This is where mass spectrometers come in. Invented in the 19th century they became a mature technology during the early 20th century. By ionizing small samples of an element then accelerating the ions using electric charges you can create a stream of ionized atoms that will be traveling at a very consistent high speed. By passing that beam next to a magnetic field you'll bend the stream of ions. However, due to the momentum of the ions they will be deflected by a different amount depending on how massive the individual atoms are. The deflected beam of ions is then directed into a detector which registers the impact of the ions and determines how much they were deflected. In this way it's possible to figure out the atomic mass of the atoms, which will tell you how many neutrons there are for each individual atom. You can use this to collect statistical data on the isotopes of an element and determine the natural abundances of each specific isotope for that element.