How to calculate premiums

How are premiums calculated for options? any formula?
is there any M2M in options ?
Learnt buyer will loose total premium paid if goes against his view? And Seller will pocket the total premium paid ? but that seems not happening if buyer or seller square off position before expiry? How to calculate profit and loss of options premium for ongoing trade before expiry?
is there any diff in calculation on expiry(excersising) or before expiry?(squaring off)
I am newbie here ? can some please clarify with this ? thanks in advance…

In the money call options:

Intrinsic Value = Price of Underlying Asset - Strike Price.

In the money put options:

Intrinsic Value = Strike Price - Price of Underlying Asset.

P&L =( Intrinsic value - Premium Amount paid) × lot quantity size

Nifty 50 & Bank Nifty were cash settled.
And There is no M2M IN OPTIONS
And some options expire with some premium left with the contract

case1:
call option sold with strike price 16750 with premium 50 rs
with current market price or spot at 16500
at start of monthly expiry and
after 2 days i noticed
spot price increased to 16700 with premium increased to 100 rs
and to avoid losses seller immediately squared off position .
what will be seller profit and loss ?
will the seller retain premium amount as strike price is still otm ? or
will the buyer only loose difference in premium amount?
and
what is the status of buyer incase if seller squared off position before expiry ?
will the buyer loose entire premium paid ? or
seller position carry forwarded to some other seller ?

case 2:
call option bought with strike price 16700 atm with premium 100 rs
with current market price or spot at 16700
at start of monthly expiry and
after 2 days i noticed
spot price decreased to 16600 and premium reduced to 50 rs and
to avoid losses buyer immediately squared off position .
what will be buyer profit and loss ?
will the buyer loose entire premium if squared off b4 expiry ? or
will the buyer only loose difference in premium amount?
and
what is the status of seller incase if buyer squared off position ?
will he get entire premium paid by buyer? or
buyer position carry forwarded to some other buyer ?

USE below calculator-