It determines the destination of a transmission by examining the IP address and subnet mask of the source machine with the IP address of the destination machine. TCP and UDP are actually responsible for conducting data transfer between machines once a connection has been established. The reason that UDP is still used is because it has less overhead than TCP and therefore can transmit data faster. This is a very simplistic way of looking at it, but it should help you to at least have a better basic understanding of these protocols. TCP and UDP are similar in that both utilize ports to differentiate the various types of signals that they receive.
Ports are similar to channels on a television.
The TV itself is the medium for receiving different types of communications called programs. The way in which the signal is sent from the television station, cable provider or satellite company tells your television that station X goes to channel 7 and that station Y goes to channel 8. Without the use of channels, sorting things out on a TV would be difficult. Likewise, TCP and UDP use something similar to channels called ports . Many of these ports are well defined and commonly accepted.