I'm new to computer networking and from what I've studied, I've understood that Forwarding tables map MAC addresses to ports. So they are used by switches. Routing tables map IP to IP ..they define the next hop which should be used to send data. So they are used by routers. ARP tables map IP address to MAC addresses . My question is which of these tables a host (including router) needs to have ? It's clear that ARP has to be there. But I studied somewhere that all hosts have their local routing tables ...why? By using subnet mask a host can determine whethera destination address is local or on some other network. If it is on some other network it needs to know the default gateway IP . Is local routing table used for storing only the default gateway IP?
all hosts have their local routing tables ...why?
In addition to its local loopback interface, a host can have more than one external interface and on each interface more than one gateway. It needs to be able to make a routing decision, albeit with a usually very small routing table. Using a default gateway is only the simplest (and most common) scenario.
Checking an interface subnet mask and prefix to determine whether to use a gateway or send directly (be its own gateway) already uses the local routing table.
If you look at it closely it's a very simple algorithm: for each entry in the routing table, apply the network mask and compare the prefixes. If equal then use the indicated interface & gateway. If gateway==local interface IP then send directly out of that interface.
In complement to @Zac67 answer, take the case of a user than connect (to the workplace for example) through a VPN. It now has 2 options to send traffic to remote networks: sending the traffic as usual to its local gateway or send it trough the VPN tunnel.
How can the host choose? Well, by looking up in its routing table, which is updated when the VPN tunnel connect / disconnect.
Regarding local routing tables, why are they needed?
Even though a host is not a router, if it is connected to the Internet, it would need to participate in the IP routing procedures. IP routing happens in a distributed way. Imagine for an IP packet to get from host A to host B, through one or more routers R1, R2, .. in between. Host A would need to create the IP packet. It would also need a local routing table in order to know how to get the IP routing started, towards host B.
In many cases, the local routing table is very simple, with only the loopback interface to itself, and the default gateway IP. Everything that is not "known" from other entries, goes to the default gateway. Where there is only the loopback interface and default gateway, then, the destination address of host B would not match the loopback, and so, would by default go out through the default gateway.
It is done with a local routing table to support a lot of flexibility, such as having more than one interfaces, e.g., if the host is has an Ethernet interface and a WiFi interface, and some traffic goes through one, some through the other. Or, if there is a VPN, it can be reflected through some kind of virtual interface in the local routing table as well.
Basically, a local routing table is like an IP routing table in a router, except that the source packets are all from the local host. As far as using the table to decide where to send the IP packet, it is very similar to an IP routing table in a router. However, in a host, it is not taking in IP packets from other hosts and forwarding them out (using the same routing table), as a router would do.