P2SH covers a wide range of scripts, from a single byte OP_TRUE to 520 byte maximum length allowed to be pushed as redeem script raw bytes. you can't come up with a formula only based on the script being P2SH. it has to be based on the redeem script.
in these two cases the redeem script shows that this is of type P2SH-P2WPKH so we have as witness:
- one signature (fixed 71 bytes if the wallet grinds for low r values)
- length of signature 1 byte
- one compressed public key (33 bytes)
- length of public key 1 byte
- witness stack item count 1 byte
we have as signature script:
- a redeem script of size 23
- push size will be 1
that means each input adds 32(hash)+4(index)+24(sigScr)+4(sequence) = 64 bytes & 71+1+33+1+1=107 as witness
each output that has P2SH (like the first example) adds 8(amount)+23(pubScr)+1(length)=32 bytes
each transaction has some extra bytes: 4(version)+1(inCount)+1(outCount)+4(locktime)=10 & 2(segwit flag)
so the raw bytes or the total size is (2*64)+(2*107)+(2*32)+10+2=418
base size (without witnesses) is (2*64)+(2*32)+10=202
weight is base*3 + totalsize = 1,024
virtual size is weight/4 = 256
fee is 279541 satoshi => 279541/256=1,091.95703125 =~1,092 sat/vbyte
wiggle roomif the wallet doesn't grind for low r and has to add the 0x00 to indicate positive r for high values you can add 1 byte to for high r which makes witness 108 bytes, total size 420, base size same 202, weight 1026, virtual size 257 and fee 1,088 sat/vbyte
the second link is the same with the difference in their output types which are P2WPKH instead of P2SH and each one adds 8(amount)+22(pubscr)+1(length)=31 bytes