Power set calculator: list every subset of a set
The power set of a set S is the set of all its subsets, including the empty set and S itself. Type a set to list every subset, grouped by size or in binary counting order, with the count 2ⁿ worked out exactly. You can copy the result as plain text or LaTeX.
On this page
What a power set is
For a set , the power set (also written ) is the set whose elements are all the subsets of :
For :
Two members are easy to forget. The empty set is a subset of every set, because it has no element that could fail to be in . And itself is a subset of . The subsets other than are called proper subsets.
The elements of a power set are sets, not elements of . So but , and as well as . Mixing up and here is the most common mistake in exercises.
Why a set of n elements has 2ⁿ subsets
To build a subset, go through the elements one at a time and decide: in or out. Each element has 2 choices, independently of the others, so by the product rule there are
subsets, of which are proper. The count doubles with every element you add, because each old subset appears twice in the new power set, once without the new element and once with it. That doubling is also an induction proof: , and adding an element turns into . See proof by induction for the general method.
| n | 0 | 1 | 2 | 3 | 4 | 5 | 10 | 20 | 30 | 64 |
|---|---|---|---|---|---|---|---|---|---|---|
| 2ⁿ subsets | 1 | 2 | 4 | 8 | 16 | 32 | 1024 | 1,048,576 | 1,073,741,824 | 18,446,744,073,709,551,616 |
The calculator counts exactly for sets of up to 1,000 elements and lists the subsets for up to 12 elements (4,096 subsets). Beyond that, any list is too long to read.
Counting subsets of each size
The number of subsets with exactly elements is the binomial coefficient , the number of ways to choose of the elements. Adding over all sizes counts every subset once, which gives the identity
For the sizes 0, 1, 2, 3 have 1, 3, 3, 1 subsets: row 3 of Pascal’s triangle. The table beside the calculator shows the row for your set, and “Show” can restrict the list to one size. To count subsets of one size for large , use the combination calculator.
Subsets as binary numbers
Number the elements 0, 1, 2, … and represent a subset by an -bit number whose bit is 1 exactly when element is in the subset. Counting from 0 to then visits every subset exactly once. For , with as bit 0:
| Mask | Bits (c b a) | Subset |
|---|---|---|
| 0 | 000 | ∅ |
| 1 | 001 | {a} |
| 2 | 010 | {b} |
| 3 | 011 | {a, b} |
| 4 | 100 | {c} |
| 5 | 101 | {a, c} |
| 6 | 110 | {b, c} |
| 7 | 111 | {a, b, c} |
This is the standard way to generate a power set in code:
function powerSet(items) {
const result = [];
for (let mask = 0; mask < (1 << items.length); mask++) {
result.push(items.filter((_, i) => mask & (1 << i)));
}
return result;
}It takes time, which is optimal since the output itself has that many element slots. Choose “Binary counting order” in the calculator to see the mask beside each subset. The same bijection explains why bitmasks are used for sets of flags, and why brute-force search over subsets (for example, trying every subset in the subset-sum or knapsack problem) becomes impractical around .
Properties worth knowing
- implies .
- , but only : the subset of is in neither power set on the left.
- , which has one element, and , which has two.
- Ordered by , a power set is a Boolean lattice: union and intersection play the roles of OR and AND, and complement plays NOT. That is why the laws on the Boolean algebra page hold for sets too.
Using the calculator
- Separate elements with commas (
red, green, blue) or spaces (1 2 3). Braces are optional. Elements can be words, numbers or symbols; repeated elements are counted once, as in any set. - Group by size lists subsets from the empty set up to , each size in lexicographic order of the elements as you typed them. Binary counting order lists them by bitmask, with the first element as the lowest bit.
- LaTeX notation writes
\emptysetand\{a, b\}, ready to paste into a document; the copy button copies the whole power set. For typesetting tips see the LaTeX guides.
Background on sets, relations and functions, with a Venn diagram you can shade, is on the sets, relations and functions page.
References
- K. H. Rosen, Discrete Mathematics and Its Applications, 8th ed., McGraw-Hill, 2019. Section 2.1 (power sets) and Section 6.4 (binomial coefficients).
- P. R. Halmos, Naive Set Theory, Van Nostrand, 1960. Section 5, complements and powers.
- D. E. Knuth, The Art of Computer Programming, Volume 4A: Combinatorial Algorithms, Part 1, Addison-Wesley, 2011. Section 7.2.1.1, generating all n-tuples.