Leviticus 25:50-53
25:50 He must calculate with the one who bought him the number of years from the year he sold himself to him until the jubilee year, and the cost of his sale must correspond to the number of years, according to the rate of wages a hired worker would have earned while with him.
25:51 If there are still many years, in keeping with them he must refund most of the cost of his purchase for his redemption,
25:52 but if only a few years remain until the jubilee, he must calculate for himself in keeping with the remaining years and refund it for his redemption.
25:53 He must be with the one who bought him like a yearly hired worker. The one who bought him must not rule over him harshly in your sight.