Lose fat gain muscle

I want to lose fat and gain muscle. So i dont mind what the scale is. But I can't get a gym membership since im young and I dont have a ride. What are others way I can gain muscle and lose fat? Plus I want to flatten my stomach which I know is going to be all in my nutrition.