Precise Meaning of Grand Canonical Partition Function Wikipedia cites the grand canonical partition function as
$$\mathcal{Z}=\sum_i e^{-\beta (E_i-\mu N_i)},$$
where $i$ denotes each available microstate of the system, $N_i$ the number of particles in that microstate, and $E_i$ the energy of that microstate. 
From my lecture notes, I have the following definition
$$\mathcal{Z'}=\sum_{N=0}^{N_{tot}}\sum_i e^{-\beta (E_i-\mu N)}.$$
Here, we said $N$ changes from zero to some fixed number of total particles available to the system ($N_{tot}$), and each state has energy $E_i$. 
To my understanding, the grand canonical ensemble allows for the number of particles in a system to change. Definition of $\mathcal{Z'}$ seems to suggest that exactly$-$we allow the system to have any number of particles from the range $0$ to $N_{tot}$, and for each $N$ we sum over all possible states those $N$ particles can be in. On the contrary, the definition of $\mathcal{Z}$ from wikipedia seems to suggest that the number of particles for each microstate $i$ is fixed$-$it seems that we simply sum over each microstate taking into account their energy and number of particles. 
I am confused as to what the grand canonical ensemble really means in terms of particles being allowed to vary. Is my definition of $\mathcal{Z'}$ incorrect? Or is my understanding flawed?
 A: The two sums are exactly the same.
In your lecture notes, the sum over $N$ is written down explicitly. For each $N$, you have a different set of microstates that you are summing over, all of them having exactly $N$ particles. In Wikipedia, the sum over $N$ is implicit in the sum over $i$, since in Wikipedia's notation, each microstate comes with the number of particles $N_i$ as an associated variable.
Why would you use the grand canonical partition function? Your intuition is correct.
Suppose you have an open system which particles can move into and out of. This means it's connected to another system containing particles of the same type.
Now, suppose you want to consider the thermodynamics of this open system. A canonical partition function isn't good enough because the number of particles varies, so you need a grand canonical partition function. 
A: 
we allow the system to have any number of particles from the range 0 to $N_{tot}$, and for each $N$ we sum over all possible states those $N$ particles can be in.

What you say is not incorrect. In a way, in the grand canonical distribution, we are considering a statistical ensemble of systems with different particle numbers. Each of these cases occurs with a certain probability in our actual open system. So what you are doing when calculating $\mathcal Z'$ is taking the member of this ensemble of different particle numbers with particle number N, computing the eigenvalues of its hamiltonian in its corresponding many particle Hilbert space (which is $\mathcal H^N = \otimes_{n=1}^N\mathcal H_n $)* and summing over the contribution of each N in that formula. 
However, there is also another way to look at it. If we broaden the vector space describing our system from distinct many particle Hilbert spaces for each particle number to the Fock space, which is the direct sum of the many particle Hilbert spaces with different particle numbers, a "state" (a vector in Fock space) also contains information about the particle number. So any state (in this new context) tells you about both of these quantities, which guessing by your description, is what is implied in Wikipedia. In fact, in this Fock space formulation, the grand canonical partition function takes the following elegant form:
$$\mathcal Z' = Tr(e^{-\beta (\hat H - \mu \hat N) })$$
Where $\hat N$ is the particle number operator which acts on the Fock space. If you need references on Fock spaces and the second quantization formulation you can check out chapter 1 of Advanced Quantum Mechanics by Schwabl as an example.
* Note that for identical particles $\mathcal H^N$ should be the symmetric or antisymmetric subspace of $\otimes_{n=1}^N\mathcal H_n$ , for Bosons and Fermions, respectively.
A: We do allow particle exchange and energy exchange in a grand canonical ensemble. The interpretation goes like this:-
Let's say at an instance, we have $N_1$ particles in the ensemble. The microstates can also vary their energy from $E_1$ to $E_{N_1}$. So we sum these little contributions of each energy value to get the contribution of $N_1$ for the grand canonical ensemble. 
Now we repeat the same process for $N_2$.
Then for $N_3$. And till we have reached $N_{tot}$.
At last we sum all these contributions of each $N's$ to get the grand canonical partition function.
It's important to have indexing of $E$ and $N$ different. We are summing over two different variables. So your $Z'$ in the lecture notes is right. 
