During the nineteenth century, John Stuart Mill was one of the foremost believers in and practitioners of Utilitarianism, a system of thought that essentially declared an action to be proper if it was beneficial to the largest portion of society. In other words, according to the Oxford Reference, "an action is right in so far as it promotes happiness, and that the greatest happiness of the greatest number should be the guiding principle of conduct."
In his highly respected essay, On Liberty, he is adamant that the preservation of individual liberty rests largely on protecting freedom of thought no matter how egregious or immoral and, by extension, the freedom to express oneself based on that thought. His ideas largely echoed the sentiments of the first amendment to the Constitution, which is to protect free speech in all manners and forms. Protecting the most egregious speech—the type of speech most citizens would disagree with—is the most crucial element to free expression, as speech that everyone loves or agrees with is hardly in need of protecting.
However, while Mill understood that thoughts alone are self-contained and therefore without consequence, expressions of those thoughts can have a very real and tangible effect on others. As such, he believed in limitations on those expressions that could arguably be perceived as harming or having an adverse effect on others. Again, he largely echoes many sentiments of classical liberalism inherent in documents written by the founding fathers, namely the fact that your rights end when you begin depriving others of theirs.
He essentially buttresses this idea with four supporting arguments. First, suppressing someone else's ideas hinders the search for truth while simultaneously showing our own infallibility. Second, the prevailing opinion on any given subject is rarely the whole truth, and only through other less popular opinions can the whole truth come out. Third, not allowing one to defend his or her opinions also means disallowing all evidence in support of them. And fourth, only through the free debate of ideas will we as a society fully comprehend the meaning behind our beliefs, our morals.
Ultimately, Mill seems preoccupied with the search for truth and feels strongly that the free exchange of ideas through thought and expression are the means to achieve it so long as those expressions don't deprive others of their freedoms.