Before every packet leaves, your computer asks one question: is this destination on my street? Yes means deliver it directly through the switch. No means hand it to the default gateway, the router’s address on your street (a door you cannot reach is not a door).
The subnet mask is how the computer answers. Where the mask says 255, that part of the address is street. Where it says 0, that part is house. So 255.255.255.0 under 192.168.10.5 means the street is 192.168.10 and the house is 5. Change the mask and you move the end of the street. With 255.255.0.0, the street becomes 192.168, and 192.168.20.6 suddenly counts as same street. Same two addresses, different mask, different answer.
Basically, the mask decides where the street ends. One street is one network and one broadcast domain. Every machine on that street has to stop and read every broadcast. Too many machines on one street, and they spend the day listening to shouting. So we cut big streets into smaller ones. Week five only draws the line between street and house. Later weeks take the line apart bit by bit. The skill that matters first is hearing the question: same street?