Need to calculate standard deviation in your application? This guide covers everything you need to know about standard deviation via API, including population vs sample, interpretation, and implementation examples.
What is Standard Deviation?
Standard deviation measures how spread out values are from the mean. A low standard deviation indicates values are close to the mean, while a high standard deviation indicates values are spread over a wider range.
Standard deviation is the square root of variance and is in the same units as the data, making it easier to interpret.
Population vs Sample
Population Standard Deviation
Used when you have data for the entire population. Divides by N.
σ = √(Σ(x - μ)² / N)
Sample Standard Deviation
Used when you have a sample of the population. Divides by (N-1) for Bessel's correction.
s = √(Σ(x - x̄)² / (n-1))
Using the Standard Deviation API
TinyFn provides a comprehensive endpoint for standard deviation:
POST https://api.tinyfn.io/v1/math/standard-deviation
Headers: X-API-Key: your-api-key
Content-Type: application/json
{
"values": [10, 12, 23, 23, 16, 23, 21, 16],
"count": 8,
"mean": 18,
"population_std_dev": 4.90,
"sample_std_dev": 5.24,
"population_variance": 24.0,
"sample_variance": 27.43
}
Parameters
| Parameter | Type | Description |
|---|---|---|
values |
array | Array of numbers |
type |
string | "population", "sample", or "both" (default) |
Code Examples
JavaScript / Node.js
const response = await fetch(
'https://api.tinyfn.io/v1/math/standard-deviation',
{
method: 'POST',
headers: {
'X-API-Key': 'your-api-key',
'Content-Type': 'application/json'
},
body: JSON.stringify({ values: [10, 12, 23, 23, 16, 23, 21, 16] })
}
);
const data = await response.json();
console.log(data.sample_std_dev); // 5.24
Python
import requests
response = requests.post(
'https://api.tinyfn.io/v1/math/standard-deviation',
json={'values': [10, 12, 23, 23, 16, 23, 21, 16]},
headers={'X-API-Key': 'your-api-key'}
)
data = response.json()
print(data['sample_std_dev']) # 5.24
cURL
curl -X POST "https://api.tinyfn.io/v1/math/standard-deviation" \
-H "X-API-Key: your-api-key" \
-H "Content-Type: application/json" \
-d '{"values": [10, 12, 23, 23, 16, 23, 21, 16]}'
Common Use Cases
- Quality Control: Monitor manufacturing consistency
- Finance: Measure investment volatility/risk
- Performance Monitoring: Detect anomalies in metrics
- Scientific Research: Report measurement precision
- Testing: Analyze test score distributions
Best Practices
- Choose correct type: Use sample std dev for most cases
- Report with mean: Std dev alone lacks context
- Consider sample size: Small samples have unreliable std dev
- Watch for outliers: They heavily influence std dev
Use via MCP
Your AI agent can call this tool directly via Model Context Protocol — no HTTP code needed. Add TinyFn to Claude Desktop, Cursor, or any MCP client:
{
"mcpServers": {
"tinyfn-math": {
"url": "https://api.tinyfn.io/mcp/math/",
"headers": {
"X-API-Key": "your-api-key"
}
}
}
}
See all math tools available via MCP in our Math MCP Tools for AI Agents guide.
Try the Standard Deviation API
Get your free API key and start calculating standard deviation in seconds.
Get Free API Key