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.

1$\begingroup$ Ok, we have $\pi_1(S^2\times D^2)=1$, so the loop $r_j$ has been killed. But how do you know that this surgery operation does not alter $\pi_1$ in any other way, i.e. adding/removing any other generators/relations? $\endgroup$ – Leo Aug 12 '13 at 16:43

2

$\begingroup$ @HJRW: Is the resulting fourmanifold orientable? $\endgroup$ – Michael Albanese Oct 18 '17 at 15:01

$\begingroup$ @MichaelAlbanese  of course! Each time you do the gluing, you just have to make sure that the induced orientations on the copy of $S^1\times S^2$ that you're gluing along are compatible. $\endgroup$ – HJRW Oct 19 '17 at 12:17
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.

1$\begingroup$ Sorry if this is silly but what is the tubular neighborhood of $X$ if $X$ is not a manifold? $\endgroup$ – zygund Apr 8 '12 at 2:23

1$\begingroup$ An appropriate tubular neighbourhood in this context would be all points in $\mathbb{R}^5$ which are $\epsilon$close to $X$, where $\epsilon$ is suitably chosen. $\endgroup$ – Somnath Basu Apr 8 '12 at 5:52

2$\begingroup$ can you explain me the last line...I mean why the boundary of the tubular nbd of $X$ has the same fundamental group?? this line is not clear to me... $\endgroup$ – Anubhav Mukherjee Jul 29 '15 at 17:08
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).