Editor's note: Aaron E. Carroll is a professor of pediatrics at the Indiana University School of Medicine and the director of its Center for Health Policy and Professionalism Research. He blogs about health policy at The Incidental Economist and tweets at @aaronecarroll. The opinions expressed in this commentary are solely those of the author.

(CNN) -- Although vaccines are required for entry into school in most places in the United States, the government does allow for exceptions, like religious reasons.

In the last few years, the rates of vaccine-preventable illness such as measles and mumps have been on the rise. In most cases, these outbreaks began with children who were unvaccinated. In a school environment, an unvaccinated child who has a contagious disease can more easily spread it to other children.

Aaron Carroll

To combat this threat, some schools in New York have been refusing to allow unvaccinated children to attend school, where they might start outbreaks or make outbreaks worse. Several parents thought this was unfair and filed lawsuits. Just recently, though, a federal court ruled in favor of the city schools, citing that government has the power to make decisions that would protect public health.

The court made the right decision. Immunizations are important because they allow us to protect those who cannot protect themselves.

Review: Childhood vaccines are safe

Doctor: You can't get flu from flu vaccine

Experts: vaccines are necessary

Vaccines significantly decrease your risk of getting a disease if you come into contact with it, though there is still a tiny chance that you can get sick. When measles outbreaks occur, for example, more of the people who get sick tend to be unvaccinated, but some who are vaccinated can become ill.

Vaccine policy depends not only on the added protection that vaccines confer upon those who get shots, but also on the decreased likelihood that anyone will come into contact with the disease. This is known as herd immunity. It refers to the fact that when enough people are immunized, then there really can't be an outbreak. And if there can't be an outbreak, then everyone is protected, even those who can't get vaccinated.

This is critical, because there are people who are at increased risk for communicable diseases but cannot be given immunizations for various reasons. Small babies are susceptible to certain diseases, but can't be given all vaccines. The elderly sometimes have less-well functioning immune systems, and are at higher risk for diseases. The same goes for all immune-compromised patients, who are always under threat of infection.

We don't just get vaccines to protect ourselves. We don't just give them to our children to protect them. We do this so that all those other people are protected as well.

In 1995, the varicella vaccine, or the chicken pox vaccine, was introduced in the United States. Over time, more and more children received it. In 2011, a study was published in the journal Pediatrics that looked at how the program affected the number of children who died from the disease.

The first thing noted in the paper was that death from chicken pox went down significantly from before the vaccine was released. From 2001 through 2007, the rates of death remained much lower, with just a few children dying from chicken pox nationally each year.

What's notable is that from 2004 through 2007, not one child less than 1 year of age died in the United States from chicken pox. None. This is remarkable, because we cannot give the varicella vaccine to babies. It's only approved for children 1 year or older.

In other words, all those babies were saved not because we vaccinated them against this illness. They were saved because older children were. Enough of the older kids were vaccinated to grant herd immunity that protected babies from getting sick.

Widespread vaccination prevents disease outbreaks. This protects all people from getting ill.

But if some parents want their children to remain at risk by leaving them unimmunized, and those children get sick, the state has then to take steps to prevent outbreaks from occurring. In New York, one of the few children who developed measles earlier this year was an unvaccinated child. The state refused to allow that child's sibling, who was also unvaccinated, to go to school. That child also developed measles. The school maintains -- and it's hard to dispute -- that letting the second child go to school would have put everyone at higher risk.

People who refuse to vaccinate themselves, or their children, aren't just putting themselves at risk -- they're putting everyone else in danger, too.