Interview's MateData Science
Interview's Mate

Data Science

Python → ML → MLOps

Visualizer

DSA Visualizer
All 32 lessons
Custom Playground
Try your own examples

Learning

System Design
31 architecture topics
SQL Learning
160 foundations → production topics
AI Engineering
160 LLM → backend topics
Data Science
160 Python → MLOps topics
Data Engineer
160 SQL → streaming topics
Docker
160 Docker learning topics
Kubernetes
160 K8s fundamentals → cloud
Java LearnSoon
Coming soon
Python Learn
Interview Q&A & internals
JavaScript Learn
Closures, async & DOM Q&A
Tech Learn
Search, practise & track Q&A
AI DSA Practice
Solve coding problems
Theme
Home
Data Science topics
Lesson 50/ 160
03. Mathematics & Statistics

Standard Error & Confidence Intervals

Estimate uncertainty of a metric with SE and interpret confidence intervals correctly.

IntermediateStandard Error · CI3 quiz questions
Practice Generative AI Q&A
In plain wordsDiagramTheoryStep by stepWhen to use itInterview cluesMistakes to avoidQuiz (3)Practice

In plain words

A confidence interval is a range around your estimate that shows how sure you can be; more data makes the range narrower.

Think of it like…

Weighing yourself on a wobbly scale: one reading isn't the truth, but ten readings give an average with a margin. The margin of error shrinks as you take more readings, and the interval says "the true weight is probably within this band".

Where you’ve seen it

An analyst samples 64 orders with mean basket ₹120 and standard deviation ₹24. SE = 24 / √64 = 3, so the 95% CI is about 120 ± 2.0 × 3 = (114, 126) using the t critical value 2.0 for 63 degrees of freedom. For conversion, 120 conversions in 1,000 visits gives p̂ = 0.12, SE = √(0.12 × 0.88 / 1000) ≈ 0.0103 and a 95% CI of 0.12 ± 0.020 = (9.99%, 14.01%). Halving that ±2-point margin would need about four times the traffic, 4,000 visits.

Words you’ll hear

Standard error
Standard deviation of an estimator's sampling distribution (not of the data).
Confidence interval
A range computed so that, over repeated samples, a stated share contains the true value.
Margin of error
Critical value × SE: the half-width of the interval.
t distribution
Heavier-tailed than normal; used for means with an estimated standard deviation and small n.

Visual diagram

Loading interactive diagram

Theory & deep dive

Computing standard errors and intervals

Mean: SE = s / √n; the 95% interval is x̄ ± t* × SE, with t* from the t distribution with n − 1 degrees of freedom (2.0 for n = 64; 2.26 for n = 10; it approaches 1.96 as n grows). Proportion: SE = √(p̂(1 − p̂) / n) and the interval p̂ ± 1.96 × SE; for small n or p near 0 or 1, prefer the Wilson interval (statsmodels.stats.proportion.proportion_confint(count, nobs, method="wilson")). Difference of two means or proportions: SE = √(SE₁² + SE₂²) for independent groups, the basis of A/B test intervals.

Other levels: a 90% interval is narrower (critical value 1.645) and a 99% interval wider (2.576). For statistics without simple formulas (medians, ratios, correlations), use the bootstrap: resample the data with replacement many times, recompute the statistic, and take the 2.5th and 97.5th percentiles (scipy.stats.bootstrap). Always compute from the right unit: if observations are clustered by user, use cluster-robust standard errors or aggregate to the user level.

A CI for a mean in Python

m, se = x.mean(), stats.sem(x); ci = stats.t.interval(0.95, df=len(x)-1, loc=m, scale=se) returns (114.0, 126.0) for the basket example.

Key takeaway: SE from s/√n or √(p(1−p)/n); critical value from t or normal; bootstrap otherwise.

Interpreting intervals and sizing samples

The 95% confidence level describes the method: across many repeated samples, 95% of intervals built this way contain the true parameter. Once computed, a specific interval either contains it or not. Practical reading: values inside the interval are consistent with the data, values far outside are not; a wide interval means imprecise knowledge; an interval for a difference that excludes 0 agrees with a significant test at the same level. An interval is not a range containing 95% of the data (that's a prediction or reference interval, based on the std, not the SE), and overlapping intervals of two groups don't necessarily mean no significant difference.

Interval width is 2 × critical value × SE, which shrinks as 1/√n. To plan an estimate with margin of error E for a proportion near p, n ≈ (1.96² · p(1 − p)) / E². For p = 0.5 and E = 0.02, n ≈ 2,401; halving E to 0.01 needs about 9,604, four times as many. Report intervals alongside point estimates in dashboards and experiment readouts so stakeholders see uncertainty, not just a number.

Sample size for a survey

To estimate a satisfaction rate within ±3 percentage points at 95% confidence, assuming p = 0.5 (the most cautious case), n = 1.96² × 0.25 / 0.03² ≈ 1,067 respondents.

Key takeaway: A CI describes the method's reliability; width falls with √n; plan sizes from the desired margin.

How it works, step by step

Step 1 of 4
Frame

1. Choose the estimand and unit

Decide whether you're estimating a mean, proportion or difference, and the independent unit of analysis.

mean basket per order · conversion per visit
Key numbers at this step
Cluster
by user if needed

When to use it & trade-offs

What it is

The standard error (SE) of a statistic is how much it would vary from sample to sample; for a mean it's s / √n, for a proportion √(p̂(1 − p̂) / n). A confidence interval (CI) turns this into a range of plausible values for the true parameter: estimate ± critical value × SE, with critical value ≈ 1.96 for 95% under the normal approximation (or from the t distribution for small samples). The right reading: if you repeated the study many times, about 95% of the intervals built this way would contain the true value. It does not say there's a 95% probability that this particular interval does.

Why it matters: A bare number ("conversion is 12%") hides how much to trust it. Intervals communicate uncertainty, drive decisions (is the lift reliably above zero?), size experiments (how many users for ±1%?) and prevent over-reading noise. Misinterpreting intervals, or confusing standard error with standard deviation, is one of the most common statistical errors in reports.

When to reach for it

  • Reporting metrics with uncertainty
  • A/B test lift intervals
  • Planning survey and experiment sizes

When to avoid or be careful

  • Reading a 95% CI as a 95% probability for the one interval
  • Using the std instead of the SE for the uncertainty of a mean
  • Using the normal interval for tiny samples or extreme proportions

Ways to quantify uncertainty

Normal / t interval
Best for: Means and proportions with adequate n

Strengths: Simple formulas; fast.

Watch out: Relies on CLT conditions and independence.

Bootstrap interval
Best for: Medians, ratios, skewed data and complex statistics

Strengths: Few assumptions; general.

Watch out: Computationally heavier; needs i.i.d. data.

Bayesian credible interval
Best for: Direct probability statements with priors

Strengths: Intuitive interpretation.

Watch out: Needs priors and modelling.

Interview signals & numbers to know

When this topic comes up

  • “What's the margin of error?”
  • “Standard error vs standard deviation”
  • “How many respondents do we need?”
  • Wilson interval
  • Bootstrap CIs

Benchmarks & rules of thumb

1.96 -
z critical value for 95%
(114, 126) -
95% CI in the basket example
≈ 1,067 -
sample size for ±3 points at 95% (p = 0.5)

Common mistakes & follow-ups

Common interview mistakes

  • Saying "there's a 95% chance the true mean is in this interval" in a stakeholder meeting.
  • Plotting mean ± std as error bars and calling them confidence intervals.
  • Computing a CI on repeated measures per user as if they were independent.

Likely interviewer follow-ups

  • How do you interpret a 95% confidence interval?
  • How does sample size affect the width of an interval?
  • When would you use a bootstrap interval?
Interview tip: Use the phrase "intervals built this way capture the true value 95% of the time". It's the correct interpretation, and it signals statistical care.

Knowledge check

Loading quiz

Put it into practice

Practice related interview Q&A

Apply Standard Error & Confidence Intervals with data science interview Q&A and hands-on practice.

Open Data Science Q&A →Machine Learning Q&A
Previous topic
Sampling Techniques & Sampling Bias
Next topic
Hypothesis Testing & Null vs Alternative