Proration is the time remaining in the current billing period divided by the time in the subscription's plan billing period. This is then multiplied by the per unit price to get the correct amount to charge and credit.
We only charge for the remaining amount of time because the customer will be billed the full price when the subscription bills at the end of the current billing cycle, so we want to make sure we don't over charge them and only charge for the actual time they will get to use the new product or service in this period. Similarly, we want to credit the customer what they paid for, but will not use. Since they will not use the product or service for the remainder of the billing cycle, this is the portion that is returned as a credit.
(time remaining in current billing period / subscription's plan period) x (per unit price)
Or more specifically...
[(current billing period end date - time of change) / (plan period end date - plan period start date)] x (per unit price)
You probably notice that the denominator of the proration fraction refers to the plan period, not the subscription's billing period. This is because the billing cycle can be customized through the postpone feature. If the bill date is changed to be sooner or later, the numerator will reflect that new end date, but the denominator will respect the underlying plan period's end date. For example, if the subscription was for an annual plan, but after the subscription was created the current billing cycle end date was moved in to a shorter date, the denominator would reflect a year while the numerator would reflect the new end date which would be less than a year out. Learn more about the postponing subscriptions below.