There are two levels of complexity involved in IP routing:
Local delivery
When the IP software is presented with a datagram for delivery,
it first checks the network/subnet part of the destination address
to see if matches its own network/subnet number -- the current
netmask is used to discover if these match. If the
network/subnet part does match, then the datagram can be delivered
locally, and is simply handed to the physical network delivery
system (typically an Ethernet device driver) for
direct delivery over the local network.
Internet delivery
If the network numbers are different, then the datagram must be
sent to a directly-connected router (or IP gateway), using direct
delivery as above, for "on-delivery" across the Internet. Note that
when the datagram is received at the router, its destination IP
address is not that of the router.
Datagrams are forwarded from router to router across each of
the intervening networks until they reach a router connected to a
network where they can be locally delivered.
The IP software in each router must keep a routing
table to know the IP address of an appropriate next-hop
router which brings the datagram closer to its destination.
Note that routers must have (at least) two IP addresses, since
they are connected to (at least) two different
networks/subnets!