Default (Q) wipe phone and keep custom rom

How do I wipe clean my phone but keep custom Rom I'm giving it to friend later and want to wipe it of all my crap lol