Class and Constitution combine
Hit point maximum is mainly set by class, with martial classes gaining more and spellcasters less. The Constitution modifier also applies at first level and on every level thereafter, raising the maximum or lowering it when Constitution is under 10.
Retroactive changes and Aid
When the Constitution modifier changes, the hit point maximum is recalculated as if that modifier had applied since level 1. The Aid spell instead adds 5 to the maximum, plus 5 more for each spell slot level above 2 used.
Step-by-Step Guide
Establish the class contribution
Use the character's class to determine how much hit point maximum each level adds, noting that martial classes have more and spellcasters fewer.
Apply the Constitution modifier per level
Add the Constitution modifier at first level and again at every level-up, subtracting instead when the modifier is negative.
Recalculate after a modifier change
Whenever the Constitution modifier changes, recompute the maximum as if that modifier had been in place from level 1.

