You seem to be confused about a couple of things.
Let's say, there are 512 clients in a router's subnet. when the router
gets a datagram from other subnet, it inspects the MAC address in the
link layer, and confirms if the datagram's destination lies in it's
subnet by checking with the ARP module.
That's not how it works. A MAC address is only significant or even seen in the LAN on where the host with that MAC address is. MAC addresses do not cross a router to get to a different LAN. When a router receives a frame with the source and destination MAC addresses, it strips the frame off the packet, losing the original source and destination MAC addresses.
How exactly does the packet go to destination host once it reaches the
When the router has the packet, stripped of the frame containing the source and destination MAC addresses, it will inspect the destination IP address in the packet header, and it will switch the packet to the interface toward the destination. It will then build a new frame for the packet from scratch for the next hop. The next hop may not be ethernet, or any other protocol which uses MAC addresses. If the next hop uses MAC addresses, it will build the frame with its own MAC address for the next ho as the source MAC address, and the MAC address of the destination device (another router or the end host) of the next hop as the destination MAC address.
Router sending that packet to all clients and each client would
process that packet only if the MAC address in the packet matches with
it's own MAC address? If this is the case, why should the router
maintain an ARP module as in both cases it is broadcasting every
Any host, even a router, sending a broadcast will send to the broadcast address MAC address, not a specific host MAC address.
Any host (a router is just another host on the LAN) sending an IP packet to another host will compare the masked destination IP address to its own masked source IP address.
If both IP addresses are on the same network, the sending host will inspect its ARP cache to see if it already knows the MAC address associated with the IP address. If it has it in its ARP cache, it will build the frame with that MAC address. If it doesn't have it in its ARP cache, it will send an ARP looking for the MAC address of the destination IP address. If the host with that IP address responds, it will add the MAC address to its ARP cache, and it will use that MAC address to build the frame. If the destination host does not respond, the packet will be dropped, and an error generated.
If the destination IP address is on a different network, the sending host will use the MAC address of its configured gateway to build the frame so that the frame containing the packet gets delivered to it configured gateway. It will use its ARP cache or ARP to discover the MAC address of its configured gateway to build the frame.