Gains in stocks occur when the selling price of a security exceeds its purchase price, resulting in a profit. Gains can be realized through selling shares or unrealized when the stock value increases without being sold.