The Halachot concerning Borer (selecting) on Shabbat are derived from the Gemara in Masechet Shabbat (p. 74, 138) and Masechet Besah. They are recorded in Shulhan Aruch, Orah Haim, Siman 319.
There is an apparent contradiction between two Gemarot regarding the basic definition of the prohibition of Borer. On one hand, the Gemara in Shabbat page 74 states that it is permitted to select the Ochel (food) from the Písolet (waste). However, on page 138, the Gemara states that the classic prohibition of Borer is selecting the Ochel from the Písolet.
Tosafot (p. 74) reconcile these two sources by establishing a new principle: The prohibition of Borer is selecting in the normal fashion, i.e. removing the smaller quantity from the larger quantity, irrespective of whether it is the food or the waste. On Shabbat, it is only permitted to do the action in the irregular way, i.e. selecting that which is the larger quantity. Therefore, the Gemara that permits selecting food from waste is referring to a case where the food is the majority. The other Gemara, which prohibits removing the food from the waste, is referring to a case where the majority of the mixture is waste, and thus the normal, prohibited method is selecting the food.
The other Rishonim, including Rambam, Rashba and Ran, disagree. They hold that the only permitted way to select on Shabbat is removing the Ochel from Písolet. It is never permitted to select the Písolet, and they do not distinguish between the relative quantities. The logic of their position, as explained by the Tosefet Shabbat, is that on Shabbat all activity must deal with permitted functions such as eating foods. Therefore, one may only select the food which he desires, even if he might do it differently during the week. Dealing with the waste is not within the parameters of Shabbat.
Maran, in Siman 319:1, permits selecting the food from the waste, assuming other conditions are met. He does not mention a difference whether the food is the majority of the mixture or not. The Beíur Halacha (Rav Yisrael Meir Kagan of Radin, 1839-1933) and the Vilna Gaon understand from this that Maran holds like the Rambam, and not Tosafot. This is also clear from Maranís ruling in 319:4, as well as in Hilchot Yom Tob, and this is the accepted Halacha.
Selecting the waste from the food is never permitted on Shabbat, regardless of the respective quantities of food and waste. Selecting food from the waste may be permitted, in certain cases, if other conditions are met.