The number of protons and electrons is the same in an atom because of the fundamental nature of electric charge and the overall electrical neutrality of atoms.
Protons have a positive electrical charge, while electrons have a negative electrical charge. According to the laws of physics, opposite charges attract each other, and like charges repel each other.
In an atom, the protons are located in the nucleus, which is at the center, while the electrons orbit around the nucleus in energy levels or electron shells. The attraction between the positively charged protons in the nucleus and the negatively charged electrons keeps the electrons bound to the atom.
For an atom to be electrically neutral, the positive charge of the protons must balance out the negative charge of the electrons. This means that the number of protons, which determines the atomic number of an element, must be equal to the number of electrons in a neutral atom.
If an atom gains or loses electrons, it becomes an ion with a net positive or negative charge. In such cases, the number of protons and electrons is no longer equal, and the atom is said to be ionized. However, in a neutral atom, the number of protons and electrons always remains the same to maintain electrical neutrality.