Subnetting works both for public and private IP addresses. But in order to be able to access the Internet, NAT (Network Address Translation) is used.

Note that aside from NAT, a router does not change anything in an IP address. It just uses a routing table to know where to forward data across subnets.