Does number of inputs or outputs affect bitcoin transaction fee? I would like to know how inputs and outputs affects my bitcoin transaction fee using legacy address, and how using a segwit address will decrease the same  transaction?

and how they will be calculated?
if input and outputs affects how can avoid that, apart of segwit address method?

thanks a lot.
Format for 1 input 2 outputs (1 to receiver, 1 change to owner). Normal non-seg transaction

P2SH    73 bytes(input) 32x2 (output)

P2PKH  about the same as P2SH 

To reduce fees reduce 

a) no of inputs.

b) Use exact match (with no change output) if possible.  

c) when fee is low, use more inputs or consolidate your input to fewer UTXO.(reduction of input for your future tx).

I think fee reduction increases a lot when you use multi-sig using seg-wit.

Output format 2of3 multisignature
      Input size    Out size

P2SH    297 32

P2SH-P2WSH  140 32  Wrapped Segwit 

P2WSH   105 43 Native Segwitness 

P2TR    58* 43 Pay to Taproot

P2PKH   148 34


means the recovery is more expensive.


To be actually sure of saving then you may want to go through the exercise of manually decoding every different type of bitcoin TX with various no of input and output.

(up to byte level where U can actually count).