Start with a rule you trust: 'If a shape is a square, then it has four sides.' Suppose a shape does not have four sides, say a triangle. Could it be a square? No, because then it would have four sides. So 'if a shape does not have four sides, then it is not a square' must also be true. That second sentence is the contrapositive: negate both parts and swap their order, so P→Q becomes ¬Q→¬P.
The two forms always agree because they rule out the same situation. P→Q is false only when P is true and Q is false. ¬Q→¬P is false only when ¬Q is true and ¬P is false, which is the same situation. Their truth-table columns are identical, so you may prove whichever is easier. For 'if n2 is even, then n is even', prove instead 'if n is odd, then n2 is odd': (2k+1)2=4k2+4k+1=2(2k2+2k)+1, which is odd.
Doing only half of the move gives a different statement. Swap without negating and you get the converse, 'if it has four sides, then it is a square', which a non-square rectangle disproves. Negate without swapping and you get the inverse, 'if it is not a square, then it does not have four sides', which the same rectangle disproves. Only the full move, negate both and swap, keeps the truth value.
Think of it like this. The contrapositive is a security rule read backwards: 'everyone inside the lab wears a badge' means 'anyone without a badge is not inside the lab'. Both sentences forbid exactly one thing, a person inside without a badge, so they stand or fall together. 'Everyone with a badge is inside' forbids something else entirely.
Core idea. The contrapositive of if P then Q is if not Q then not P, always equivalent.