I have studied from various sources that router is a layer 3 device. It does routing based on Network layer (layer 3) header, but I have a doubt.
Network address translation (NAT) is a feature of Router which is required for routing traffic. It does processing based on both Network layer and Transport layer (layer 4) headers. So why cant we say that router is a layer 3 & layer 4 device when it is processing layer 4 header also?
Best Answer
That is completely incorrect. NAT is a kludge (a clumsy, inefficient solution) designed to extend the life of IPv4 addressing until IPv6 is ubiquitous. NAT breaks the IP paradigm of end-to-end connectivity, and many things have problems with NAT. Routing works quite well without NAT. You should only use NAT were you absolutely must use it, e.g. private to public addressing, or for joining two networks with overlapping addresses.
Again, no. Routing does not involve the layer-4 header. One form of NAT, NAPT (Network Address Port Translation), will use the TCP or UDP ports, or ICMP query IDs, but it only works for those three protocols, and it breaks other transport protocols and many applications. A routing table (what routers use to determine the path of packets) has nothing about layer-4 protocols in it.
RFC 2663, IP Network Address Translator (NAT) Terminology and Considerations explains NAPT: