Naegele's rule, developed in the 19th century and still used today, calculates the due date by adding 280 days (40 weeks) to the first day of the last menstrual period (LMP). An equivalent shortcut is to subtract 3 months from your LMP date and add 7 days. For example, if your LMP was January 1, your estimated due date would be October 8.
This method assumes a 28-day cycle with ovulation on day 14. It also assumes that the first 2 weeks of pregnancy are pre-conception — which is why "40 weeks pregnant" really means 38 weeks since fertilization.
Naegele's rule works well for people with regular cycles close to 28 days. For shorter or longer cycles, or irregular cycles, ultrasound dating is more reliable.