Corollary 2.15. If $V$ and $W$ are finite dimensional subspaces of a vector space over a division ring $D$, then $dim V + dim W = dim (V \cap W) + dim (V + W)$. Sketch of proof. Let $X$ be a basis of $V \cap W, Y$ a (finite) basis of $V$ that contains $X$, and $Z$ a (finite) basis of $W$ that contains X (Theorem 2.4). Show that $X \cup (Y - X) \cup (Y - X)$ is a basis of $V + W$, whence $dim (V + W) = |X| + |Y - X| + |Z - X| = dim V \cap W + (dim V - dim V \cap W) + (dim W - dim V \cap W)$.
I don't know how the set difference of two bases is a basis so makes two parts of the proof not understandable:
1- How $X \cup (Y - X) \cup (Y - X)$ is a basis of $V + W$?
2- How $|Y - X| = (dim V - dim V \cap W)$?
Proving the theorem has been posted on MSE but this question is not a duplicate of those since my question is about understanding the proof that has been given by the book.
Here are the details of the proof whose sketch is in Hungerford's book (page 187)
Proof: Let $X$ be a basis of $V \cap W$. Then $X \subset V$ and, since $X$ is linearly independent, by Theorem 2.4, there is $Y$ a basis of $V$ that contains $X$. Since $V$ is a finite dimensional space, we have that $Y$ is finite (by Theorem 2.7). In a similar way there is $Z$ a finite basis of $W$ that contains $X$.
Let us list the elements of $X$, $Y - X$ and $Z-X$. So, $ X =\{x_1, \dots x_r \} $, $ Y - X = \{y_1, \dots y_s \} $ and $ Z - X = \{z_1, \dots z_t \} $. Note that the sets $X$, $Y - X$ and $Z-X$ are disjoint.
Now, let $B= X \cup (Y - X) \cup (Z - X)$.
Let us prove that $B$ is linearly independent. Suppose $$ a_1 x_1 + \dots + a_r x_r+ b_1y_1 +\dots b_s y_s + c_1 z_1 + \dots c_t z_t =0 \tag{1}$$ Then $$ -(c_1 z_1 + \dots c_t z_t) = a_1 x_1 + \dots + a_r x_r+ b_1y_1 +\dots b_s y_s \tag{2}$$ Clearly, $-(c_1 z_1 + \dots c_t z_t) \in W$, as $Z$ is a basis of $W$. From the equality above, we also have that $-(c_1 z_1 + \dots c_t z_t) \in V$ (because $X \cup (Y-X)$ is $Y$, a basis of $V$). So, $-(c_1 z_1 + \dots c_t z_t) \in V\cap W$. So, $-(c_1 z_1 + \dots c_t z_t)$ can be written as a linear combination of elements in $X$: $$ -(c_1 z_1 + \dots c_t z_t) = d_1 x_1 + \dots + d_r x_r $$ that is $$ -(c_1 z_1 + \dots c_t z_t) = d_1 x_1 + \dots + d_r x_r + 0y_1 +\dots 0 y_s \tag{3} $$ Since $X \cup (Y-X)$ is $Y$, a basis of $V$, $-(c_1 z_1 + \dots c_t z_t)$ can be written in a single way as a linear combination of elements in $X \cup (Y-X)$. So, from $(2)$ and $(3)$, we have that $b_1=\cdots=b_s=0$. So, $(1)$ reduces to $$ a_1 x_1 + \dots + a_r x_r+ c_1 z_1 + \dots c_t z_t =0 $$ But, $X \cup (Z-X)$ is $Z$, a basis of $W$ and so, linearly independent. So $a_1= \cdots = a_r= c_1 = \cdots = c_t=0$. So, $B$ is linearly independent.
Now, given any $v \in V$, $v$ can be written as a linear combination of elements in $X \cup (Y-X)$. Given any $w \in W$, $w$ can be written as a linear combination of elements in $X \cup (Z-X)$. So $v+w$ can be written as a linear combination of elements in $X \cup (Y-X) \cup (Z-X) $. So, any element in $V+W$ can be written as a linear combination of elements in $B$. Since $B \subset V+W$, we have that $B$ is a basis of $V+W$.
Now, note that $\dim_D(V\cap W) = r =|X|$, $\dim_DV = r+s= \dim_D(V\cap W) +|Y-X| $ and $\dim_DW = r+t= \dim_D(V\cap W) +|Z-X| $. Therefore, \begin{align*} \dim_D(& V+W) = |B| = |X| + |Y - X| + |Z - X| = \\ & = \dim_D(V\cap W) + (\dim_D V-\dim_D(V\cap W)) + (\dim_D W-\dim_D(V\cap W)) =\\ & = \dim_D V + \dim_D W - \dim_D (V\cap W) \end{align*}
So, we have: $$ \dim_D V + \dim_D W = \dim_D (V \cap W) + \dim_D (V + W)$$