Liberalism is a philosophy that is based on free markets, (bourgeois) democracy, and fundamental rights such as equality before the law. It arose with capitalism as justification for the emerging bourgeoisie against the old aristocratic and feudal order, enabling it to emerge from the mercantilism characteristic of the time when monarchies and capitalism coexisted. As trade restrictions were lifted and free markets were established, capitalism was given a basis to rise. Liberalism was originally more libertarian like its exponents preached, although as private interests became stronger and sapped powers from the state, it became more oligarchic like the aristocrats of before. Thus liberalism has a tendency to decay, as liberty is very often a zero-sum game where restrictions on one mean the freedom of another. Liberals tend not to identify with their label and often say they have no ideology, that they just do what works, but in practice they end up serving liberalism by doing things like expanding imperialist wars, cutting social services, and making student loan debt non-dischargeable. Sometimes the word "liberal" is used only in reference to social liberals, as in the United States, although liberals may in fact be socially conservative, among other things, thus making Republicans liberals too.
John Locke is often credited with founding liberalism as a philosophy in the late 17th century, with his works reflecting the more egalitarian currents of capitalist thought at the time that were seeking to undermine the notion of divine right. As he writes, governments which are opposed to "life, liberty, and property" violate the "inalienable" rights of people, and thus are invalid and may be rightfully deposed. Adam Smith developed on this ideology, expounding the idea of rational self-interest and promoting competition with the belief that such a way of thinking benefits society more than deliberate altruism because of the invisible hand — the force which benefits society through such unconscious acts of altruism. Conveniently, this gives an excuse to the wealthy for not going out of their way to aid the poor, as their selfishness is really altruism after all. Smith also developed the notion of laissez-faire, the idea that the government should just protect property and the institution of markets (as through the police and army).
Liberals are not socialists, and at most have somewhat of an inclination or sympathy towards them. Liberals tend to be unaware of legitimate critical theory but may side at times with socialism nonetheless either because they believe in forming a popular front or because they have a misconception about what socialism is (most commonly, this manifests as a liberal’s desire for what they believe to be socialism, when really they just focus on the achievement of welfare, not to change the relations to the means of production per se). Marxism rejects liberal reform of capitalism, considering reform to be a bandage that cannot reconcile the inherent contradictions of capitalism. Regardless, liberals on the path to class consciousness are generally considerable allies and have a place within the socialist movement, particularly at first when uniting against reactionary and other anti-socialist forces (wherein there is the establishment of a popular front).
After World War II a class collaborationist economic regime was set up in developed countries under pressure from the working class. Declining rates of profit led to the rise of neoliberalism in the 1970s in response to the perceived failure of neo-Keynesianism to address the stagflation of the time. It sought privatization, the diminishing of union power, and emphasized personal responsibility — a reactionary movement which sought to emulate the class disparities of the Gilded Age and the economic conditions which served the basis for such, including longer workdays, unsafe workplaces, and unequal rights for much of the population. Thus regulations were rolled back and government power was ceded to private entities like banks and other corporations. The liberal fanaticism about personal responsibility, based on the notion that the system is fair for everyone, also led to a decrease in public investment. With this came a hyperindividualist worldview as exemplified by Margaret Thatcher's statement that "there is no such thing as society". The decay of liberalism has produced a considerable amount of backlash against it, such as in the rhetoric of the far-right, politicians like Bernie Sanders, Alexandria Ocasio-Cortez, and Lee J. Carter, as well as organizations like the Democratic Socialists of America.