As far as I know, in 9th grade, you are only familiar with Bohr's Atomic Model, but actually, Bohr's atomic model only holds for single electronic species like Hydrogen and Hydrogen like ions (example: $\ce{He+, Li^{2+}, etc.}$). For multi-electronic species like all elements after hydrogen, Schrodinger model takes over.
Now, shells contain subshells and subshells contain orbitals. You might know what a shell is. The shells start from $\ce{K}$, then $\ce{L}$, $\ce{M}$, $\ce{N}$ and so on... These shells contain subshells, labelled as $\ce{s, p, d}$ and $\ce{f}$. The $\ce{K}$ shell contains only one subshell $\ce{s}$, while the $\ce{L}$ shell contains both $\ce{s}$ and $\ce{p}$, and so on...
Now, these subshells contains orbitals. Electron is actually in orbitals. Each orbital contains $2$ electrons. The $\ce{s}$ subshell contains only $1$ orbital and hence maximum number of electrons in $\ce{s}$ subshell is $2$. The $\ce{p}$ subshell contains $3$ orbitals (so, total $6$ electrons), similarly $\ce{d}$ subshell contains $5$ and $\ce{f}$ subshell contains $7$ orbitals.
So, now you can tell that $\ce{K}$ shell contains maximum $2$ electrons, while in $\ce{M}$ shell, there are maximum $8$ electrons ($\ce{M}$ shell contains both $\ce{s}$ and $\ce{p}$ subshells, so $2$ from $\ce{s}$ and $6$ from $\ce{p}$, total $8$).
Why 8 electrons are required for stability?
So, for this, I would say, $8$ electrons are required in outermost shell for stability only for elements upto Calcium (atomic number $20$) in Mordern Periodic Table. For elements after that, $\ce{d}$ block comes into play and octet rule seems to not be followed by these atoms.
For Hydrogen and Helium, they only have $\ce{K}$ shell, so, they can only fill upto $2$ electrons to gain stability, that's why they follow Duplet Rule instead of Octet Rule.
For elements with atomic numbers $3$ to $20$, they have both $\ce{K}$ and $\ce{M}$ shell. Their $\ce{K}$ shell is filled, and outermost shell $\ce{M}$ can only contain max $8$ electrons, that's why its stated that for stability, $8$ electrons are required. But as you can see, this rule is only valid for elements from atomic numbers $3$ to $20$. When a shell is completely filled, it has maximum stability and minimum energy.
Why Fully Filled shells have more stability?
- Electron Repulsion: Electrons are negatively charged, so they naturally repel one another. In a partially filled shell, this repulsion is stronger because electrons are more likely to be unpaired or unevenly distributed, causing instability. When a shell is fully filled, the electrons are more evenly spread out within the shell, reducing the overall electron-electron repulsion.
- Symmetry: Fully filled shells are more symmetrical, and symmetrical systems tend to be lower in energy because they are more balanced. This symmetry minimizes the forces between electrons and between electrons and the nucleus, reducing the energy required to maintain the atom’s structure.
- Electrostatic Attraction to the Nucleus: In a fully filled shell, the attraction between the electrons and the positively charged nucleus is maximized while repulsions between electrons are minimized. This creates a state of balance where the system doesn't have excess energy, making it less likely to react with other atoms.
These are major reasons why Fully Filled shells are more stable.
I hope this clears your doubt. I think you will get a more clear idea on this when you come in $11$th grade in Science Stream, as it is taught in a little bit of detail there.