Just think of it in terms of delta, I think it makes this concept easier to understand.
The delta of a stock is always 1. The delta of a call is always positive, the delta of a put is always negative.
Now, you will probably be given your delta value for the call/put options, say it’s 0.6 delta for the call option, and -0.3 for the put.
Having a hedged portfolio (delta only) means that you are delta neutral (i.e. you have no delta exposore, your delta position sums to 0).
Now just add up you deltas and solve for what you are trying to solve for (i.e. how many calls or how many puts or how many underlying)
So as an example
1) if you are given that you are long 100 calls, how many underlying do you need to hedge porfolio:
simply solve this equation 100 * 0.6 + x * 1 = 0
this is the 100 calls times their delta plus x amount of stock with a 1 delta equal to zero delta (i.e. delta neutral).
2) If you are short 100 puts
-100 * -0.3 + x * 1 = 0
again, just solve for x
3) you are long 100 shares, how many calls do you need to hedge
x * 0.6 + 100 * 1 = 0
again solve for x to tell you how many calls
4) you are long 100 calls, how many puts do you need to hedge
100 * 0.6 + x * -0.3 = 0
sove for x to figure out how many puts you need