IPsec is a set of protocols defined by the IETF, to provide IP security at the network layer. An IPsec based VPN is made up of two parts:

Basically there is an initial brief interaction where one or each of the devices attempt to discover each other, via the Internet, they then trade Phase 1 (IKE) parameters and attempt to get a Phase 1 (sometimes called IKE or ISAKMP) connection which creates the keys used to encrypt Phase2. They then trade Phase 2 parameters and attempt to create an encrypted Phase 2 (sometimes called IPSec SA or ESP) tunnel connection.

The devices then transport data back and forth, as well as maintain the connection, with some additional administrative traffic.