Five people have each bought their own Christmas gift. They put the gifts in a sack which then everyone can pull their gift from. In how many ways can the gifts be distributed so that no one gets the Christmas gift they have bought themselves?
So I have figured $93$ combinations in which only $1$ and then $2, 3$ or $4$ and $5$ get their gift but I haven't figured out how to calculate that other people don't get their gift. For example
If $2$ people get their gifts how do I count that the other $3$ don't get their own gifts etc? I have read about derangement and seen different formulas but I haven't quite understood the logic.

You can use the concept of derangement. It is derived from Principle of exclusion and inclusion, For example if there are two tasks- $A$ and $B$, let $A$: Getting right gift for person $1$ and $B$ be getting right gift for person $2$. Then you want: $U-(A \cup B)$
Which can also be expressed as total ways of $U - (A + B - A \cap B)$ i.e. total ways - number of ways in which Event $A$ happens- Event $B$ + Ways where $A$ and $B$ occur simultaneously. This whole process for a general scenario becomes $n!\left(\frac{1}{2!}-\frac{1}{3!}+\frac{1}{4!}\cdots+ \frac{(-1)^n}{n!}\right)$.