The defining difference between a switch and a router is this: A switch uses the destination MAC address to decide where to send the packet, a router uses the destination IP address to decide where to send the packet.
However that description is too short to cover everything a router has to do. Aspects that make the concept of a router more complicated include:
- The answer about where to send a packet is more than just the number of a port, if the port is Ethernet it includes destination MAC and possibly a VLAN tag.
- It cannot just compare the destination address for equality. Each routing table entry has just a prefix of the address.
The switching feature is usually implemented directly in hardware making it capable of handling traffic at wire speed. But routers are too complicated to do everything in hardware, so they will generally also be equipped with a general purpose CPU. High end routers can perform the most performance critical operations in hardware. Low end routers do everything in software limiting their performance to what speed can be achieved on the CPU.
Combining the two in a single box is certainly possible. I have seen one example of a router with just two ports where each of the two ports is then internally hooked up to a five port switch such that externally the box has eight Ethernet interfaces.
A typical CPE these days put a modem, a router, a switch, and an AP into a single box. They still are four different network components, so what do you call the box containing all four of them? In such a box the CPU used to implement the router functionality then gets another task to do, because it also has to run a configuration interface which is used to configure all of the components.