You need to do it specific to you and the riding you want to do.
Generally about 25% sag for XC and anything up to 50% for DH stuff.
Sit on the bike, see how much the shock sags, and then put in more air or take some out – seems a bit numpty, but this is the way to do it.
Make sure you have all your kit on, helmet and if you take water with you on a ride put this on as well. There’s a little rubber ring on the shock to help you to do this.
Same for front and rear although I don’t think I’d run my shock on the front @ 50%