None of what I described is automatic, it would all need to be configured.
A hub and a switch are in fact two different pieces of equipment. Hubs are old technology and aren't sold anymore, but you may occasionally come across one in the wild.
Basically a hub would take traffic it received on any port and send it out all it's other ports. A switch maintains a table of MAC addresses of all the different pieces of equipment connected to it and which MAC address is on which physical port. It looks at the destination MAC address of traffic coming in a port and sees if that address is on another port, if it knows about it it sends the traffic to only that port. There are some traffic types that are sent out all the ports, except the one it was received on, on a switch, those being broadcasts and multicasts. Most of the switches that are available in retail stores are what are termed, dumb switches. This means they can't be managed or changed in any manner. More advanced "managed" switches allow it's configuration to change. These switches allow for the creation of VLANs. A VLAN is just a grouping of physical ports, and ports on a specific VLAN can only send and receive traffic to other ports on the same VLAN. You can think of it like multiple switches in one physical box.
IP addressing runs at a different layer. If a client is trying to reach another machine, it sends out an ARP request. This is basically a mapping of an IP address to a MAC address. If the IP the client is trying to reach is on a different subnet, the ARP will be for the IP address that is configured as it's gateway IP so it can send traffic to the router. So if you had two IPs on different subnets assigned to a single router port, clients on both subnets would see the same MAC address for their gateway IP in their ARP tables.