this is a famous theorem called whitneys embedding theorem proved probably in the 1940's. let me see if i can make up a proof for the compact case off the top of my head. take any point p of M, say a 2 manifold. Then p has a disc like nbhd so there is a map of that disc nbhd taking the interior onto the complement of the north pole in some sophere in R^3. Then just extend continuously so that all the rest of M goes to that northpole.
now we have a map from M to R^3 which embeds the interior of a nbhd of p, but does not embed the rest of M. Now do this for an open nbhd of every point and pick a finite subcover of M by the interiors of these nbhds.
That emans we have chosen N points pi of M and a nbhd of each one, and and N embeddings, one of each of these nbhds into R^3. Moreover these N nbhds cover M.
Then take the product of these N functions, getting a map from M to R^(3N). I claim this embeds M into R^3N, not of cousre as an open subset, but as a closed subet, much as the sphere is naturally embedded as a closed subset of R^3.
I have to prove the map is injective.
Given any two points x,y at all of M, if they lie in one nbhd of one of the points pi, then the ith corrdinate map fi separates them, since the ith map fi is injective on that whole nbhd.
If x is in the interior of some nbhd, and y is not, then the ith map sends x to the complement of the northpole on the ith sphere, and sends y to the north pole, thus x,y, are still separated by the ith coordinate function of the map f = f1xf2x...xfN.
WE cfan also arrange for our disc nbhd to map with injective deriavtive on the interior of each nbhd, hence actually getting an embedding onto a differentiable submanifold of R^N.
Notice in my definition of continuity for a subset of R^n I did nort require the subset to be open, since I sneakily said:”for every point q WHICH IS ALSO IN M, and which is within delta of p...”
after embedding a 2 dimensional M into some large dimensional R^N, one can then project down easily until it is actually differentiably embedded in R^5. Whitney showed with more difficulty one can even get it into R^4.
In fact since one knows what all the compact two manifodls are, one easil;y see that all orientable ones actually embed in R^3, since they are just toruses with more holes.
