It compares network portions using the subnet mask. The device computes (its own IP AND mask) and (destination IP AND mask); if those network parts are equal, the destination is on the same subnet, so the device delivers the frame directly on the local link, it uses ARP to resolve the destination IP to a MAC address and sends straight to it. If the network parts differ, the destination is on another network, so the device sends the packet to its configured default gateway (a router): it ARPs for the gateway's MAC, frames the packet to the gateway, and the router forwards it toward the destination, with the source/destination MAC changing at each hop while the IP addresses stay end-to-end. This is why a device needs three things to reach the internet, its own IP, the subnet mask (to make this decision), and the gateway address, and why a missing or wrong gateway means "local network works, internet doesn't." The decision happens for every packet and is the crux of how layer-2 local delivery and layer-3 routing cooperate.
Networking & IoT · Interview question
How does a device decide whether to send a packet directly or to the gateway?
A strong answer
What a weak answer sounds like
You know the answer. Do you know what gets you dinged?
Pro breaks down the answer most candidates actually give to this question — and the specific reason an interviewer marks it down. It’s the difference between sounding correct and sounding senior, on all 472 questions.
From the lesson
IP Addressing
How a packet finds a device: IPv4/IPv6 addresses split into network and host by the subnet mask, the same-subnet-vs-gateway decision, plus DHCP, NAT, and why IoT devices dial out.