A change in the internal energy of a system depends on the the net heat transfer into the system and the net work done by the system. The first law of thermodynamics, which is a generalized form of energy conservation, relates these three quantities mathematically. It states that the change in the internal energy equals the difference between the heat transfer and work done by the system.
The applied heat increases the internal energy of a system. Hence, conventionally heat is considered positive when added to the system and it is negative when removed from the system. When a gas expands, it does work, and its internal energy decreases. Thus, work is considered positive when it is done by the system and negative when it is done on the system.
Although heat and work both depend on the thermodynamic path taken between two equilibrium states, the change in internal energy depends only on the system's initial and final equilibrium states. Similar to the change in potential energy, the change in internal energy is a path independent quantity. The internal energy is a function of thermodynamic variables like pressure, temperature and volume. Functions such as internal energy and potential energy are known as state functions because their values depend solely on the state of the system.