First things first: pasta with different structures will give you different results. Smooth pasta will cook uniformly, ribbed pasta (like rigatoni) does not have that quality, but it will make the sauce stick.
Take a saucepan, fill it with water and bring it to boil. Quantity is important. Pasta needs to be free to move, so a lot of water is necessary: the general rule is 1 liter every 100g. With 500g of pasta you would need 5 liters.
Salt has to be added before adding the pasta, but after the water has started to boil, otherwise it will take longer to reach boiling point. 10 to 1 is the rule here: for every liter of water, 10g of salt. If the sauce contains ingredients with lot of salt, add a bit less.
You are probably thinking this is the part where you add oil to the water. Wrong and useless: if pasta comes out of the water all stuck together in one piece, next time use more water and buy some decent quality of pasta.
When the water has diluted the salt, add the pasta. If you are using long pasta like spaghetti, it will stick out of the pan, but there is no need to break it (broken spaghetti is not spaghetti after all). Push it down gently instead.
Pasta is at room temperature so it will make the boiling stop. This is a very delicate stage: you have to be quick in bringing back the boil, by covering the pan and turning up the heat. When the water is bubbling again, let the steam go out and turn down the heat, but keep it lively.
Stir the pasta every 2-3 minutes, keep it moving to make sure it will not stick. The cooking time in the packet usually is for pasta al dente. This means that it will be cooked in the end, but it will not melt in your mouth, you will still have to bite it.
Al dente is how pasta should be. Do not overdo, for at least three reasons: pasta will not stop cooking until it is cold, and long before you have finished eating it, it will be like chewing gum; if you cook it too much your stomach will take longer to process it; (last but not least): this is the way the do it in Italy. Once you become an al dente expert, you can taste it to know when it is time to drain it, using the packet as a general guide.
Drain the pasta completely. Keep some cooking water if you need it (it would depend on the recipe). Put it back in the sauce pan with the sauce, and stir vigorously for 2-3 minutes at low heat.
On the other hand, if you are preparing a pasta salad, or your lunchbox for the next day, you will need to stop the cooking process by pouring cold water on the colander after the pasta is drained.