Simple answer - the subnet mask on all the devices in a subnet MUST be the same or you can run into some problems with what they will or will not recognise. It matters not if the mask is 255.255.255.0 or 255.255.0.0 or 255.0.0.0 what is important is that all the machines in that subnet have the same mask.
YES all routers and gateways must have their ports configured to match the subnet that they are attached to via that port.
You can have different masks in different subnets but need a router or gateway with two addressable ports, one on each subnet, that is configured for each subnet.
Although subnet masks are usually set to divide at each byte point they can be set to divide within a byte but this is harder to work out as it must be done based on the binary figures within the byte.
All a subnet mask does is define how many hosts the network sees as belonging to it, and then allows them to talk readily to each other but insists anything else must go to a gateway.
You cna use any IP address range that you want internally provided that you have some sort of gateway between you and the Internet and use Network Address Translation (NAT) in that gateway. Otherwise you have to apply for and get a public IP address class licence to suit your network. Better to set up a router or gateway with NAT and just use the IP address assigned by your ISP.
Three specific address groups have been reserved solely for internal use. It is recommended that you use these as the Internet routers etc are set up NOT to forward on address within these ranges, thus if any traffic gets out by accident it gets dumped at the first router. The internal groups are:
Class C 192.168.0.x for small networks 254 hosts max, mask is usually 255.255.255.0
Class B 172.1.x.x for bigger networks 65,020 hosts max, mask is usually 255.255.0.0
Class A 10.0.0.0 for large networks 16,645,120 hosts max, mask is usually 255.0.0.0