This is discussed in the standard textbooks on algebraic topology. Pick a presentation of the group $G = \langle g_1,g_2,...,g_nr_1,r_2,...r_m \rangle$ where $g_i$ are generators and $r_j$ are relations. Then we have a wedge of $n$ circles and attach twocells to the wedge sum according to the relations $r_j$. Denote the final space $X$. Then van Kampen says $\pi_1(X)=G$. While usually $X$ is not a manifold, it is wellknown that every finitely generated group $G$ can be realized as the fundamental group of some 4manifold $X$. Can someone sketch the proof? Also, if $X$ could not be some manifold of dimension $<4$, what is the obstruction?
Theorem. Every finitely presentable group is the fundamental group of a closed 4manifold. Sketch proof. Let $\langle a_1,\ldots,a_m\mid r_1,\ldots, r_n\rangle$ be a presentation. By van Kampen, the connected sum of $m$ copies of $S^1\times S^3$ has fundamental group isomorphic to the free group on $a_1,\ldots, a_m$. Now we can quotient by each relation $r_j$ as follows. Realise $r_j$ as a simple loop. A tubular neighbourhood of this looks like $S^1\times D^3$. Do surgery and replace this tubular neighbourhood with $S^2\times D^2$. This kills $r_j$. QED There are many restrictions on 3manifold groups. One of the simplest arises from the existence of Heegaard splittings. It follows easily that if $M$ is a closed 3manifold then $\pi_1(M)$ has a balanced presentation, meaning that $n\leq m$. Other obstructions to being a 3manifold group were discussed in this MO question. 


A slightly different way of proving the same is the following. Take a wedge of n circles, one each for the generators. Now attach a disc for each relation. Imagine this complex $X$ sitting inside $\mathbb{R}^5$. By general position and finitely presented nature of $G$, the discs have no intersections in the interior. Take a tubular neighbourhood of $X$ in $\mathbb{R}^5$ and then take its boundary. One can check that this is a $4$manifold with the required property. 


Yet another explanation of the same constructions given above is to add 1 and 2 handles to the 4 ball according t the given presentation, obtaining a 4 manifold $X$ with boundary. Now the boundary of $X\times I$ (i.e. the double of $X$) has the same fundamental group by Van Kampen and the fact that $\partial X\subset X$ induces a surjection on fundamental groups (turning $X$ upside down shows that $X$ is obtained from $\partial X$ by adding 2 and 3 handles). Since the first homology=abelianization of $\pi_1$ of closed 1 and 2manifolds are known, it is easy to see most groups dont occur for $n=1$ or $2$. For $n=3$, another algebraic obstruction is to observe that if $\pi=\pi_1(M^3)$, then $H_2(M)\to H_2(\pi)$ is onto, and if $M$ is orientable, then $H_2(M)=H^1(M)=H^1(\pi)$. So if $H^1(\pi)$ is smaller than $H_2(\pi)$, it cannot occur (for an oriented 3manifold, in any case). 

