Externalities are the effects a transaction has on individuals or firms not part of the transaction. They are usually considered to be a market failure. Externalities may be positive or negative. Pollution is an example of a negative externality: a factory may produce pollution at the same time as it produces goods to be sold, but if the buyer of the goods is not harmed by the pollution, the factory will have no incentive to reduce or eliminate it. The pollution then becomes a negative externality affecting other individuals, who had not conducted any business with the factory.
In mathematical economics, an externality exists when the marginal cost (or benefit) is not the same as the marginal social cost (or benefit) for some good, where the marginal social cost is the marginal cost for the private actor plus the marginal value of effects on bystanders to the transaction.
Economic analysis demonstrates that goods with negative externalities will always be over-produced, and those with positive externalities always under-produced. A situation in which externalities exist is not socially optimal, and society may wish to force its economic agents to internalize their externalities - that is, to produce as much or as little of the externality as would be efficient. The two mechanisms for internalizing external effects are government regulation (or tax-based incentives) and special markets created for trading in the former externality (for example, the market for pollution credits).
Marginal analysis holds that when all externalities have been internalized, the marginal social cost of every good (or bad) equals its marginal social benefit. Such a situation is sometimes referred to as a Kaldor-Hicks social optimum.