Let us assume one wants to evade Venn diagrams, then indicator functions are an alternative.

Recall that for every set $A$ and every element $x$, $\mathbf 1_A(x)$ is $1$ if $x\in A$ and $0$ if $x\notin A$. Then, for every subset $A$ of a given set $E$, this defines a function $\mathbf 1_A:E\to\mathbb R$, called the indicator function of $A$ (in $E$), such that

$$

|A|=\sum\limits_{x\in E}\mathrm 1_A(x).\tag{1}

$$

This formulation might seem to only complicate things. Let us show the opposite is true, for the reason that now one deals with sums on a fixed set $E$.

It happens that indicator functions are especially well suited to intersections. To wit, for every collection of sets $A_k$ with intersection $C$,

$$

\mathbf 1_C=\prod\limits_k\mathbf 1_{A_k}.

$$

Let us now put indicator functions and intersections of sets together.

First consider two sets $A$ and $B$. Then one might remember that $\mathbf 1_{A\cup B}=\mathbf 1_A+\mathbf 1_B-\mathbf 1_{A\cap B}$ and proceed. So far so good, except this is not a new formula at all. To see this, consider that unions of complementary sets are complementary sets of intersections so let us find the intersection hidden here. One gets

$$

E\setminus(A\cup B)=(E\setminus A)\cap(E\setminus B),

$$

hence

$$

\mathbf 1_{E\setminus(A\cup B)}=\mathbf 1_{E\setminus A}\cdot\mathbf 1_{E\setminus B}.\tag{2}

$$

One last tool before we proceed. To enumerate a complementary set is easy, since

$$

\mathbf 1_{E\setminus A}=1-\mathbf 1_A.\tag{3}

$$

Note that, using (1), (3) yields

$$

|E\setminus A|=\sum\limits_{x\in E}(1-\mathrm 1_A(x))=\sum\limits_{x\in E}1-\sum\limits_{x\in E}\mathrm 1_A(x)=|E|-|A|.

$$

Coming back to the union, (2) and (3) yield

$$

1-\mathbf 1_{A\cup B}=(1-\mathbf 1_{A})\cdot(1-\mathbf 1_{B})=1-\mathbf 1_A-\mathbf 1_B+\mathbf 1_{A\cap B},

$$

which can be rewritten as

$$

\mathbf 1_{A\cup B}=\mathbf 1_A+\mathbf 1_B-\mathbf 1_{A\cap B}.

$$

For two sets, this was complicating well known arguments for nothing but now, let us consider $n$ subsets $A_k$ of $E$ and let us try to imitate the arguments above.

Calling $A$ the union of the sets $A_k$, $B_k=E\setminus A_k$ and $B$ the intersection of the sets $B_k$, one gets

$$

E\setminus A=B,\quad

\mathbf 1_B=\prod\limits_{k=1}^n\mathbf 1_{B_k},

\quad

\mathbf 1_B=1-\mathbf 1_A,

\quad

\mathbf 1_{B_k}=1-\mathbf 1_{A_k}.

$$

To summarize, the key formula here is

$$

1-\mathbf 1_A=\prod\limits_{k=1}^n(1-\mathbf 1_{A_k}).\tag{4}

$$

The rest is algebra. Expanding the RHS of (4) yields a sum over every sequence of choices of $1$ or $(-\mathbf 1_{A_k})$, from $k=1$ to $n$. One can choose $(-\mathbf 1_{A_k})$ for every $k$ in $K$ and $1$ for every $k$ not in $K$, and the product is the sum of the results over every possible subset $K$ of $\{1,2,\ldots,n\}$, that is,

$$

\prod\limits_{k=1}^n(1-\mathbf 1_{A_k})=\sum\limits_K\prod\limits_{k\in K}(-\mathbf 1_{A_k})=\sum\limits_K(-1)^{|K|}\mathbf 1_{A_K},

\qquad

A_K=\bigcap\limits_{k\in K}A_k.

$$

The $K=\varnothing$ term is $1$, which can be cancelled with $1$ on the LHS of (4), hence, changing the signs, one is left with

$$

\mathbf 1_A=\sum\limits_{K\ne\varnothing}(-1)^{|K|+1}\mathbf 1_{A_K},

\quad\text{with}\quad

A=\bigcup\limits_{k=1}^nA_k,

\quad

A_K=\bigcap\limits_{k\in K}A_k.

$$

This yields finally the size of $A$ by summation over $x$ in $E$, namely,

$$

|A|=\sum\limits_{K\ne\varnothing}(-1)^{|K|+1}|A_K|.

$$

Note that these identities are valid for every number $n$ of sets $A_k$.

Example When $n=3$, the sum over the sets $K$ such that $|K|=1$ is $|A_1|+|A_2|+|A_3|$, the sum over the sets $K$ such that $|K|=2$ is $-1$ times $|A_1\cap A_2|+|A_2\cap A_3|+|A_3\cap A_1|$, and the sum over the sets $K$ such that $|K|=3$ is $|A_1\cap A_2\cap A_3|$, which is the formula in your post.