If you are replacing an existing toilet with a new one, or remodeling an existing bathroom, the single most important dimension that you need to know is the "rough-in" dimension.
This is the dimension measured from the face of the wall to the center of the toilet's floor mounting bolts (center or the sewer outlet flange). This is typically 12-inches for most toilets, but there are some that have a dimension of 10-inches or 14-inches.
If you are replacing an existing toilet, you can measure how much space you have between the back wall and the center of the mounting flange. If it is 12-inches, then make sure your new toilet has a "rough-in" dimension of 12-inches or smaller.
If you are remodeling or doing new construction, you will want to install the sewer mounting flange so that it matches the toilet you are purchasing. If you are measuring from the wall studs, don't forget to take into account the width of the drywall (typically 1/2-inch).