HomeAll CategoriesOne Sample Z Test Calculator with Steps (Free) | StatsUnlock

One Sample Z Test Calculator with Steps (Free) | StatsUnlock

One Sample Z Test Calculator

Test a sample mean against a known population mean when σ is known, or a sample proportion against a hypothesised proportion. Paste comma-separated data or summary statistics and get the z statistic, p-value, critical value, confidence interval, effect size, power, four charts and copy-ready APA results.

Hypothesis TestParametricKnown σOne ProportionEffect Size & PowerMulti-Group

⚡ 0. Quick Answer

A one sample z test calculator checks whether a sample mean differs from a hypothesised population mean μ0 when the population standard deviation σ is known, using z = (x̄ − μ0) ÷ (σ ÷ √n).

For 16 leaves with x̄ = 52.44 mm, μ0 = 50 and σ = 4, z = 2.44 and the two-tailed p = 0.0148, so the mean is significantly above 50 mm. The same test works for one proportion with z = (p̂ − p0) ÷ √(p0(1 − p0) ÷ n).

z = (x̄ − μ0) ÷ (σ ÷ √n)  ·  z = (p̂ − p0) ÷ √(p0(1 − p0) ÷ n)

Rule of thumb: reject H0 at α = 0.05 when |z| > 1.96 (two-tailed) or z > 1.645 (one-tailed). Use it only when σ is truly known and n ≥ 30 or the data are normal. If σ comes from your own sample, use the one-sample t test.

Key takeaways

  • The one sample z test compares one sample mean with a fixed value when σ is known in advance.
  • The test statistic counts how many standard errors (σ ÷ √n) the sample mean sits from μ0.
  • Critical values are fixed: ±1.960 two-tailed and 1.645 one-tailed at α = 0.05, whatever the sample size.
  • For a one sample proportion z test, check that n·p0 and n(1 − p0) are both at least 10.
  • Always report z, p, the confidence interval and Cohen’s d together, because a tiny effect can be significant in a large sample.

📚 1. What Is a One Sample Z Test?

A one sample z test is a hypothesis test that asks one question: is the mean of the population my sample came from equal to a stated value μ0? It can be used when the population standard deviation σ is already known from earlier work, a standard, or the way a test is scaled. Because σ is known, the test statistic follows the standard normal distribution exactly when the data are normal, and approximately for large samples through the central limit theorem.

What it actually measures: the distance between the sample mean and μ0, expressed in standard errors. One standard error is σ ÷ √n, the typical amount a sample mean of size n wobbles around the true mean. A z of 2.44 says the sample mean sits 2.44 standard errors from the null value, which is rare if the null value is true.

A worked one-liner: 16 leaves give x̄ = 52.4375 mm. With μ0 = 50 and σ = 4, the standard error is 4 ÷ √16 = 1, so z = (52.4375 − 50) ÷ 1 = 2.4375 and the two-tailed p = 0.0148.

464748495051525354μ0 = 50x̄ = 52.442.44 SE2.5% tail2.5% tailSample mean of 16 leaves (mm), SE = σ ÷ √n = 4 ÷ 4 = 1
Under H0 the sample mean of 16 leaves would follow a normal curve centred on 50 mm with a standard error of 1 mm. The orange tails hold the most extreme 5%. The observed mean of 52.44 mm falls in the upper tail, so H0 is rejected.

Two versions in one tool. The z test for one sample mean uses σ. The one sample z test for proportions tests whether a population proportion p equals p0, using the standard error √(p0(1 − p0) ÷ n). The proportion version needs no σ because the spread of a proportion is set by p0 itself.

Who uses it: quality engineers checking a filling line with a long-run σ, psychologists testing IQ scores scaled to σ = 15, pollsters testing whether support differs from 50%, clinicians comparing a ward with a national rate, and ecologists comparing a plot with a regional benchmark where the spread is well documented.

FeatureOne sample z testOne sample t test
Spread usedKnown population σSample SD s, estimated from the data
Reference distributionStandard normalt with n − 1 degrees of freedom
Critical value at α = 0.05, two-tailed1.960 for every n2.131 at n = 16, 2.045 at n = 30
Works for proportionsYes, the one proportion z testNo
Use whenσ is known, or a proportion with n·p0 ≥ 10σ is unknown, which is most real data

🧮 2. Set Up Your Data

Group names are editable. Click a name to rename it. Nothing is computed until you press Run.
Accepts .csv, .txt, .xlsx and .xls. Headers are detected automatically. Click the columns you want: every selected column is loaded as its own group, named after its header.

Type one value per cell. Each column becomes a group, and the column name is editable. Empty cells are ignored.


Must come from outside this sample: a standard, a long-run record or the test’s scaling.

📊 3. Results

Enter or load your data above, then press Run One Sample Z Test. The z statistic, p-value, confidence interval, effect size, power, assumption checks, four charts and auto-filled reporting sentences will appear here.

🧠 4. Interpretation of Results, In Detail

Sub-sections 4.1 to 4.5 fill in automatically with your numbers after you press Run. Sub-sections 4.6 to 4.10 explain how to read any one sample z test result.

4.1 What your result says

Run the analysis above to fill this paragraph with your own numbers. ___

4.2 Reading the p-value correctly

Run the analysis above to fill this paragraph with your own numbers. ___

4.3 The confidence interval tells you more than the decision

Run the analysis above to fill this paragraph with your own numbers. ___

4.4 Effect size: is the difference big enough to matter?

Run the analysis above to fill this paragraph with your own numbers. ___

4.5 Power and the sample size you would need

Run the analysis above to fill this paragraph with your own numbers. ___

4.6 Why the critical value never changes with n

In a t test the critical value shrinks as n grows, because the sample SD becomes a better estimate of σ. In a z test σ is known, so there is nothing to estimate and the cut-offs stay fixed: 1.960 two-tailed and 1.645 one-tailed at α = 0.05. What changes with n is the standard error. Quadruple the sample and the standard error halves, so the same raw difference produces a z twice as large.

4.7 One-tailed or two-tailed: decide before you look

A one-tailed test puts all of α in one tail, so it rejects H0 sooner, at z = 1.645 instead of 1.96, but only in the direction you predicted. Choosing the tail after seeing the data doubles your real false-positive rate. Use a one-tailed test only when a result in the other direction would lead to exactly the same action as no result, as in a quality check that only cares if the defect rate is too high.

4.8 Statistical significance versus practical importance

With 1,600 exam scripts, a mean of 506 against 500 with σ = 100 gives z = 2.40 and p = 0.016. That is significant, but Cohen’s d is 0.06, a shift of six points on a scale with a spread of one hundred. Always pair the p-value with the raw difference, the interval and the effect size, and ask a subject expert whether the gap matters.

4.9 What a non-significant result does and does not mean

“Fail to reject H0” means the data are compatible with μ0. It does not prove that μ equals μ0. A small study can miss a real effect, which is why this tool reports observed power and the n needed for 80% power. If the confidence interval is wide and includes both trivial and important values, the honest conclusion is that the study was inconclusive.

4.10 When the known σ is wrong

The whole test rests on σ. If the true spread is larger than the value you entered, the standard error is too small, z is inflated and you get false positives. The assumption panel compares your sample SD with σ using a chi-square test. A sample SD far from σ is a sign that the stated σ does not apply to this population, and the one-sample t test is the safer choice.

Common mistakes this calculator prevents: using the sample SD as if it were σ (the tool asks for σ separately and warns when s disagrees), reporting a one-tailed p as two-tailed (the tail is stated beside every p), ignoring multiple groups (Holm-adjusted p is shown automatically), using the normal approximation for a rare proportion (the exact binomial p is shown beside it), and reporting p without an effect size.

4.11 Decision guide

You seeWhat to concludeWhat to report
p < α, CI excludes μ0, d ≥ 0.5A real and meaningful differencez, p, CI and d, in the direction of the effect
p < α, d < 0.2Real but probably trivialStress the effect size and the raw difference
p just above α, power < 50%Inconclusive, the study was too smallThe CI and the n needed for 80% power
p > α, narrow CI around μ0Good evidence the mean is close to μ0The CI, which rules out large differences
Assumption panel shows a concernThe p-value may be wrongRun the t test, sign test or exact binomial test instead

✍ 5. How to Write Your Results in Research

▶ Run the analysis above to auto-fill all five examples with your results. Before that, they show the leaf-length worked example.

Example 1, APA 7th Edition
A two-tailed one-sample z test showed that mean leaf length (M = 52.44 mm, σ = 4, n = 16) differed significantly from the hypothesised population mean of 50 mm, z = 2.44, p = .015, d = 0.61, 95% CI [50.48, 54.40].
📌 Key conventions for this style
  • Italicise z, p, M and d. Report z to two decimals.
  • Give exact p to three decimals, and write p < .001 below that. No leading zero on p.
  • State the tail and that σ was known, and where σ came from.
  • Always add the effect size and the confidence interval.
Example 2, Thesis / Dissertation
To test whether mean leaf length differed from the regional benchmark of 50 mm, a two-tailed one-sample z test was conducted at α = 0.05, using a population standard deviation of σ = 4 mm taken from long-term herbarium records. The sample of n = 16 gave a mean of 52.44 mm (z = 2.44, p = .015). The null hypothesis was rejected. The 95% confidence interval was [50.48, 54.40] and the effect size was d = 0.61, a medium effect.
📌 Key conventions for this style
  • Justify the source of σ in the Methods chapter. Examiners always ask.
  • State the hypotheses, α and the tail before the result.
  • Mention the assumption checks and their outcome.
  • Name the software and version used.
Example 3, Plain-Language Summary
We measured 16 leaves. On average they were 52.4 mm long, compared with the usual 50 mm. This gap is too large to be explained by chance alone. The true average is probably between 50.5 and 54.4 mm.
📌 Key conventions for this style
  • Never write z, p or Greek letters.
  • Say “too large to be chance” rather than “significant”.
  • Give the units every time a number appears.
  • Explain the range of likely values in plain words.
Example 4, Structured Abstract / Conference Poster
Objective: test whether mean leaf length differs from 50 mm. Methods: two-tailed one-sample z test, σ = 4 mm, α = 0.05, n = 16. Results: M = 52.44 mm; z = 2.44, p = .015; d = 0.61; 95% CI [50.48, 54.40]. Conclusion: leaves at this site are longer than the regional benchmark.
📌 Key conventions for this style
  • Keep each heading to one line.
  • Use the same decimals in every row.
  • Put the effect size next to the p-value, not in a separate box.
  • On a poster, place chart 1 or chart 3 beside this block.
Example 5, Replication / Pre-Registration
Pre-registered hypothesis: H0: μ = 50 versus H1: μ ≠ 50, two-tailed, α = 0.05. Population SD fixed in advance at σ = 4 mm. Planned n = 16. Observed: z = 2.44, p = .015, d = 0.61. To replicate this effect with 80% power, n = 22 is required.
📌 Key conventions for this style
  • Fix μ0, σ, α, the tail and n before collecting data.
  • Report any deviation from the plan.
  • Give the n needed for 80% power so others can replicate.
  • Share the raw data or the summary statistics.

5.1 Methods wording

Name the test, the tail, α, μ0 and the source of σ: “A two-tailed one-sample z test (α = 0.05) compared the sample mean with μ0 = 50 mm, using σ = 4 mm from long-term records.” For proportions, say “a one-sample z test for a proportion compared p̂ with p0 = 0.50” and state whether a continuity correction was used.

5.2 The results sentence

Lead with the direction and size of the difference, then the statistics in brackets: the mean or proportion, z, p, the effect size and the interval. Readers should be able to understand the finding without the brackets.

5.3 Tables and figures

In a table, use columns for n, x̄ or p̂, μ0 or p0, z, p, d or h and the CI. Chart 1 (z on the normal curve) suits teaching; chart 3 (the forest plot) suits papers with several groups.

5.4 The discussion sentence

Interpret the interval, not just the decision: “the data are consistent with an increase of between 0.5 and 4.4 mm, a medium effect that is large enough to matter for the growth model.”

5.5 Reporting checklist

  • ✓ Hypotheses and tail stated
  • ✓ Source of σ given (mean test) or n·p0 condition met (proportion test)
  • ✓ z to two decimals and exact p
  • ✓ Effect size with its label
  • ✓ Confidence interval with its level
  • ✓ Multiple-group correction named, if used

∑ 6. Formulas Used

①
One Sample Z Test Statistic for a Mean
z = (x̄ − μ0) ÷ (σ ÷ √n)
zTest statistic, unitless, compared with the standard normal distribution
x̄Sample mean, in the units of the measurement
μ0Hypothesised population mean under H0, same units
σKnown population standard deviation, same units
nNumber of observations
Requiresσ known from outside the sample; normal data or n ≥ 30
Example(52.4375 − 50) ÷ (4 ÷ 4) = 2.4375
②
One Sample Z Test for a Proportion
p̂ = x ÷ n  ·  z = (p̂ − p0) ÷ √(p0(1 − p0) ÷ n)
p̂Sample proportion, 0 to 1
xNumber of successes, a count
p0Hypothesised proportion under H0, 0 to 1
nSample size, a count
Rulen·p0 ≥ 10 and n(1 − p0) ≥ 10, or use the exact binomial test
NoteThe SE uses p0, not p̂, because it is computed as if H0 were true
Example280 of 500: (0.56 − 0.5) ÷ 0.02236 = 2.683
③
Standard Error
SE = σ ÷ √n  ·  SEp = √(p0(1 − p0) ÷ n)
SEStandard deviation of the sample mean across repeated samples, data units
SEpStandard error of a proportion under H0, unitless
PropertyQuadrupling n halves the standard error
Example4 ÷ √16 = 1 mm
④
p-Value and Critical Value
ptwo = 2(1 − Φ(|z|))  ·  pright = 1 − Φ(z)  ·  pleft = Φ(z)
ΦStandard normal cumulative distribution function
zcritΦ⁻¹(1 − α÷2) two-tailed, Φ⁻¹(1 − α) one-tailed
αSignificance level chosen before the test, usually 0.05
RuleReject H0 when p < α, which is the same as z beyond zcrit
Example2(1 − Φ(2.4375)) = 0.0148
⑤
Confidence Intervals
x̄ ± zα/2 · σ ÷ √n  ·  Wilson: (p̂ + z²÷2n ± z√(p̂(1 − p̂)÷n + z²÷4n²)) ÷ (1 + z²÷n)
zα/21.960 for 95%, 2.576 for 99%
Use forThe range of population values compatible with the data
NoteWilson stays inside 0 to 1 and covers better than Wald when p̂ is near 0 or 1
Example52.4375 ± 1.96 × 1 = [50.48, 54.40]
⑥
Effect Size
d = (x̄ − μ0) ÷ σ  ·  h = 2·asin√p̂ − 2·asin√p0
dCohen’s d, difference in units of σ, unitless
hCohen’s h for proportions, unitless
Range0.2 small, 0.5 medium, 0.8 large (Cohen, 1992)
Linkz = d × √n, so z grows with n while d does not
Example2.4375 ÷ 4 = 0.61, a medium effect
⑦
Power and Sample Size
Power = 1 − Φ(zα/2 − d√n) + Φ(−zα/2 − d√n)  ·  n = ((zα/2 + zβ) ÷ d)²
zβ0.8416 for 80% power, 1.2816 for 90% power
PowerChance of rejecting H0 when the true effect is d, 0 to 1
NoteFor a one-tailed test replace zα/2 with zα and drop the second term
Exampled = 0.61, n = 16 gives power 0.68; 80% needs n = 22

🔀 7. One Sample Z Test Calculation Flowchart, Step by Step

This flowchart shows how the one sample z test is calculated, step by step, from a raw column of numbers to a reportable decision. Every box uses the same worked example as the Excel, R and Python sections: 16 leaf lengths in mm, tested against μ0 = 50 mm with a known σ of 4 mm.

Start or result Data step Calculation step Yes or no check
StartRaw measurements and a null value16 leaf lengths in mm; H0: μ = 50, H1: μ ≠ 50, α = 0.05
CheckIs σ known from outside this sample?
YesCarry on. Here σ = 4 mm comes from long-term records.
No, stopUse the one-sample t test with the sample SD instead.
1
Put every value in one column and count themn = number of values52, 48, 55, 61, 47, 50, 58, 53, 49, 56, 51, 54, 46, 57, 50, 52 → n = 16
CheckIs n ≥ 30, or do the data look roughly normal?
Yesn is 16, but the K² normality test gives p = 0.75 and skew is 0.39, so the normal model is fine.
No, stopSmall and skewed: use the sign test or Wilcoxon signed-rank test.
2
Find the sample meanx̄ = Σx ÷ n839 ÷ 16 = 52.4375 mm
3
Find the standard errorSE = σ ÷ √n4 ÷ √16 = 4 ÷ 4 = 1.0000 mm
4
Compute the z statisticz = (x̄ − μ0) ÷ SE(52.4375 − 50) ÷ 1 = 2.4375
5
Turn z into a p-valuep = 2(1 − Φ(|z|))2 × (1 − 0.99260) = 0.0148
6
Build the interval and the effect sizex̄ ± 1.96 × SE  ·  d = (x̄ − μ0) ÷ σ95% CI [50.48, 54.40]  ·  d = 0.61
Resultz = 2.44, p = 0.0148, d = 0.61, 95% CI [50.48, 54.40]Significant Medium effectRule: reject H0 because p < 0.05 and |z| > 1.96. Cohen’s d of 0.5 to 0.8 is medium.

Check any box yourself: the Excel sheet in Section 9, the R script in Section 10 and the Python script in Section 11 all return x̄ = 52.4375, z = 2.4375 and p = 0.0148 for this dataset.

📝 8. How to Use This Calculator

  1. Choose what you are testing. Pick a mean with known population σ, or a proportion, in the "What are you testing?" box.
  2. Enter your data. Paste comma-separated numbers into the group box, in the format 52, 48, 55, 61, 47. Newlines, tabs and spaces also work, so a column copied from Excel is fine.
  3. Or switch to summary statistics. Set Data format to Summary statistics and type the sample mean and n, or the number of successes x and n for a proportion.
  4. Name each group. Click the group name and type something meaningful such as Clinic A. It flows into the tables, charts and reports.
  5. Add more groups or upload a file. Press Add group, or use the Upload tab and click the columns you want. Every selected column becomes its own group.
  6. Set the null value and sigma. Type the hypothesised mean μ0 and the known σ, or the hypothesised proportion p0.
  7. Pick the tail and alpha. Choose two-tailed, right-tailed or left-tailed, and the significance level, before you look at the result.
  8. Press Run One Sample Z Test. Nothing is computed until you press Run. Changing any setting clears the old results.
  9. Read the cards, table and assumption checks. Start with the decision line, then the confidence interval and effect size, then the assumption panel.
  10. Copy a report or export. Section 5 fills five reporting styles with your numbers. Download Doc gives a text report and Download PDF a printable one.

Worked example: load sample 1, keep μ0 = 50, σ = 4, two-tailed, α = 0.05, and press Run. You should see z = 2.44, p = 0.0148 and the 95% CI [50.48, 54.40].

📈 9. How to Run a One Sample Z Test in Excel

Excel has a Z.TEST function, but it trips up almost everyone: it returns a one-tailed p-value for the upper tail, and if you leave out σ it quietly uses the sample SD instead. The safest way is to build the test from AVERAGE, SQRT and NORM.S.DIST, which shows every step and gives exactly the same answer as this calculator.

The whole thing in one line: with your data in A2:A17, μ0 = 50 and σ = 4, type =2*(1-NORM.S.DIST(ABS((AVERAGE(A2:A17)-50)/(4/SQRT(COUNT(A2:A17)))),TRUE)) for the two-tailed p-value. It returns 0.0148.

9.1 The functions you need

You wantExcel functionNote
n=COUNT(A2:A17)COUNT skips blanks and text, COUNTA does not
Sample mean=AVERAGE(A2:A17)Ignores blank cells
Standard error=C3/SQRT(C4)σ in C3, n in C4
z statistic=(C5-C2)/C6Mean minus μ0, over SE
Two-tailed p=2*(1-NORM.S.DIST(ABS(C7),TRUE))TRUE means the cumulative area
Right-tailed p=1-NORM.S.DIST(C7,TRUE)H1: μ greater than μ0
Left-tailed p=NORM.S.DIST(C7,TRUE)H1: μ less than μ0
Critical z=NORM.S.INV(0.975)1.96 for α = 0.05 two-tailed
Built-in test=Z.TEST(A2:A17,50,4)Upper one-tailed p only, see the warning below
Cohen’s d=(C5-C2)/C3No built-in function
The Z.TEST trap. =Z.TEST(A2:A17,50,4) returns 0.0074, the area to the right of z, not the two-tailed p of 0.0148. For a two-tailed p use =2*MIN(Z.TEST(A2:A17,50,4),1-Z.TEST(A2:A17,50,4)). If you leave out the third argument, Excel replaces σ with STDEV.S of the data, which turns the test into a t test with the wrong distribution. The Analysis ToolPak has no one-sample z test at all; its “z-Test: Two Sample for Means” is a different test.

9.2 Step by step

1 Put your numbers in one column

Paste the 16 leaf lengths down column A with a label in A1. Formulas ignore the header automatically.

Xztest.xlsx - ExcelA2fx52A1Leaf length (mm)252348455561647750858953

The 16 measurements sit in A2:A17. Only the first eight rows are shown here.

2 Type μ0 and σ, then count n

Put the null mean in C2 and the known σ in C3. Count the values in C4 with COUNT, never by hand.

=COUNT(A2:A17)
Xztest.xlsx - ExcelC4fx=COUNT(A2:A17)ABC1LengthStatisticValue252μ050348σ (known)4455n16561647750858953

C2 holds μ0 = 50, C3 holds σ = 4 and C4 returns n = 16.

3 Find the mean and the standard error

The mean goes in C5 and the standard error, σ divided by the square root of n, in C6.

=AVERAGE(A2:A17)=C3/SQRT(C4)
Xztest.xlsx - ExcelC6fx=C3/SQRT(C4)ABC1LengthStatisticValue252μ050348σ (known)4455n16561Mean52.4375647SE1.0000750858953

C5 = 52.4375 and C6 = 1.0000.

4 Compute z

Subtract μ0 from the mean and divide by the standard error.

=(C5-C2)/C6
Xztest.xlsx - ExcelC7fx=(C5-C2)/C6ABC1LengthStatisticValue252μ050348σ (known)4455n16561Mean52.4375647SE1.0000750z2.4375858953

C7 = 2.4375, so the mean sits 2.44 standard errors above 50.

5 Turn z into a two-tailed p-value

NORM.S.DIST with TRUE gives the area to the left of z. One minus that, doubled, is the two-tailed p.

=2*(1-NORM.S.DIST(ABS(C7),TRUE))
Xztest.xlsx - ExcelC8fx=2*(1-NORM.S.DIST(ABS(C7),TRUE))ABC1LengthStatisticValue252μ050348σ (known)4455n16561Mean52.4375647SE1.0000750z2.4375858p, two-tailed0.0148953

C8 = 0.0148, below 0.05, so H0 is rejected.

6 Add the 95% confidence interval

The interval is the mean plus or minus the critical z times the standard error.

=C5-NORM.S.INV(0.975)*C6=C5+NORM.S.INV(0.975)*C6
Xztest.xlsx - ExcelC10fx=C5+NORM.S.INV(0.975)*C6ABC1LengthStatisticValue252μ050348σ (known)4455n16561Mean52.4375647SE1.0000750z2.4375858p, two-tailed0.0148953CI lower50.47751049CI upper54.3975

C9 = 50.4775 and C10 = 54.3975. The interval does not contain 50.

9.3 The awkward cases

A proportion. With 280 successes in 500 and p0 = 0.5, z is =(280/500-0.5)/SQRT(0.5*(1-0.5)/500), which returns 2.6833, and the two-tailed p is =2*(1-NORM.S.DIST(ABS(2.6833),TRUE)) = 0.0073. Because p0 = 0.5 is symmetric, the exact two-tailed binomial p is =2*(1-BINOM.DIST(279,500,0.5,TRUE)) = 0.0083, a useful check that the normal approximation is close. The classic mistake is putting p̂ instead of p0 inside the square root.

Summary statistics only. If you have x̄, n and σ but not the raw data, type them into C5, C4 and C3 directly and the remaining formulas work unchanged.

A one-tailed test. Use =1-NORM.S.DIST(C7,TRUE) for H1: μ > μ0 and =NORM.S.DIST(C7,TRUE) for H1: μ < μ0. Never halve the two-tailed p when z points the wrong way.

9.4 Why your Excel answer might differ from R or Python

SituationWhat happensFix
Z.TEST without σExcel uses STDEV.S, so the result is not a z test with known σAlways pass σ as the third argument
Z.TEST read as two-tailedIt is upper one-tailed, half the two-tailed p when z is positiveUse the 2*MIN(...) formula in 9.1
Python statsmodels ztestIt estimates σ from the sample SD, there is no known-σ argumentCompute z by hand with scipy.stats.norm, as in Section 11
R has no base z.test()BSDA::z.test(x, mu = 50, sigma.x = 4) exists in a packageUse the base-R script in Section 10, which agrees to every decimal
Blank cells or textCOUNT and AVERAGE skip them silently, so n shrinksCheck that C4 matches the number of rows you expect
Zeros typed for missing dataCounted as real values and drag the mean downLeave missing cells blank
Rounding shown vs storedA displayed 2.44 may be 2.4375 underneathReference cells, never retype rounded values
Proportion test in R prop.testApplies a continuity correction by default and reports chi-square = z²Use correct = FALSE to match the standard z test

9.5 Charting the result in Excel

Select A2:A17 and insert a Scatter chart with the values on the x axis and a constant y, then add two vertical lines for the mean and μ0 as extra series. For a normal-curve figure, fill a column with z from −4 to 4 in steps of 0.1, compute =NORM.S.DIST(B2,FALSE) beside it and insert a Scatter with Smooth Lines. Remove the gridlines and label the axes with units, the two changes that make the chart publication-ready.

9.6 Excel errors you will probably hit

ErrorCauseFix
#DIV/0!n is 0 or σ is blank, so the SE divides by zeroCheck C3 and C4
#NUM!NORM.S.INV given a probability of 0 or 1, or a negative under SQRTUse 0.975, not 97.5
#VALUE!A number stored as text inside a formula referenceUse Data, Text to Columns, or VALUE()
#NAME?Old Excel without NORM.S.DISTUse NORMSDIST(z) in Excel 2007 and earlier

📈 10. How to Run a One Sample Z Test in R

Base R has t.test() but no z.test(), because a known σ is rare in practice. The good news is that a one sample z test in R takes four lines with pnorm() and qnorm(). The script below is complete: it computes z, the p-value for any tail, the confidence interval, Cohen’s d and power, prints a plain-English verdict, and saves one publication-ready figure at 300 dpi.

Copy the whole block. It runs top to bottom in RStudio, VS Code or plain Rscript. Change only the x <- c(...) line, plus mu0 and sigma.
statspnorm, qnorm, ships with R
graphicsplot, polygon, stripchart
BSDA (optional)z.test() one-liner in 10.5

10.1 The complete script

R, base only, saves z_test_plot.png

# ============================================================
# One sample z test with one publication-ready figure
# StatsUnlock - https://statsunlock.com/one-sample-z-test-calculator/
# Base R only, nothing to install
# ============================================================

# ---- 1. Your data: change only this line --------------------
x <- c(52, 48, 55, 61, 47, 50, 58, 53, 49, 56, 51, 54, 46, 57, 50, 52)
# x <- read.csv("leaves.csv")$length_mm
x <- x[!is.na(x)]                      # drop missing values

mu0   <- 50      # hypothesised mean
sigma <- 4       # KNOWN population SD, not sd(x)
alpha <- 0.05
tail  <- "two"   # "two", "greater" or "less"

# ---- 2. The test ---------------------------------------------
n    <- length(x)
xbar <- mean(x)
se   <- sigma / sqrt(n)
z    <- (xbar - mu0) / se
p <- switch(tail,
            two     = 2 * pnorm(-abs(z)),
            greater = pnorm(z, lower.tail = FALSE),
            less    = pnorm(z))
zc    <- qnorm(1 - alpha / 2)
ci    <- xbar + c(-1, 1) * zc * se
d     <- (xbar - mu0) / sigma
power <- pnorm(zc - d * sqrt(n), lower.tail = FALSE) + pnorm(-zc - d * sqrt(n))
n80   <- ceiling(((zc + qnorm(0.80)) / d)^2)

# ---- 3. Printed summary --------------------------------------
cat(sprintf("n = %d, mean = %.4f, sample SD = %.4f\n", n, xbar, sd(x)))
cat(sprintf("SE = %.4f, z = %.4f, p (%s) = %.4f\n", se, z, tail, p))
cat(sprintf("95%% CI = [%.4f, %.4f], Cohen's d = %.4f\n", ci[1], ci[2], d))
cat(sprintf("power = %.4f, n for 80%% power = %d\n", power, n80))
size <- if (abs(d) < 0.5) "small" else if (abs(d) < 0.8) "medium" else "large"
if (p < alpha) {
  cat(sprintf("Verdict: p is below %.2f and d is %.2f (%s), so the mean differs from %g.\n", alpha, d, size, mu0))
} else {
  cat(sprintf("Verdict: p is %.3f, above %.2f, so there is no evidence the mean differs from %g.\n", p, alpha, mu0))
}

# ---- 4. One 300 dpi figure -----------------------------------
set.seed(1)                                   # reproducible jitter
png("z_test_plot.png", width = 3000, height = 1200, res = 300)
par(mfrow = c(1, 2), mar = c(4.2, 4.2, 2.5, 1))
g <- seq(-4, 4, length.out = 400)
plot(g, dnorm(g), type = "l", lwd = 2, col = "#2563eb",
     xlab = "z", ylab = "Density", main = "z on the standard normal curve")
hi <- g[g >= zc];  polygon(c(zc, hi, 4),  c(0, dnorm(hi), 0), col = "#fdba74", border = NA)
lo <- g[g <= -zc]; polygon(c(-4, lo, -zc), c(0, dnorm(lo), 0), col = "#fdba74", border = NA)
abline(v = z, col = "#7c3aed", lwd = 3)
legend("topleft", legend = sprintf("z = %.2f", z), bty = "n")
stripchart(x, method = "jitter", pch = 19, col = "#16a34a", ylim = c(0.5, 1.5),
           xlab = "Leaf length (mm)", main = "Data, mean and 95% CI")
abline(v = xbar, col = "#7c3aed", lwd = 3)
abline(v = mu0, col = "#ea580c", lwd = 2, lty = 2)
segments(ci[1], 0.6, ci[2], 0.6, col = "#0d9488", lwd = 6)
dev.off()

Expected output: n = 16, mean = 52.4375, SE = 1.0000, z = 2.4375, p (two) = 0.0148, 95% CI = [50.4775, 54.3975], Cohen’s d = 0.6094, power = 0.6835, n for 80% power = 22.

10.2 What each part does

Line or functionWhat it does, and why it is there
x <- c(...)Builds the data vector. Swap in read.csv() for a file, and keep x[!is.na(x)] because mean() returns NA if one value is missing.
sigma <- 4The known population SD. Never set it to sd(x); that is a t test.
se <- sigma / sqrt(n)The standard error of the mean under the known σ.
pnorm(-abs(z))Lower-tail area beyond |z|. Doubling it gives the two-tailed p.
pnorm(z, lower.tail = FALSE)Upper-tail area, more accurate than 1 - pnorm(z) for large z.
qnorm(1 - alpha / 2)The critical value, 1.959964 for α = 0.05.
power <- ...Power of the two-tailed test if the true effect equals the observed d.
png(..., res = 300)Opens a 300 dpi file; dev.off() closes and writes it.

10.3 What the figure shows

The left panel is the standard normal curve with the 2.5% rejection tails shaded orange and the observed z of 2.44 as a purple line inside the upper tail. The right panel shows the 16 leaves as jittered points, the sample mean in purple, μ0 = 50 as a dashed orange line and the 95% CI as a teal bar that stops short of 50.

10.4 Common R problems and fixes

ProblemFix
could not find function "z.test"Base R has none. Use this script or install.packages("BSDA").
Result matches t.test(), not this pageYou used sd(x) as sigma. Use the known value.
p is exactly 0Print with format.pval(p); R gives about 1e-300 before underflow.
prop.test() p differs from the z testAdd correct = FALSE; its chi-square equals z squared.
Figure is blankYou forgot dev.off(), or ran the script line by line in a different folder.
NA in the meanKeep the x[!is.na(x)] line.

10.5 Useful one-liners

BSDA::z.test(x, mu = 50, sigma.x = 4)                    # packaged one sample z test
prop.test(280, 500, p = 0.5, correct = FALSE)            # proportion z test (X-squared = z^2)
binom.test(280, 500, p = 0.5)                            # exact check for a proportion
pnorm(2.4375, lower.tail = FALSE)                        # right-tailed p from a z value
qnorm(c(0.95, 0.975, 0.995))                             # critical values 1.645, 1.960, 2.576
ceiling(((qnorm(0.975) + qnorm(0.8)) / 0.5)^2)           # n for 80% power at d = 0.5
sapply(split(df$y, df$site), function(v) (mean(v) - 50) / (4 / sqrt(length(v))))  # z per site

📈 11. How to Run a One Sample Z Test in Python

SciPy has no ready-made one-sample z test with a known σ, and the ztest in statsmodels estimates σ from your data, which is not the same test. The script below computes the one sample z test directly with scipy.stats.norm, prints a verdict, and saves one 300 dpi figure. It matches this calculator, Excel and R to every decimal.

Copy the whole block. Change only the x = np.array([...]) line and the mu0, sigma line.
numpyarrays and the arithmetic
scipy.statsnorm.sf, norm.cdf, norm.ppf
matplotlibthe figure
pandas (optional)reading a CSV

Install with pip install numpy scipy matplotlib if you do not already have them.

11.1 The complete script

Python 3, saves z_test_plot.png

# ============================================================
# One sample z test with one publication-ready figure
# StatsUnlock - https://statsunlock.com/one-sample-z-test-calculator/
# ============================================================
import numpy as np
from scipy import stats
import matplotlib
matplotlib.use("Agg")                 # remove this line in Jupyter
import matplotlib.pyplot as plt

# ---- 1. Your data: change only this line --------------------
x = np.array([52, 48, 55, 61, 47, 50, 58, 53, 49, 56, 51, 54, 46, 57, 50, 52], dtype=float)
# import pandas as pd; x = pd.read_csv("leaves.csv")["length_mm"].to_numpy(dtype=float)
x = x[~np.isnan(x)]                   # drop missing values

mu0, sigma, alpha = 50.0, 4.0, 0.05   # null mean, KNOWN population SD, alpha
tail = "two"                          # "two", "greater" or "less"

# ---- 2. The test ---------------------------------------------
n = x.size
xbar = x.mean()
se = sigma / np.sqrt(n)
z = (xbar - mu0) / se
if tail == "two":
    p = 2 * stats.norm.sf(abs(z))
elif tail == "greater":
    p = stats.norm.sf(z)
else:
    p = stats.norm.cdf(z)
zc = stats.norm.ppf(1 - alpha / 2)
ci = (xbar - zc * se, xbar + zc * se)
d = (xbar - mu0) / sigma
power = stats.norm.sf(zc - d * np.sqrt(n)) + stats.norm.cdf(-zc - d * np.sqrt(n))
n80 = int(np.ceil(((zc + stats.norm.ppf(0.80)) / d) ** 2))

# ---- 3. Printed summary --------------------------------------
print(f"n = {n}, mean = {xbar:.4f}, sample SD = {x.std(ddof=1):.4f}")
print(f"SE = {se:.4f}, z = {z:.4f}, p ({tail}) = {p:.4f}")
print(f"95% CI = [{ci[0]:.4f}, {ci[1]:.4f}], Cohen's d = {d:.4f}")
print(f"power = {power:.4f}, n for 80% power = {n80}")
size = "small" if abs(d) < 0.5 else ("medium" if abs(d) < 0.8 else "large")
if p < alpha:
    print(f"Verdict: p is below {alpha} and d is {d:.2f} ({size}), so the mean differs from {mu0}.")
else:
    print(f"Verdict: p is {p:.3f}, above {alpha}, so there is no evidence the mean differs from {mu0}.")

# ---- 4. One 300 dpi figure -----------------------------------
rng = np.random.default_rng(1)        # seeded jitter, reproducible
fig, ax = plt.subplots(1, 2, figsize=(10, 4))
g = np.linspace(-4, 4, 400)
ax[0].plot(g, stats.norm.pdf(g), color="#2563eb", lw=2)
ax[0].fill_between(g, stats.norm.pdf(g), where=abs(g) >= zc, color="#fdba74")
ax[0].axvline(z, color="#7c3aed", lw=2.5, label=f"z = {z:.2f}")
ax[0].set(title="z on the standard normal curve", xlabel="z", ylabel="Density")
ax[0].legend(frameon=False)
ax[1].scatter(x, rng.uniform(0.2, 0.8, n), color="#16a34a", alpha=0.7)
ax[1].axvline(xbar, color="#7c3aed", lw=2.5, label=f"mean = {xbar:.2f}")
ax[1].axvline(mu0, color="#ea580c", ls="--", lw=2, label=f"mu0 = {mu0:g}")
ax[1].hlines(0.05, ci[0], ci[1], color="#0d9488", lw=5, label="95% CI")
ax[1].set(title="Data, mean and 95% CI", xlabel="Leaf length (mm)", yticks=[], ylim=(0, 1))
ax[1].legend(frameon=False, fontsize=8)
fig.tight_layout()
fig.savefig("z_test_plot.png", dpi=300, bbox_inches="tight")

Printed output: n = 16, mean = 52.4375, sample SD = 4.1947; SE = 1.0000, z = 2.4375, p (two) = 0.0148; 95% CI = [50.4775, 54.3975], Cohen’s d = 0.6094; power = 0.6835, n for 80% power = 22.

11.2 What each part does

Line or functionWhat it does, and why it is there
dtype=floatAvoids integer surprises and lets np.isnan work.
x[~np.isnan(x)]Drops missing values, because np.mean returns nan if any value is nan.
stats.norm.sf(abs(z))Survival function, the upper tail. More accurate than 1 - cdf far out in the tail.
stats.norm.ppf(1 - alpha / 2)Critical value, 1.959964 at α = 0.05.
x.std(ddof=1)The sample SD, printed only to compare with σ. NumPy’s default ddof=0 is the population formula.
default_rng(1)Seeded jitter so the figure is identical every run.
savefig(dpi=300)Writes the figure at print resolution.

11.3 What the figure shows

The same two panels as the R figure: the observed z of 2.44 inside the shaded upper rejection region of the standard normal curve, and the raw leaf lengths with the sample mean, μ0 and the 95% confidence interval, which lies entirely above 50 mm.

11.4 Common Python problems and fixes

ProblemFix
statsmodels ztest gives a different zIt uses the sample SD. Compute z with the known σ as in the script.
proportions_ztest differs from this pageIt uses p̂ in the SE by default. Pass prop_var=0.5 (your p0) to use the null SE.
p prints as 0.0Use stats.norm.logsf(z) or format with :.3e.
Figure window never appearsRemove matplotlib.use("Agg") and add plt.show().
ModuleNotFoundError: scipyRun pip install scipy in the same environment as Python.

11.5 Useful one-liners

from statsmodels.stats.proportion import proportions_ztest
proportions_ztest(280, 500, value=0.5, prop_var=0.5)          # proportion z test, null SE
from scipy.stats import binomtest; binomtest(280, 500, 0.5)    # exact check for a proportion
stats.norm.sf(2.4375)                                          # right-tailed p from z
stats.norm.ppf([0.95, 0.975, 0.995])                           # 1.645, 1.960, 2.576
int(np.ceil(((stats.norm.ppf(0.975) + stats.norm.ppf(0.8)) / 0.5) ** 2))  # n for 80% power, d = 0.5
df.groupby("site")["y"].apply(lambda v: (v.mean() - 50) / (4 / np.sqrt(len(v))))  # z per site

Run it with python script.py from a terminal. In Jupyter, drop the matplotlib.use("Agg") and savefig lines and add plt.show().

📋 12. Reference Tables

12.1 Critical z values

αTwo-tailed (±)One-tailedConfidence level
0.101.6451.28290%
0.051.9601.64595%
0.012.5762.32699%
0.0013.2913.09099.9%

What to conclude: reject H0 when |z| passes the value in your row. These never change with n, unlike t critical values. Values from the standard normal quantile function (Wichura, 1988).

12.2 z to p-value lookup

|z|Two-tailed pOne-tailed p
1.0000.31730.1587
1.2820.19980.0999
1.5000.13360.0668
1.6450.10000.0500
1.9600.05000.0250
2.0000.04550.0228
2.3260.02000.0100
2.5000.01240.0062
2.5760.01000.0050
3.0000.00270.0013
3.2910.00100.0005

What to conclude: the one-tailed p is exactly half the two-tailed p when z points in the predicted direction. The worked example, z = 2.4375, sits between 2.326 and 2.500, so its two-tailed p of 0.0148 lies between 0.0200 and 0.0124.

12.3 Cohen’s d bands and the sample size for 80% power

dLabeln for 80% power, two-tailed α = 0.05n, one-tailed
0.1Negligible785619
0.2Small197155
0.3Small8869
0.5Medium3225
0.8Large1310
1.0Large87

What to conclude: halving the effect you want to detect roughly quadruples the sample you need. From n = ((zα/2 + zβ) ÷ d)², bands from Cohen (1992).

12.4 Power at d = 0.5 for different n

n10203050100
Power, two-tailed α = 0.050.3530.6090.7820.9420.999

What to conclude: a study of 10 detects a medium effect only about one time in three. A non-significant result from such a study tells you very little.

12.5 z versus t critical values, two-tailed α = 0.05

n510153060120∞
t critical (df = n − 1)2.7762.2622.1452.0452.0011.9801.960
z critical1.9601.9601.9601.9601.9601.9601.960

What to conclude: using z when σ is really estimated makes the bar too low, most of all in small samples. At n = 10 the correct cut-off is 2.262, not 1.960, so a z test would produce too many false positives.

12.6 Minimum n for the one proportion z test (n·p0 ≥ 10 and n(1 − p0) ≥ 10)

p00.500.300.200.100.050.030.01
Minimum n2034501002003341000

What to conclude: rare outcomes need large samples before the normal approximation is safe. Below these sizes, report the exact binomial p shown in the results table (Brown, Cai and DasGupta, 2001).

📈 13. Example Results

Eight worked one sample z test examples with solutions, from the textbook case to a test that should not be used. Every example is also a built-in sample dataset in Section 2, so you can load it and check the numbers yourself.

1
TEXTBOOK CASE

Leaf length in a botany practical

The worked example used in every section of this page.

Sixteen leaves measured to the nearest mm. Herbarium records give a regional mean of 50 mm with σ = 4 mm.

n = 16x̄ = 52.44σ = 4z = 2.44p = 0.0148
-4-3-2-101234z = 2.44z
z = 2.44 lies inside the upper 2.5% tail.
StatisticValueNote
x̄52.4375 mmSample mean
SE1.00004 ÷ √16
z2.4375Two-tailed
p0.0148Below 0.05
95% CI[50.48, 54.40]Excludes 50
d0.61Medium

What it means: Leaves at this site are longer than the regional benchmark by about 2.4 mm, a medium effect.

How to write it: Mean leaf length (M = 52.44 mm) was significantly greater than 50 mm, z = 2.44, p = .015, d = 0.61.

2
CLEARLY SIGNIFICANT

IQ after a reading programme

IQ is scaled to σ = 15, the classic known-sigma case.

Thirty pupils finished a reading programme. Does their mean IQ exceed the population mean of 100? Right-tailed test.

n = 30x̄ = 106.17σ = 15z = 2.25p = 0.0122
-4-3-2-101234z = 2.25z
All of α sits in the right tail beyond 1.645.
StatisticValueNote
x̄106.17Sample mean
SE2.738615 ÷ √30
z2.2517Right-tailed
p0.0122Below 0.05
95% CI[100.80, 111.53]Above 100
d0.41Small to medium

What it means: The programme group scores about 6 IQ points higher than the population, a small to medium effect.

How to write it: Pupils in the programme scored higher than the population mean of 100 (M = 106.17), z = 2.25, p = .012, one-tailed, d = 0.41.

3
BORDERLINE

Cereal box fill weight

A result just inside α that needs careful wording.

Thirty-six boxes from line 2. The machine has a long-run σ of 3 g and a target of 500 g.

n = 36x̄ = 498.96σ = 3z = −2.09p = 0.0367
-4-3-2-101234z = −2.09z
z = −2.09 has only just crossed −1.96.
StatisticValueNote
x̄498.96 gSample mean
SE0.50003 ÷ √36
z−2.0889Two-tailed
p0.0367Just below 0.05
95% CI[497.98, 499.94]Just below 500
d−0.35Small

What it means: Boxes are underfilled by about 1 g. Significant at 0.05 but not at 0.01, so repeat the check before adjusting the machine.

How to write it: Mean fill weight (M = 498.96 g) was significantly below the 500 g target, z = −2.09, p = .037, d = −0.35.

4
NULL RESULT

Systolic blood pressure at Clinic A

Not significant, and the interval explains why.

Twenty-five patients compared with a reference of 120 mmHg and σ = 15 mmHg.

n = 25x̄ = 122.40σ = 15z = 0.80p = 0.4237
-4-3-2-101234z = 0.80z
z = 0.80 sits in the middle of the curve.
StatisticValueNote
x̄122.40 mmHgSample mean
SE3.000015 ÷ 5
z0.8000Two-tailed
p0.4237Far above 0.05
95% CI[116.52, 128.28]Contains 120
Power0.12Very low

What it means: There is no evidence the clinic differs from 120 mmHg, but the interval is wide, so a difference of up to 8 mmHg cannot be ruled out.

How to write it: Mean systolic pressure (M = 122.40 mmHg) did not differ from 120 mmHg, z = 0.80, p = .424, 95% CI [116.52, 128.28].

5
SMALL SAMPLE

Tree diameter in a forest plot

Only ten trees, so normality matters.

Ten trees in plot 7 compared with a regional mean of 30 cm and σ = 6 cm. One tree is only 12.9 cm.

n = 10x̄ = 33.40σ = 6z = 1.79p = 0.0731
-4-3-2-101234z = 1.79z
z = 1.79 falls short of 1.96.
StatisticValueNote
x̄33.40 cmSample mean
SE1.89746 ÷ √10
z1.7920Two-tailed
p0.0731Above 0.05
Skew−1.56Strong left skew
s vs σ8.57 vs 6Spread larger than assumed

What it means: Not significant, and the assumption panel flags skew and a sample SD well above σ. With n = 10 the result is fragile in both directions.

How to write it: Mean diameter (M = 33.40 cm) did not differ significantly from 30 cm, z = 1.79, p = .073; with n = 10 and marked skew this result should be treated as preliminary.

6
SIGNIFICANT BUT TRIVIAL

National exam scores, 1,600 scripts

A huge n makes a tiny gap significant.

District mean of 506 against a national mean of 500 with σ = 100, entered as summary statistics.

n = 1600x̄ = 506σ = 100z = 2.40d = 0.06
-4-3-2-101234z = 2.40z
Statistically clear, practically tiny.
StatisticValueNote
x̄506.00Sample mean
SE2.5000100 ÷ 40
z2.4000Two-tailed
p0.0164Below 0.05
95% CI[501.10, 510.90]Excludes 500
d0.06Negligible

What it means: The district is genuinely a little above the national mean, but six points on a 100-point spread is unlikely to matter for policy.

How to write it: District scores (M = 506) were significantly higher than the national mean of 500, z = 2.40, p = .016, but the effect was negligible, d = 0.06.

7
ASSUMPTION FAILURE

Hospital length of stay, skewed data

What a bad fit for the z test looks like.

Twelve patients, two with long stays of 9 and 14 days. Compared with 4 days and an assumed σ of 2.5.

n = 12x̄ = 4.42σ = 2.5z = 0.58skew = 2.19
-4-3-2-101234z = 0.58z
The z is small, but the test itself is not valid here.
StatisticValueNote
x̄4.42 daysPulled up by two long stays
Median3.00 daysBelow 4
z0.5774Two-tailed
p0.5637Not significant
K² normality p0.0004Strongly non-normal
Outliers29 and 14 days

What it means: With n = 12 and heavy right skew the normal model fails. Use the median with a sign test or Wilcoxon signed-rank test instead.

How to write it: Because length of stay was strongly right-skewed (skewness = 2.19, n = 12), the median (3 days) was reported and tested with a sign test instead of a z test.

8
APPLIED, PROPORTION

Voter support poll

A one sample proportion z test with an exact cross-check.

280 of 500 respondents support a proposal. Is support different from 50%?

x = 280n = 500p̂ = 0.56z = 2.68p = 0.0073
-4-3-2-101234z = 2.68z
z = 2.68 is beyond 1.96 and also beyond 2.576.
StatisticValueNote
p̂0.5600280 ÷ 500
SE under H00.02236√(0.25 ÷ 500)
z2.6833Two-tailed
p0.0073Below 0.01
Wilson 95% CI[0.516, 0.603]Excludes 0.5
Exact binomial p0.0083Agrees

What it means: A majority supports the proposal. The exact test agrees, and the Wilson interval puts support between about 52% and 60%.

How to write it: Support (56.0%, 280 of 500) was significantly higher than 50%, z = 2.68, p = .007, h = 0.12, 95% Wilson CI [0.516, 0.603].

🧪 14. Data Collection Protocol

Study design: the one sample z test assumes one simple random sample of independent observations, measured on an interval or ratio scale (or as success and failure for a proportion), from a population whose standard deviation is known before the data are collected.

  1. Fix the null value before collecting data for the one sample z test. Write down μ0 or p0 and where it comes from: a standard, a target, a census figure or a published benchmark.
  2. Document the source of σ. Name the record, the time span and the population it describes. If you cannot, plan a one-sample t test instead.
  3. Choose the tail and α in advance. A one-tailed one sample z test is only valid if the direction was chosen before seeing the data.
  4. Calculate the sample size for your one sample z test. Use n = ((zα/2 + zβ) ÷ d)². For a medium effect, d = 0.5, you need 32 for 80% power.
  5. Randomise selection. Pick units with a random number table or software, not by convenience. A biased sample makes every p-value meaningless.
  6. Keep observations independent. One measurement per unit. Repeated readings of the same unit must be averaged first.
  7. Use the same instrument and units as the source of σ. A different scale or method changes the spread.
  8. Record missing values as blanks, never as 0.
  9. For proportions, define success precisely and check that n·p0 and n(1 − p0) will both reach 10.
  10. Write the outlier rule in advance and keep every genuine value.
sample_idsitelength_mmsupports (0/1)
L001Plot 7521
L002Plot 7480
L003Plot 7551

Minimum sample: n ≥ 30 when the population shape is unknown; smaller n only when the population is known to be normal. For proportions, see Table 12.6. Pre-registration: record μ0, σ, the tail, α and n on OSF or in your protocol before data collection.

Common mistakes that make the data unusable: taking σ from the same sample, mixing two populations with different spreads, measuring the same unit twice, and choosing the tail after looking at the mean.

🎯 15. When to Use a One Sample Z Test

Use the one sample z test when:

  • ✓ You compare one sample mean with a fixed value and σ is known from outside the sample.
  • ✓ The data are roughly normal, or n is at least 30.
  • ✓ You test one proportion against p0 and n·p0 and n(1 − p0) are both 10 or more.
  • ✓ Observations are independent, one per unit.

Do not use it when:

  • ✗ σ is unknown and estimated from the sample: use the one-sample t test.
  • ✗ You compare two groups: use the two sample z test or an independent t test.
  • ✗ The data are small and skewed: use the sign test or Wilcoxon signed-rank test.
  • ✗ A rare proportion fails the n·p0 ≥ 10 rule: use the exact binomial test.
  • ✗ The same units are measured twice: use a paired t test.

Real-world examples:

  1. Manufacturing: is the mean fill weight on target, given the machine’s long-run σ?
  2. Psychology: do pupils on a programme score above the IQ norm of 100, with σ = 15?
  3. Polling: does support for a proposal differ from 50%?
  4. Ecology: is mean body mass in a population different from a regional reference with a well-documented spread?

One sample vs two sample z test: the one sample version compares one group with a fixed number; the two sample version compares two groups with each other. Decision tree: one group and a fixed value? Then is σ known? Yes, z test. No, t test. Data skewed and small? Sign or Wilcoxon test. Counting successes? Proportion z test, or exact binomial when n·p0 is below 10.

🔧 16. Troubleshooting and Common Errors

My z test and t test give different p-values

Cause: The t test uses the sample SD and a t distribution; the z test uses your known σ and the normal curve.

Fix: That is expected. Keep the z test only if σ really is known from outside the sample.

Excel Z.TEST gives half my p-value

Cause: Z.TEST returns the upper one-tailed p.

Fix: Use =2*MIN(Z.TEST(r,μ0,σ),1-Z.TEST(r,μ0,σ)) for two-tailed.

statsmodels ztest disagrees with this page

Cause: It replaces σ with the sample SD.

Fix: Compute z with the known σ as in Section 11.

R prop.test gives a different p for a proportion

Cause: Its continuity correction is on by default.

Fix: Add correct = FALSE, or switch the correction on here to match.

The assumption panel says s does not agree with σ

Cause: The spread in your sample is far from the σ you entered.

Fix: Check the source of σ. If it does not apply, use the t test.

p shows as < 0.0001

Cause: z is very large.

Fix: Report p < .001 in APA style; the exact value is in the Doc export.

Fewer values were read than I pasted

Cause: Text, units or stray symbols were ignored.

Fix: Read the "ignored" list under the box and clean those entries.

The proportion z test and exact test disagree

Cause: n·p0 or n(1 − p0) is small, so the normal approximation is poor.

Fix: Report the exact binomial p from the results table.

Results disappeared after I changed a setting

Cause: Any change clears results so you never read stale numbers.

Fix: Press Run again.

My uploaded column does not appear

Cause: Fewer than 80% of its cells are numeric.

Fix: Remove text notes from the column, or paste the values instead.

⚖ 17. Assumptions and Limitations

Assumptions

  1. σ is known. Check: name its source. If it fails: when the true spread is larger than σ, the SE is too small and p-values are too small, giving false positives; when it is smaller, the test is too conservative.
  2. Independence. Check: the design, one unit per value. If it fails: clustered data shrink the real information, so p-values are too small.
  3. Normal sampling distribution. Check: n ≥ 30, or the K² test and skewness in the panel. If it fails with small n: one tail is over-stated and the other under-stated, so one-tailed p-values are the most biased.
  4. Random sampling. Check: how units were chosen. If it fails: the estimate is biased in an unknown direction, and no p-value can correct it.
  5. For proportions, n·p0 ≥ 10 and n(1 − p0) ≥ 10. Check: the panel. If it fails: the z test is usually too liberal for rare outcomes, as in the defect-rate sample dataset in Section 2, where z gives p = 0.039 but the exact test gives 0.060.

Limitations

  1. Known σ is rare in real research. For most data the one-sample t test is the right tool.
  2. The test compares one group with one number. For two groups use the two sample z test or independent samples t test.
  3. It is sensitive to outliers because it uses the mean. For robust inference use the Wilcoxon signed-rank test or a bootstrap interval.
  4. A p-value is not the probability that H0 is true. For that question use a Bayesian test with a Bayes factor.
  5. The proportion z test is approximate. For small or extreme samples use the exact binomial test.

🏁 18. Conclusion

A one sample z test calculator answers one clear question: is the population mean, or proportion, equal to a stated value? It works by counting how many standard errors the sample estimate sits from the null value. When σ is genuinely known, the standard normal curve gives an exact p-value with fixed critical values of 1.960 and 1.645.

In the worked example, 16 leaves with a mean of 52.44 mm against a benchmark of 50 mm and σ = 4 gave z = 2.44 and p = 0.0148, with a 95% interval of 50.48 to 54.40 mm and a medium effect of d = 0.61. That is the complete story: the decision, the size and the uncertainty.

The biggest risk is not the arithmetic but the inputs. A σ borrowed from the sample, a tail chosen after looking, or a rare proportion with too few cases will each give a confident but wrong answer. The assumption panel exists to catch exactly these problems.

Run your own data above, read the assumption checks before the p-value, and copy one of the five reporting templates. Then come back to this one sample z test calculator whenever you need to test a mean with known σ or a single proportion. Run the analysis above to replace this summary with your own results. ___

❓ 19. Frequently Asked Questions

Q1. What is a one sample z test?

A one sample z test is a hypothesis test that checks whether a population mean equals a stated value μ0 when the population standard deviation σ is known. It turns the gap between the sample mean and μ0 into a z score, z = (x̄ − μ0) ÷ (σ ÷ √n), and compares it with the standard normal distribution.

Q2. What is the one sample z test formula?

For a mean, z = (x̄ − μ0) ÷ (σ ÷ √n). For a proportion, z = (p̂ − p0) ÷ √(p0(1 − p0) ÷ n). The two-tailed p-value is 2 × (1 − Φ(|z|)), where Φ is the standard normal cumulative distribution.

Q3. When do you use a one sample z test?

Use it when you compare one sample with a fixed value, the population standard deviation is known from outside the sample, and the data are normal or n is at least 30. Use the proportion version when testing one proportion with n·p0 and n(1 − p0) both at least 10.

Q4. What are the conditions for a one sample z test?

There are four: a random sample, independent observations, a known population σ, and a normal sampling distribution, which holds if the population is normal or n ≥ 30. For proportions the condition is n·p0 ≥ 10 and n(1 − p0) ≥ 10.

Q5. What is the difference between a one sample t test and a z test?

The z test uses a known population σ and the standard normal distribution. The t test estimates the spread with the sample SD and uses the t distribution with n − 1 degrees of freedom. When σ is unknown, which is most real data, the t test is correct.

Q6. What does calculating the one sample z test serve to give you?

It gives you a z score showing how many standard errors your sample mean lies from the hypothesised mean, and a p-value showing how surprising that distance would be if the null hypothesis were true. Together they decide whether to reject H0.

Q7. The one sample z test is used to compare the what?

The one sample z test is used to compare the mean of a single sample with a known or hypothesised population mean, when the population standard deviation is known. The proportion version compares a sample proportion with a hypothesised population proportion.

Q8. How do you do a one sample z test step by step?

State H0 and H1 and choose α. Compute the sample mean and the standard error σ ÷ √n. Calculate z = (x̄ − μ0) ÷ SE. Find the p-value from the normal curve. Reject H0 if p < α, then report z, p, the confidence interval and Cohen’s d.

Q9. What is a one sample z test for proportions?

It tests whether a population proportion equals p0 using z = (p̂ − p0) ÷ √(p0(1 − p0) ÷ n). For example, 280 supporters out of 500 gives p̂ = 0.56, z = 2.68 and p = 0.0073 against p0 = 0.5. Check that n·p0 and n(1 − p0) are at least 10.

Q10. What is an example of a one sample z test?

Sixteen leaves have a mean length of 52.44 mm. The regional mean is 50 mm with σ = 4 mm. The standard error is 4 ÷ √16 = 1, so z = 2.44 and the two-tailed p = 0.0148. The mean is significantly larger than 50 mm.

Q11. How do you do a one sample z test in Excel?

Compute the mean with AVERAGE, the standard error as σ/SQRT(COUNT(range)), z as (mean − μ0)/SE, and the two-tailed p with =2*(1-NORM.S.DIST(ABS(z),TRUE)). Excel’s Z.TEST returns only the upper one-tailed p, so double it carefully.

Q12. How do you run a one sample z test in R?

Base R has no z.test function. Compute z <- (mean(x) - mu0) / (sigma / sqrt(length(x))) and p <- 2 * pnorm(-abs(z)). The BSDA package offers z.test(x, mu = 50, sigma.x = 4) as a one-liner.

Q13. How do you run a one sample z test in Python?

Compute z = (x.mean() - mu0) / (sigma / np.sqrt(len(x))) and p = 2 * scipy.stats.norm.sf(abs(z)). Avoid statsmodels ztest for a known σ, because it estimates σ from the sample.

Q14. Consider a one sample two sided z test: when do you reject H0?

In a two-sided one sample z test you reject H0 when |z| is larger than the critical value: 1.645 at α = 0.10, 1.960 at α = 0.05 and 2.576 at α = 0.01. Equivalently, reject when the two-tailed p-value is below α.

Q15. What is the difference between a one sample and two sample z test?

A one sample z test compares one sample mean with a fixed value μ0. A two sample z test compares the means of two independent samples with each other, using both known standard deviations in the standard error.

Q16. What is the purpose of a one sample z test?

Its purpose is to decide whether a sample provides enough evidence that the population mean, or proportion, differs from a stated value such as a target, a standard or a historical benchmark.

Q17. Can I use a z test if n is less than 30?

Yes, if σ is known and the population itself is normal. With small n and skewed data the p-value becomes unreliable, so use the sign test or Wilcoxon signed-rank test, or the t test if σ is unknown.

Q18. What is the critical value for a one sample z test?

At α = 0.05 the critical value is ±1.960 for a two-tailed test and 1.645 for a one-tailed test. At α = 0.01 it is ±2.576 two-tailed and 2.326 one-tailed. These values do not depend on the sample size.

Q19. How do I report a one sample z test in APA format?

Give the mean, σ and n, then z to two decimals, the exact p, the effect size and the confidence interval, for example: M = 52.44, σ = 4, n = 16, z = 2.44, p = .015, d = 0.61, 95% CI [50.48, 54.40].

Q20. What effect size goes with a one sample z test?

Cohen’s d = (x̄ − μ0) ÷ σ for means and Cohen’s h = 2·asin√p̂ − 2·asin√p0 for proportions. Values of 0.2, 0.5 and 0.8 are small, medium and large.

📑 20. Cite This Tool

APA 7th edition
StatsUnlock. (2026). One sample z test calculator [Interactive statistical tool]. https://statsunlock.com/one-sample-z-test-calculator/
BibTeX
@misc{statsunlock_ztest_2026, title={One Sample Z Test Calculator}, author={{StatsUnlock}}, year={2026}, note={Interactive statistical tool}, url={https://statsunlock.com/one-sample-z-test-calculator/}}
Methods wording
A two-tailed one-sample z test was computed with the StatsUnlock One Sample Z Test Calculator (2026). The sample mean (n = 16) was compared with μ0 = 50 using a known population SD of σ = 4. Significance was set at α = 0.05, and the 95% confidence interval and Cohen’s d are reported.

🔗 21. Related Tools

📖 22. Glossary of Terms

Alpha (α)
The false-positive rate you accept, chosen before the test. Usually 0.05.
Alternative hypothesis (H1)
The claim that the population value differs from, or is above or below, the null value.
Central limit theorem
The rule that sample means are close to normally distributed for large n, whatever the population shape.
Cohen’s d
The difference between the sample mean and μ0 divided by σ. It measures size, not significance.
Cohen’s h
An effect size for proportions based on the arcsine of their square roots.
Confidence interval
A range of population values that are compatible with the data at a chosen level, such as 95%.
Continuity correction
A 0.5 adjustment that makes a normal approximation to counts slightly more conservative.
Critical value
The z beyond which H0 is rejected, such as 1.96 for a two-tailed test at α = 0.05.
Exact binomial test
A test for one proportion that uses the binomial distribution directly, with no normal approximation.
Holm correction
A step-down method that adjusts p-values when several groups are tested, controlling the chance of any false positive.
Known σ
A population standard deviation that comes from outside the sample, such as a standard or long-run record.
Null hypothesis (H0)
The claim that the population mean equals μ0, or the proportion equals p0.
One-tailed test
A test with all of α in one tail, used when only one direction matters.
p-value
The probability of a result at least as extreme as yours if H0 were true.
Population
The whole group you want to make a statement about.
Power
The chance that the test rejects H0 when a real effect of a given size exists.
Sample proportion (p̂)
The number of successes divided by the sample size.
Standard error
The standard deviation of the sample mean across repeated samples, σ ÷ √n.
Standard normal distribution
The bell curve with mean 0 and standard deviation 1 that z follows under H0.
Two-tailed test
A test that splits α between both tails, used when a difference in either direction matters.
Wilson interval
A confidence interval for a proportion that stays between 0 and 1 and covers well even for small samples.
z statistic
The number of standard errors between the sample estimate and the null value.

📚 23. References

These peer-reviewed references support the methods used in this one sample z test calculator: the normal test statistic and its quantiles, confidence intervals for proportions, effect sizes and power, and good practice in reporting p-values.

  1. Agresti, A., & Coull, B. A. (1998). Approximate is better than “exact” for interval estimation of binomial proportions. The American Statistician, 52(2), 119–126. https://doi.org/10.1080/00031305.1998.10480550
  2. Altman, D. G., & Bland, J. M. (1995). Absence of evidence is not evidence of absence. BMJ, 311(7003), 485. https://doi.org/10.1136/bmj.311.7003.485
  3. Amrhein, V., Greenland, S., & McShane, B. (2019). Scientists rise up against statistical significance. Nature, 567(7748), 305–307. https://doi.org/10.1038/d41586-019-00857-9
  4. Benjamin, D. J., Berger, J. O., Johannesson, M., et al. (2018). Redefine statistical significance. Nature Human Behaviour, 2(1), 6–10. https://doi.org/10.1038/s41562-017-0189-z
  5. Bland, J. M., & Altman, D. G. (1995). Multiple significance tests: The Bonferroni method. BMJ, 310(6973), 170. https://doi.org/10.1136/bmj.310.6973.170
  6. Brown, L. D., Cai, T. T., & DasGupta, A. (2001). Interval estimation for a binomial proportion. Statistical Science, 16(2), 101–133. https://doi.org/10.1214/ss/1009213286
  7. Cohen, J. (1992). A power primer. Psychological Bulletin, 112(1), 155–159. https://doi.org/10.1037/0033-2909.112.1.155
  8. Cumming, G., Fidler, F., & Vaux, D. L. (2007). Error bars in experimental biology. Journal of Cell Biology, 177(1), 7–11. https://doi.org/10.1083/jcb.200611141
  9. du Prel, J.-B., Hommel, G., Röhrig, B., & Blettner, M. (2009). Confidence interval or p-value? Part 4 of a series on evaluation of scientific publications. Deutsches Ärzteblatt International, 106(19), 335–339. https://doi.org/10.3238/arztebl.2009.0335
  10. Faul, F., Erdfelder, E., Lang, A.-G., & Buchner, A. (2007). G*Power 3: A flexible statistical power analysis program for the social, behavioral, and biomedical sciences. Behavior Research Methods, 39(2), 175–191. https://doi.org/10.3758/BF03193146
  11. Ghasemi, A., & Zahediasl, S. (2012). Normality tests for statistical analysis: A guide for non-statisticians. International Journal of Endocrinology and Metabolism, 10(2), 486–489. https://doi.org/10.5812/ijem.3505
  12. Greenland, S., Senn, S. J., Rothman, K. J., Carlin, J. B., Poole, C., Goodman, S. N., & Altman, D. G. (2016). Statistical tests, P values, confidence intervals, and power: A guide to misinterpretations. European Journal of Epidemiology, 31(4), 337–350. https://doi.org/10.1007/s10654-016-0149-3
  13. Kwak, S. G., & Kim, J. H. (2017). Central limit theorem: The cornerstone of modern statistics. Korean Journal of Anesthesiology, 70(2), 144–156. https://doi.org/10.4097/kjae.2017.70.2.144
  14. Lakens, D. (2013). Calculating and reporting effect sizes to facilitate cumulative science: A practical primer for t-tests and ANOVAs. Frontiers in Psychology, 4, 863. https://doi.org/10.3389/fpsyg.2013.00863
  15. Lumley, T., Diehr, P., Emerson, S., & Chen, L. (2002). The importance of the normality assumption in large public health data sets. Annual Review of Public Health, 23, 151–169. https://doi.org/10.1146/annurev.publhealth.23.100901.140546
  16. Newcombe, R. G. (1998). Two-sided confidence intervals for the single proportion: Comparison of seven methods. Statistics in Medicine, 17(8), 857–872. https://doi.org/10.1002/(SICI)1097-0258(19980430)17:8<857::AID-SIM777>3.0.CO;2-E
  17. Sullivan, G. M., & Feinn, R. (2012). Using effect size, or why the P value is not enough. Journal of Graduate Medical Education, 4(3), 279–282. https://doi.org/10.4300/JGME-D-12-00156.1
  18. Wasserstein, R. L., & Lazar, N. A. (2016). The ASA statement on p-values: Context, process, and purpose. The American Statistician, 70(2), 129–133. https://doi.org/10.1080/00031305.2016.1154108
  19. Wichura, M. J. (1988). Algorithm AS 241: The percentage points of the normal distribution. Journal of the Royal Statistical Society, Series C (Applied Statistics), 37(3), 477–484. https://doi.org/10.2307/2347330
  20. Wilson, E. B. (1927). Probable inference, the law of succession, and statistical inference. Journal of the American Statistical Association, 22(158), 209–212. https://doi.org/10.1080/01621459.1927.10502953
STATS UNLOCK · statsunlock.com · One Sample Z Test Calculator
RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Statistical Models

Important Plots & Charts

Calculators and Converters