The volume that a firm should produce for profit maximization can be determined in several ways. The best way to do this is by determining the marginal cost and the marginal revenue curves. The corresponding volume where the two curves intersect is where profit maximization is achieved.
In the case of perfect competition marginal revenue is a horizontal line. This happens as there are theoretically an infinite number of producers. A firm operating under these conditions has to consider its marginal cost curve. The marginal cost curve is usually one that is concave. Marginal cost first decreases due to the economies of scale and after a certain volume, when diseconomies of scale set in, it starts to move up again.
Profit is maximized where the volume produced is such that marginal revenue and marginal cost are equal. Here the difference between total revenue and total cost is also the largest.