One method is ultrasound and the accuracy of this method depends on when it is done. If an ultrasound is done in the first trimester (before 12 weeks) it is most accurate, but if it's done beyond 30 weeks, it can be off as much as 21 days! The accuracy of ultrasound dating decreases by over 1/2 a day with each week pregnancy has advanced. For example, if an ultrasound is done at 8 weeks, 8 x .5 = 4, so the accuracy is give or take 4 days. If it's done at 18 weeks, 18 x .5 = 9, the date can be off by around 9 days.
Oftentimes when a woman is seeing her healthcare provider during pregnancy, they will use a pregnancy wheel to calculate her due date and current gestational age. The rule on which these wheels work is by adding 280 days to the first day of her last normal period. This rule is general and does not take into account cycles that are more than or less than 28 days, or irregular. Another mathematical method, if the date of conception is known, is to add 266 days to that date to determine the due date.
While we have many "rules" to estimate due dates, they are still only estimates. Only 4% of births actually happen on the exact due date which is why it is so important that expectant mothers understand that it is more of a due period than a due date. The due period is generally two weeks before and two weeks after the due date. Try to enjoy being pregnant while it lasts since after all, it is only nine short months!