S parameters measurement inside VNA
Here's a good basic explanation about how a VNA works.

An excerpt follows:




  To measure S11 or S21, the switch would route the signal toward Port
  1. The signal first enters a directional device, shown as Directional Device R1 in Figure. This directional device could be a directional
  coupler or bridge. A power divider could also be used here. The
  purpose of this device is to direct a portion of the input signal to a
  reference receiver, shown as Reference Receiver 1. Once the signal
  enters this reference receiver, it’s downconverted and ultimately
  processed.
  
  The signal that passes through Directional Device R1 then passes
  through another directional device, shown as Directional Device M1 in
  Figure, before arriving at the DUT. When the signal does arrive at the
  DUT, a portion is reflected back to Port 1 of the VNA and reenters
  Directional Device M1. This device now directs a portion of the
  reflected signal to a measurement receiver, shown as Measurement
  Receiver 1. Next, this signal is downconverted and processed. The VNA
  can then compare the data obtained from Measurement Receiver 1 with
  the data obtained from Reference Receiver 1. This process summarizes
  how S11 is measured.
  
  The signal applied to the DUT also results in a transmitted signal,
  which exits the DUT and enters Port 2 of the VNA. This transmitted
  signal enters another directional device, shown as Directional Device
  M2 in Figure. This device directs a portion of the signal to another
  measurement receiver, shown as Measurement Receiver 2. This signal is
  subsequently downconverted and processed. Now, the VNA can compare the
  data obtained from Measurement Receiver 2 with the data obtained from
  Reference Receiver 1. This process summarizes how S21 is measured.
  
  To measure S22 or S12, the switch would route the signal to Port 2.
  The same process occurs in the opposite direction: The signal first
  enters Directional Device R2 in Figure, which directs a portion of the
  signal to Reference Receiver 2. After entering this reference
  receiver, the signal is downconverted and processed.
  
  The signal that passes through Directional Device R2 then passes
  through Directional Device M2 on its way toward the DUT. After
  arriving at the DUT, a portion of the signal is reflected back to Port
  2 of the VNA and reenters Directional Device M2. Now, a portion of
  this reflected signal is directed to Measurement Receiver 2.
  Afterward, this signal is downconverted and processed. The data
  obtained from Measurement Receiver 2 can then be compared with the
  data obtained from Reference Receiver 2, thus summarizing the S22
  measurement process.
  
  The signal that’s transmitted through the DUT enters Port 1 of the
  VNA. This transmitted signal enters Directional Device M1 in Figure,
  which directs a portion of the signal to Measurement Receiver 1. This
  signal is likewise downconverted and processed. The data obtained from
  Measurement Receiver 1 can now be compared with the data obtained from
  Reference Receiver 2, thus summarizing the S12 measurement process.


If you want to obtain S-parameters of a network with input/output impedance other than 50-ohm, these must be recalculated afterwards from the already measured, 50-ohm referenced S-parameters.