If you are talking about a switch that has IP addresses on, it this implies you are speaking about what’s known as a Layer-3 switch. Layer 3 switches have something called “Switch Virtual Interfaces” (SVIs) which are just logical interfaces–they don’t necessarily correspond to physical ones. An SVI is paired with a particular vlan. So, for example, you could have a VLAN 168, and you would assign ip address 192.168.1.1 to that VLAN. The syntax to do this is:
(config)#interface vlan 168
(config-if)#ip address 192.168.1.1 255.255.255.0
You can repeat this for any number of vlans you want. So, for, say, VLAN 10:
(config)#interface vlan 10
(config-if)#ip address 10.10.10.1 255.255.255.0
Next, you can assign a particular physical switch port to a vlan, in this case Fa0/1 to VLAN 168
(config-if)#switchport mode access
(config-if)#switchport access vlan 168
Now, if you plug in a device to port Fa0/1, and configure it to use an IP in the range of 192.168.1.2 - 192.168.1 254, it will be able to use the SVI for vlan 168 (192.168.1.1) as its gateway to get elsewhere.
If you repeat this process by assigning another physical port to VLAN 10, configure a host plugged into that port in the 10.10.10.0/24 range, then the hosts on ports 1 and 2 will be able to talk even though they are in different subnets.