Every machine gets an IP address and a netmask (or CIDR format mask).
Every machine has a routing table.
Lets assume one machine is 10.0.0.7/8, the gateway/router is 10.0.0.1/8 and the other machine is 10.0.0.27/8
You have a TCP/IP server running on 10.0.0.27 port 30000
You have a TCP/IP client running on 10.0.0.7 (ephemeral port 51167) that's trying to connect to the server.
How does 10.0.0.7 find 10.0.0.27?
The router keeps an ARP (address resolution protocol) table which has MAC address and IP address. It can also send out ARP packets to discover the network topology. "Who has 10.0.0.7, tell 10.0.0.1". The answer to that is "MAC aa:bb:cc:dd:ee:ff has 10.0.0.7". That's separate from DHCP and is used with ALL routing within your LAN.
When we connect to port 30000 we send a SYN from 10.0.0.7 to 10.0.0.27. (source=0x0A000007, dest=0x0A00001B) (The router knows how to find 10.0.0.27 and can send it on the wires to the right MAC address)
10.0.0.27 sends back a SYN,ACK (source==0x0A00001B, dest=0x0A000007)
10.0.0.7 sends the payload with an ACK (s=0x0A000007, d=0x0A00001B)
10.0.0.27 sends a reply with ACK (s=0x0A00001B, d=0x0A000007)
eventually there's a FIN,ACK packet to end the conversation.
Much the same stuff happens for a ping except that uses ICMP packets with a 56byte payload. There's no SYN, SYN,ACK, ACK three way handshake for ICMP.
When you connect to google.com port 80 (173.194.34.130) the same thing happens, except this time the router has to hand the request up the wire to your ISP and your ISP hands it off to their boundary router and onwards until it reaches Google's server.
Your first reading assignment is to read, digest and understand ALL 998 pages of
http://www.redbooks.ibm.com/redbooks/pdfs/gg243376.pdf
If you can't complete that reading assignment then read all HTML pages starting from
http://www.tcpipguide.com/free/index.htm