Consider aldohexoses. Aldohexoses are carbohydrates (sugars) that have 4 stereocenters. For example D-glucose is shown below. Since it has 4 stereocenters there are 24 = 16 stereoisomers. D-glucose is one of these 16. The D means that the bottom stereocenter when portrayed in a Fischer projection has the heteroatom (O) in this case on the right side.
Aldohexoses can form cyclic hemiacetals when one of the distal hydroxy groups attack the aldehyde. These can be either 6-membered rings (pyranose) or 5-membered rings (furanose). I always remember Furanose and Five both start with F.
Let us walk through this cyclization and draw a cyclic hemiacetal in a perspective drawing.
Start with the sugar in a Fischer projection and then lay it on its side. Anything on the left is now pointing up and anything on the right is now pointing down.
Curl the structure around so that it looks like a cyclohexane. I start by drawing the carbon backbone out and then add the up and down bonds and then the OH's and H's.
We need to rotate the bottom stereocenter (now on back side), so the -OH is in the correct position to attack the carbonyl. Be careful when rotating so as not to mess up the stereochemistry. The green arrows show the rotation. I highlighted the groups/atoms that are rotating.
Now we can do the nucleophilic addition.
After deprotonation/protonation we get the following hemiacetal on the left. This particular acetal is known as α-D-glucopyranose. Had the carbonyl been facing the other way then we would have obtained β-D-glucopyranose. The alpha (α) and beta (β) refer to whether the the hemiacetal OH is up (beta) or down (alpha). I highlighted the hemiacetal carbons in blue in each structure below. The mnemonic BUDA is useful for remembering this. Beta Up Down Alpha.
Read more about how this relates to mutarotation on wikipedia.