The first law of thermodynamics sets the relationship of the change of internal energy as equal to the addition of heat minus the work a system completes. This is one of three laws that determines the characteristics of thermodynamics.
The internal energy in a thermodynamic system comes from molecules that move consistently and at random. The work in the system is the output. The values for heat and work having a positive sign depend on the direction of either element in the system. For closed systems, the process is cyclical, but there are variations on the first law of thermodynamics in an open system.