We have a more general result. Let $A_1,A_2,\ldots,A_n$ be measurable sets in a finite measure space $(\Omega,\mathcal{F},P)$. For an integer $k$, $0\le k\le n$, let $E_k$ denote the event consisting of $x\in \Omega$ such that $x$ belongs to exactly $k$ sets among $A_1,A_2,\ldots,A_n$. Then $E_k\in\mathcal{F}$ and
$$P(E_k)=\sum_{r=k}^n(-1)^{r-k}\binom{r}{k}\sum_{1\le i_1<i_2<\ldots<i_r\le n}P\left(A_{i_1}\cap A_{i_2}\cap \ldots \cap A_{i_r}\right).\ \ \ \ \ (0)$$
For $k=0$, the sum $\sum_{1\le i_1<i_2<\ldots<i_r\le n}P\left(A_{i_1}\cap A_{i_2}\cap \ldots \cap A_{i_r}\right)$ for $r=0$ is to be interpreted as $P(\Omega)$.
In particular when $\Omega$ is a finite set and $P$ is the counting measure, (0) can be rewritten as
$$|E_k|=\sum_{r=k}^n(-1)^{r-k}\binom{r}{k}\sum_{1\le i_1<i_2<\ldots<i_r\le n}\left|A_{i_1}\cap A_{i_2}\cap \ldots \cap A_{i_r}\right|.$$
Again, for $k=0$ and $r=0$, we use the convention
$$|\Omega|=\sum_{1\le i_1<i_2<\ldots<i_r\le n}\left|A_{i_1}\cap A_{i_2}\cap \ldots \cap A_{i_r}\right|.$$
For a proof, let $\chi_S$ denote the characteristic function of $S\in \mathcal{F}$. That is, $P(S)=\int\chi_S dP$. By writing
$$E_k=\left(\bigcup_{1\le i_1<i_2<\ldots<i_k\le n}\bigcap_{j=1}^kA_{i_j}\right)\setminus\left(\bigcup_{1\le i_0<i_1<i_2<\ldots<i_k\le n}\bigcap_{j=0}^kA_{i_j}\right),$$ it follows that $E_k\in\mathcal{F}$. Here when $k=0$, we use the convention
$$\bigcup_{1\le i_1<i_2<\ldots<i_k\le n}\bigcap_{j=1}^kA_{i_j}=\Omega.$$
We want to verify that
$$\chi_{E_k}=\sum_{r=k}^n(-1)^{r-k}\binom{r}{k}\sum_{1\le i_1<i_2<\ldots<i_r\le n}\chi_{A_{i_1}\cap A_{i_2}\cap\ldots\cap A_{i_r}},\ \ \ \ \ (1)$$
where we interpret $\sum_{1\le i_1<i_2<\ldots<i_r\le n}\chi_{A_{i_1}\cap A_{i_2}\cap\ldots\cap A_{i_r}}$ when $k=0$ and $r=0$ as $\chi_\Omega=1$.
Here is an example. Recall that $$1-\chi_X=\chi_\Omega-\chi_X=\chi_{\Omega\setminus X}=\chi_{X^c}$$ and $$\chi_{X_1\cap X_2\cap \ldots \cap X_m}=\chi_{X_1}\ \chi_{X_2}\ \cdots \ \chi_{X_m}.$$ The case $k=0$ is easy as the LHS of (1) is precisely
$$\prod_{j=1}^n(1-\chi_{A_j})=\prod_{j=1}^n \chi_{A_j^c}=\chi_{\bigcap_{j=1}^nA_j^c}=\chi_{\left(\bigcup_{j=1}^nA_j\right)^c}=\chi_{E_0}.$$
Fix $x\in \Omega$. Suppose that $x$ is in precisely $\ell$ sets among $A_1,A_2,\ldots,A_n$. Then it follows that
$$\sum_{1\le i_1<i_2<\ldots <i_r\le n}\chi_{A_{i_1}\cap A_{i_2}\cap\ldots\cap A_{i_r}}(x)=\binom{\ell}{r} .$$
Therefore
$$\sum_{r=k}^n(-1)^{r-k}\binom{r}{k}\sum_{1\le i_1<i_2<\ldots <i_r\le n}\chi_{A_{i_1}\cap A_{i_2}\cap\ldots\cap A_{i_r}}(x)
= \sum_{r=k}^n (-1)^{r-k}\binom{r}{k}\binom{\ell}{r}
= \left\{\begin{array}{ll}0&\text{if }\ell<k\\ \sum_{r=k}^\ell(-1)^{r-k}\binom{r}{k}\binom{\ell}{r}&\text{if }\ell\ge k.\end{array}\right.$$
So when $\ell<k$, (1) when evaluated at $x$ yields a correct result. Let now $\ell\ge k$. Using $\binom{r}{k}\binom{\ell}{r}=\binom{\ell}{k}\binom{\ell-k}{r-k}$ we get
$$\sum_{r=k}^\ell(-1)^{r-k}\binom{r}{k}\binom{\ell}{r}=\binom{\ell}{k}\sum_{r=k}^{\ell}(-1)^{r-k}\binom{\ell-k}{r-k}=\binom{\ell}{k}\sum_{j=0}^{\ell-k}(-1)^j\binom{\ell-k}{j}.\ \ \ \ \ (2)$$
It is well known that $\sum_{j=0}^m(-1)^j\binom{m}{j}=1$ for $m=0$, and $\sum_{j=0}^m(-1)^j\binom{m}{j}=(1-1)^m=0$ for $m>0$. Therefore, (2) gives
$$\sum_{r=k}^\ell(-1)^{r-k}\binom{r}{k}\binom{\ell}{r}=\left\{\begin{array}{ll}1&\text{if } \ell=k\\0&\text{if }\ell>k.\end{array}\right.$$
Hence, also when $\ell \ge k$, (1) evaluated at $x$ also yields the correct result. This shows that (1) is true.
By integrating (1) we get
$$P(E_k)=\int \chi_{E_k}dP=\int\left(\sum_{r=k}^n(-1)^{r-k}\binom{r}{k}\sum_{1\le i_1<i_2<\ldots<i_r\le n}\chi_{A_{i_1}\cap A_{i_2}\cap\ldots\cap A_{i_r}}\right)dP.$$
By linearity of integration,
$$P(E_k)=\sum_{r=k}^n(-1)^{r-k}\binom{r}{k}\sum_{1\le i_1<i_2<\ldots<i_r\le n}\int\chi_{A_{i_1}\cap A_{i_2}\cap\ldots\cap A_{i_r}}dP,$$
which is precisely (0).