The first law of thermodynamics can be written as
where
is the variation of internal energy of the system
is the amount of heat absorbed by the system
is the work done by the system on the surrounding.
Using this form, the sign convention for Q and W becomes:
Q > 0 --> heat absorbed by the system (because it increases the internal energy)
Q < 0 --> heat released by the system (because it decreases the internal energy)
W > 0 --> work done by the system (for instance, an expansion: when the system expands, it does work on the surrounding, and so the internal energy decreases, this is why there is a negative sign in the formula Q-W)
W < 0 --> work done by the surrounding on the system (for instance, a compression: when the system is compressed, the surrounding is doing work on the system, and so the internal energy of the system increases)