TITLE: What is the total sum of the cardinalities of all subsets of a set?
QUESTION [49 upvotes]: I'm having a hard time finding the pattern. Let's say we have a set
$$S = \{1, 2, 3\}$$
The subsets are:
$$P = \{ \{\}, \{1\}, \{2\}, \{3\}, \{1, 2\}, \{1, 3\}, \{2, 3\}, \{1, 2, 3\} \}$$
And the value I'm looking for, is the sum of the cardinalities of all of these subsets. That is, for this example, $$0+1+1+1+2+2+2+3=12$$
What's the formula for this value?
I can sort of see a pattern, but I can't generalize it.

REPLY [2 votes]: You can encode every subset of a set as a binary number. If the set has $n$ elements, then you need the binary numbers of length $n$. Position $i$ in the number is element $i$ of the original set. An element $i$ is in the subset, if you have a 1 at position $i$.
There are $2^n$ numbers of length $n$, and there are $n$ digits per number. So in all the digits of all numbers are $n*2^n$.
Now the sum of the cardinality of all subsets is just the number of 1's in all these numbers. For each binary number, you can complement each bit to get another binary number of the same length. Thus the number of 0's and 1's must be the same, or put it another way: the number of 1's must be half of the digits.
Therefore, the number of 1's is $n*2^n/2$ or $n*2^{n-1}$, and that is the number of the sum of the cardinalities.