Similar to the Sun, other stars shed mass and magnetic flux via ubiquitous quasi-steady wind and episodic stellar coronal mass ejections (CMEs). We investigate the mass loss rate via solar wind and CMEs as a function of solar magnetic variability represented in terms of sunspot number and solar X-ray background luminosity. We estimate the contribution of CMEs to the total solar wind mass flux in the ecliptic and beyond, and its variation over different phases of the solar activity cycles. The study exploits the number of sunspots observed, coronagraphic observations of CMEs near the Sun by SOHO/LASCO, in situ observations of the solar wind at 1 AU by WIND, and GOES X-ray flux during solar cycle 23 and 24. We note that the X-ray background luminosity, occurrence rate of CMEs and ICMEs, solar wind mass flux, and associated mass loss rates from the Sun do not decrease as strongly as the sunspot number from the maximum of solar cycle 23 to the next maximum. Our study confirms a true physical increase in CME activity relative to the sunspot number in cycle 24. We show that the CME occurrence rate and associated mass loss rate can be better predicted by X-ray background luminosity than the sunspot number. The solar wind mass loss rate which is an order of magnitude more than the CME mass loss rate shows no obvious dependency on cyclic variation in sunspot number and solar X-ray background luminosity. These results have implications to the study of solar-type stars.