Your reasoning is the wrong way. TCP/IP handles the layers top down, not bottom up.
PC A will first do a lookup in the routing table and decide that the only way to reach PC B is via the router specified in that routing table.
If the MAC address of the router is unknown it will send an ARP request to figure out which MAC address corresponds to the gateway IP.
Then the frame (containing the IP packet) will be sent to the MAC address of the router which will do a lookup in its routing table to see on which interface PC B is connected or via which next hop it should be routed. Assuming PC B is connected to another interface of the router the router will do a lookup (and if needed an ARP request) to figure out the MAC address of PC B and then forward the frame.
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
subnet.
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
packet?
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.
Best Answer
This is a correct description of ARP for IPv4.
It doesn't matter what IP range the LAN uses as long as it forms one subnet.
When the (broadcast) ARP request doesn't ask for the router's LAN IP address the request is just dropped.
No, a router does not forward L2 broadcasts that are used with ARP.
If node C wants to send an IP packet to a destination outside the LAN, its routing table tells it to pass the packet to the router as gateway. The packet is encapsulated by an L2 frame addressing the router's MAC. The router then receives the frame with the packet and forwards the latter according to its own routing table.
If the destination is local to the router, the router ARPs the destination IP and uses the discovered MAC for the Ethernet frame (assuming Ethernet is used). If the destination isn't local to the router it will use the next hop's MAC as local L2 destination in the frame.