Approximately 50 million children in the United States attended public elementary and secondary schools in 2016, according to the National Center for Education Statistics.

» RELATED: These are Georgia’s top 34 high schools, according to new ranking

And for the majority of American parents, public education is the only option.

But in the U.S., the quality of public education varies from state to state and is often dependent on how much government spending (federal, state and local) is contributed to improve school systems.

» RELATED: 2017 Milestones: Georgia elementary school state test results

To determine the best (and worst) school systems in the country, researchers at personal finance website WalletHub compared the 50 states and the District of Columbia across two key dimensions: quality and safety.

Analysts evaluated the two dimensions using 21 relevant metrics, including funding, high school graduation rate among low-income students, presence of public schools in U.S. News & World Report’s annual ranking, test scores, bullying rates, youth incarceration rates and more.

» RELATED: How to keep your kids safe on social media

Massachusetts earned top honors as the state with the best school system, ranking first in both quality and safety.

It also ranked first for highest math, reading and median ACT scores and has the lowest percentage of threatened or injured high school students.

» RELATED: Teachers share best advice on how parents can help children

The state with the worst school system? Louisiana.

Louisiana ranked dead last in safety and came in at No. 44 in quality, despite high funding.

Georgia came in at No. 38 on the list and ranked 36th and 38th in quality and safety, respectively, falling three spots from last year's overall No. 35 spot.

» RELATED: How did your Georgia school do on the 2016 SAT?

While the state improved in its quality rank (39th in 2016), it fell a whopping 15 spots in safety from its No. 23 rank last year.

In 2015, The Atlanta Journal-Constitution reported that nearly one in six Georgia public schools had work to do to ensure a safe classroom environment.

» RELATED: Georgia school fights raise concerns about classroom safety

And in May, an AJC and Channel 2 Action News investigation found roughly 12 percent of the 656 officers working in Georgia's 31 school police departments have been terminated or resigned under investigations relating to poor performance, sexual misconduct, inappropriate use of force among others.

The rate is twice the rate of local police departments.

There have also been incidents of student-on-student attacks, including 92 fights at just one Gwinnett County high school in 2016.

» RELATED:  Does your child attend one of the 10 Georgia schools with the most fights?

But Georgia schools have seen some improvement this year.

In fact, 74 of 243 schools were removed from the Georgia Department of Education's "Focus" and "Priority" schools lists, the AJC reported in April.

From AJC’s Ty Tagami:

Priority schools represent the lowest-performing 5 percent of schools with the highest poverty levels (Title 1 schools) based on achievement data, plus schools with a graduation rate below 60 percent for two consecutive years. Focus schools represent the lowest-performing 10 percent of high poverty schools based on "achievement gap" data, which show the difference between a school's lowest performing students and the state average, and the amount of gap closure.

The 10 states with the best school systems, according to WalletHub:

  1. Massachusetts
  2. New Jersey
  3. New Hampshire
  4. Wisconsin
  5. Virginia
  6. Minnesota
  7. Connecticut
  8. Iowa
  9. Maine
  10. Illinois

» RELATED: Should teachers try to break up fights or are risks too great?

And the 10 states with the worst:

  1. Louisiana
  2. New Mexico
  3. West Virginia
  4. District of Columbia
  5. Mississippi
  6. Arkansas
  7. Alaska
  8. Alabama
  9. Oregon
  10. Tennessee

More about the study and its methodology at WalletHub.com.