I was wondering if the cardinality of a set is a well defined function, more specifically, does it have a well defined domain and range?
One would say you could assign a number to every finite set, and a cardinality for an infinite set. So the range would be clear, the set of cardinal numbers. But what about the domain, here we get a few problems. This should be the set of all sets, yet this concept isn't allowed in mathematics as it leads to paradoxes like Russell's paradox.
So how do we formalize the notion of 'cardinality'? It seems to behave like a function that maps sets into cardinal numbers, but you can't define it this way as that definition would be based on a paradoxical notion. Even if we only restrict ourselves to finite sets the problem pops up, as we could define the set {A} for every set, thereby showing a one-to-one correspondence between 'the set of all sets' (that doesn't exist) and the 'set of all sets with one element'.
So how should one look at the concept of cardinality? You can't reasonably call it a function. Formalizing this concept without getting into paradoxes seems very hard indeed.
The collection of all sets does not form a set in ZF(-style) set theory, indeed. Note that the same is true for the collection of all cardinals: there is no set containing all cardinals, because then its union would be a set as well, and it would be a greater cardinal than any of its elements.
So the function $X \mapsto |X|$ is not a function internally to ZFC. However, it can be made a function externally: that is, there is a formula $\phi(x,y)$, in two free variables, which holds if and only if $y$ is the cardinality of $x$. For this formula, we can prove $\phi(x,y) \land \phi(x,y') \to y = y'$, and we can prove $\forall x \exists y \phi(x,y)$. Hence, if we want to, we can introduce a function symbol $\mathrm{Card}$ to the language of set theory, such that $\mathrm{Card}(x)$ is interpreted as the unique $y$ such that $\phi(x,y)$. This is fine for the purposes for which we want to use cardinality.
Note also that if you are looking at a more limited part of the universe of sets, say $V_\alpha$ for some ordinal $\alpha$, then the restriction of the meta-function $\mathrm{Card}$ to this set does form a set.