Calculating the size of a set. If there was a set i.e. $S = \{2, 4, 6\}$ I understand that the size of the set would be $3$.
But what would be the size if there was a set within a set and another within?
For example: $X = \{2,4,6,\{8\}\}$ and $Y = \{2,4,6,\{8\}\,\{\{10\}\}, 12\}$
 A: If $A \in B$ and $x \in A$, this means that $x$ is an element of $A$. But it need not be an element of $B$.
The basic way to think about this, is because of encapsulation : an object , with all its features, may belong in a certain set, but the subobjects of that object may not qualify.
Here are good explanations on why this is not the case in set theory.
But essentially, imagine I were counting cars in my alley.  I can see only three of them. However, imagine that the cars, in truth, were sets themselves, containing the steering wheel, the windshield,the bonnet, the ... (I am not an expert on cars, but I can drive!) then I would have counted a million objects, when in truth I was meant to count only three.

With that in mind, it does not matter what resides within each element. The number of elements is the only thing that matters. Remember that every set is determined by its elements.
In particular, the elements of $X$ are $2 , 4 , 6$ and $\{8\}$. Its cardinality is then $4$.
The elements of $Y$ are $2 ,4,6 , \{8\}, \{\{10\}\}, 12$. Its cardinality is then $6$.
We do not look at the nature of the elements (i.e. if they are sets , or numbers, or fruits) we only see how many of them there are, and that number is the cardinality.

On duplication (carryover of comments)
What about duplication of elements? For example, what is the cardinality of $Z=\{b,1,2,b,4,\{b\},\{\{b\}\},4\}$?
Membership determines a set. Therefore, in a set we do not count how often each element appears, but whether it appears or not. With that in mind, the set $Z$ is as good as $\{b,1,2,4,\{b\},\{\{b\}\}\}$, which is the set of its "non-duplicate" elements. That has size six, and therefore so has $Z$.
To summarize, the size of a set is number of its elements, where each element is counted once. To avoid confusion for small sets , we write a set so that we can avoid explicit duplication of elements.
A: A set $B$ that is within another set $A$ is just considered another element of $A$. By definition this would mean for your example the cardinality of $X$ is 4 and the cardinality of $Y$ is 6.
