The plumbing fitting that holds a toilet to the floor is called the flange, and while it isn't difficult to install one, it's essential to do it properly. The flange has two slots for the bolts that hold the toilet, and if you don't align them properly, your toilet won't be straight. Before you install the flange, you should have cut a circular hole in the floor with a diameter about 1/2 inch greater than the flange pipe. The rough plumbing for the toilet waste line should be in place, terminating with a closet fitting just under the floor.
Dry-fit the flange by inserting the pipe through the hole in the floor and into the waste fitting underneath. Turn the flange collar so that the two slots for the toilet bolts form a line that is parallel to the back wall, then mark the positions of the bolt holes on the floor with a felt marker.
Remove the flange and, if the floor is tile or stone, drill a pilot hole for the flange bolt on each mark, using a masonry bit with a diameter equal to the that of the bolt.
Put a piece of masking tape on each mark to prevent the drill tip from wandering when you start the hole, and keep a bowl of water nearby. Drill at a slow speed, and remove the bit frequently from the hole and dip it in water to prevent it from overheating. Stop drilling as soon as the bit clears the tile.
Spread PVC cement on the outside of the flange pipe and the inside of the waste fitting under the floor, then quickly insert the flange pipe into the fitting and push down until the collar touches the floor. Rotate the collar until the bolt holes line up with the ones you drilled in the tile or the marks you made on a wood floor.
Drive a 10-gauge screw into each hole and tighten it with a screwdriver. Use screws that are long enough to bite at least an inch into the wood subfloor.