The IP (internet protocol) is a protocol for transmitting data over packets ("datagrams"). It is the primary protocol of the Internet. "IP" may also refer to an IP address, the numerical address assigned to an IP-capable device.
The Internet Protocol (IP) forms the basis of media-independent transmission and routing (a.k.a forwarding) of network packets, it is part of the Internet Protocol Suite.
In the OSI model, it resides at Layer 3 (the network layer). The protocol data unit for this layer is called a packet. IP packets are identified by source and destination IP addresses.
IP addresses, in combination with subnet masks, provide the basis for the concept of networks (or internetworks, more exactly) in the OSI model.
This means that a node, using IP addressing, can talk to machines it is directly connected to (on the same subnet), or that is on another network (on a different subnet).
While subnet masks are not specified in IP packets, they are used by devices that transmit and receive IP packets to determine if the packet is meant for another node that network, or another network. If the traffic is not meant for this network, it must be forwarded to that network via a router, and vice versa.
This is all in contrast to the common Layer 2 protocol Ethernet, in which nodes can only talk to other nodes reachable on the same network.
IP provides no guarantees on packet delivery. Responsibility for ensuring this reliability through retransmission and data integrity checking is assumed by a higher layer protocol, usually TCP.