# Linear scale a number between ranges

Map a value from one range onto another.

Canonical: https://1loc.dev/math/linear-scale-number-in-ranges/
Version: 1.0.0
Runtime: JavaScript · Node.js 22 / modern browsers
Verification: Local fixtures; no external services
Updated: 2026-10-28

## Implementation

```javascript
function linearScale({ value, inMin, inMax, outMin, outMax }) { return ((value - inMin) * (outMax - outMin)) / (inMax - inMin) + outMin; }
```

## Input

```json
{
  "value": 5,
  "inMin": 0,
  "inMax": 10,
  "outMin": 0,
  "outMax": 100
}
```

## Expected output

```json
50
```

## Edge case

Input:
```json
{
  "value": 0,
  "inMin": -1,
  "inMax": 1,
  "outMin": 100,
  "outMax": 0
}
```
Output:
```json
50
```

## Limits

- Output ranges may be reversed, as the edge case shows. The lab requires inMin ≠ inMax.

The lab validates types and size before calling this function. Add equivalent validation at your own trust boundary.

## Source and license

Original: https://github.com/phuocng/1loc/blob/14b481cf60dff1620ab1bb99a43b1f68068cdd9b/contents/linear-scale-number-in-ranges.mdx
Author: Nguyen Huu Phuoc and original contributors
Contributors: iamandrewluca
Source commit: 14b481cf60dff1620ab1bb99a43b1f68068cdd9b
Copyright (c) 2020 phuoc-ng
License: MIT — https://1loc.dev/licenses/
Maintainer: Oveyon
Modifications: Takes named fields as one object. Original MDX retained as inert source evidence.
