Z Test
Z test is a statistical test that is conducted on data that approximately follows a normal distribution. The z test can be performed on one sample, two samples, or on proportions for hypothesis testing. It checks if the means of two large samples are different or not when the population variance is known.
A z test can further be classified into lefttailed, righttailed, and twotailed hypothesis tests depending upon the parameters of the data. In this article, we will learn more about the z test, its formula, the z test statistic, and how to perform the test for different types of data using examples.
1.  What is Z Test? 
2.  Z Test Formula 
3.  Z Test for Proportions 
4.  How to Calculate Z Test Statistic? 
5.  Z Test vs TTest 
6.  FAQs on Z Test 
What is Z Test?
A z test is a test that is used to check if the means of two populations are different or not provided the data follows a normal distribution. For this purpose, the null hypothesis and the alternative hypothesis must be set up and the value of the z test statistic must be calculated. The decision criterion is based on the z critical value.
Z Test Definition
A z test is conducted on a population that follows a normal distribution with independent data points and has a sample size that is greater than or equal to 30. It is used to check whether the means of two populations are equal to each other when the population variance is known. The null hypothesis of a z test can be rejected if the z test statistic is statistically significant when compared with the critical value.
Z Test Formula
The z test formula compares the z statistic with the z critical value to test whether there is a difference in the means of two populations. In hypothesis testing, the z critical value divides the distribution graph into the acceptance and the rejection regions. If the test statistic falls in the rejection region then the null hypothesis can be rejected otherwise it cannot be rejected. The z test formula to set up the required hypothesis tests for a one sample and a twosample z test are given below.
OneSample Z Test
A onesample z test is used to check if there is a difference between the sample mean and the population mean when the population standard deviation is known. The formula for the z test statistic is given as follows:
z = \(\frac{\overline{x}\mu}{\frac{\sigma}{\sqrt{n}}}\). \(\overline{x}\) is the sample mean, \(\mu\) is the population mean, \(\sigma\) is the population standard deviation and n is the sample size.
The algorithm to set a one sample z test based on the z test statistic is given as follows:
Left Tailed Test:
Null Hypothesis: \(H_{0}\) : \(\mu = \mu_{0}\)
Alternate Hypothesis: \(H_{1}\) : \(\mu < \mu_{0}\)
Decision Criteria: If the z statistic < z critical value then reject the null hypothesis.
Right Tailed Test:
Null Hypothesis: \(H_{0}\) : \(\mu = \mu_{0}\)
Alternate Hypothesis: \(H_{1}\) : \(\mu > \mu_{0}\)
Decision Criteria: If the z statistic > z critical value then reject the null hypothesis.
Two Tailed Test:
Null Hypothesis: \(H_{0}\) : \(\mu = \mu_{0}\)
Alternate Hypothesis: \(H_{1}\) : \(\mu \neq \mu_{0}\)
Decision Criteria: If the z statistic > z critical value then reject the null hypothesis.
Two Sample Z Test
A two sample z test is used to check if there is a difference between the means of two samples. The z test statistic formula is given as follows:
z = \(\frac{(\overline{x_{1}}\overline{x_{2}})(\mu_{1}\mu_{2})}{\sqrt{\frac{\sigma_{1}^{2}}{n_{1}}+\frac{\sigma_{2}^{2}}{n_{2}}}}\). \(\overline{x_{1}}\), \(\mu_{1}\), \(\sigma_{1}^{2}\) are the sample mean, population mean and population variance respectively for the first sample. \(\overline{x_{2}}\), \(\mu_{2}\), \(\sigma_{2}^{2}\) are the sample mean, population mean and population variance respectively for the second sample.
The twosample z test can be set up in the same way as the onesample test. However, this test will be used to compare the means of the two samples. For example, the null hypothesis is given as \(H_{0}\) : \(\mu_{1} = \mu_{2}\).
Z Test for Proportions
A z test for proportions is used to check the difference in proportions. A z test can either be used for one proportion or two proportions. The formulas are given as follows.
One Proportion Z Test
A one proportion z test is used when there are two groups and compares the value of an observed proportion to a theoretical one. The z test statistic for a one proportion z test is given as follows:
z = \(\frac{pp_{0}}{\sqrt{\frac{p_{0}(1p_{0})}{n}}}\). Here, p is the observed value of the proportion, \(p_{0}\) is the theoretical proportion value and n is the sample size.
The null hypothesis is that the two proportions are the same while the alternative hypothesis is that they are not the same.
Two Proportion Z Test
A two proportion z test is conducted on two proportions to check if they are the same or not. The test statistic formula is given as follows:
z =\(\frac{p_{1}p_{2}0}{\sqrt{p(1p)\left ( \frac{1}{n_{1}} +\frac{1}{n_{2}}\right )}}\)
where p = \(\frac{x_{1}+x_{2}}{n_{1}+n_{2}}\)
\(p_{1}\) is the proportion of sample 1 with sample size \(n_{1}\) and \(x_{1}\) number of trials.
\(p_{2}\) is the proportion of sample 2 with sample size \(n_{2}\) and \(x_{2}\) number of trials.
How to Calculate Z Test Statistic?
The most important step in calculating the z test statistic is to interpret the problem correctly. It is necessary to determine which tailed test needs to be conducted and what type of test does the z statistic belong to. Suppose a teacher claims that his section's students will score higher than his colleague's section. The mean score is 22.1 for 60 students belonging to his section with a standard deviation of 4.8. For his colleague's section, the mean score is 18.8 for 40 students and the standard deviation is 8.1. Test his claim at \(\alpha\) = 0.05. The steps to calculate the z test statistic are as follows:
 Identify the type of test. In this example, the means of two populations have to be compared in one direction thus, the test is a righttailed twosample z test.
 Set up the hypotheses. \(H_{0}\): \(\mu_{1} = \mu_{2}\), \(H_{1}\): \(\mu_{1} > \mu_{2}\).
 Find the critical value at the given alpha level using the z table. The critical value is 1.645.
 Determine the z test statistic using the appropriate formula. This is given by z = \(\frac{(\overline{x_{1}}\overline{x_{2}})(\mu_{1}\mu_{2})}{\sqrt{\frac{\sigma_{1}^{2}}{n_{1}}+\frac{\sigma_{2}^{2}}{n_{2}}}}\). Substitute values in this equation. \(\overline{x_{1}}\) = 22.1, \(\sigma_{1}\) = 4.8, \(n_{1}\) = 60, \(\overline{x_{2}}\) = 18.8, \(\sigma_{2}\) = 8.1, \(n_{2}\) = 40 and \(\mu_{1}  \mu_{2} = 0\). Thus, z = 2.32
 Compare the critical value and test statistic to arrive at a conclusion. As 2.32 > 1.645 thus, the null hypothesis can be rejected. It can be concluded that there is enough evidence to support the teacher's claim that the scores of students are better in his class.
Z Test vs TTest
Both z test and ttest are univariate tests used on the means of two datasets. The differences between both tests are outlined in the table given below:
Z Test  TTest 

A z test is a statistical test that is used to check if the means of two data sets are different when the population variance is known.  A ttest is used to check if the means of two data sets are different when the population variance is not known. 
The sample size is greater than or equal to 30.  The sample size is lesser than 30. 
The data follows a normal distribution.  The data follows a studentt distribution. 
The onesample z test statistic is given by \(\frac{\overline{x}\mu}{\frac{\sigma}{\sqrt{n}}}\)  The t test statistic is given as \(\frac{\overline{x}\mu}{\frac{s}{\sqrt{n}}}\) where s is the sample standard deviation 
Related Articles:
Important Notes on Z Test
 Z test is a statistical test that is conducted on normally distributed data to check if there is a difference in means of two data sets.
 The sample size should be greater than 30 and the population variance must be known to perform a z test.
 The onesample z test checks if there is a difference in the sample and population mean,
 The two sample z test checks if the means of two different groups are equal.
Examples on Z Test

Example 1: A teacher claims that the mean score of students in his class is greater than 82 with a standard deviation of 20. If a sample of 81 students was selected with a mean score of 90 then check if there is enough evidence to support this claim at a 0.05 significance level.
Solution: As the sample size is 81 and population standard deviation is known, this is an example of a righttailed onesample z test.
\(H_{0}\) : \(\mu = 82\)
\(H_{1}\) : \(\mu > 82\)
From the z table the critical value at \(\alpha\) = 1.645
z = \(\frac{\overline{x}\mu}{\frac{\sigma}{\sqrt{n}}}\)
\(\overline{x}\) = 90, \(\mu\) = 82, n = 81, \(\sigma\) = 20
z = 3.6
As 3.6 > 1.645 thus, the null hypothesis is rejected and it is concluded that there is enough evidence to support the teacher's claim.
Answer: Reject the null hypothesis

Example 2: An online medicine shop claims that the mean delivery time for medicines is less than 120 minutes with a standard deviation of 30 minutes. Is there enough evidence to support this claim at a 0.05 significance level if 49 orders were examined with a mean of 100 minutes?
Solution: As the sample size is 49 and population standard deviation is known, this is an example of a lefttailed onesample z test.
\(H_{0}\) : \(\mu = 120\)
\(H_{1}\) : \(\mu < 120\)
From the z table the critical value at \(\alpha\) = 1.645. A negative sign is used as this is a left tailed test.
z = \(\frac{\overline{x}\mu}{\frac{\sigma}{\sqrt{n}}}\)
\(\overline{x}\) = 100, \(\mu\) = 120, n = 49, \(\sigma\) = 30
z = 4.66
As 4.66 < 1.645 thus, the null hypothesis is rejected and it is concluded that there is enough evidence to support the medicine shop's claim.
Answer: Reject the null hypothesis

Example 3: A company wants to improve the quality of products by reducing defects and monitoring the efficiency of assembly lines. In assembly line A, there were 18 defects reported out of 200 samples while in line B, 25 defects out of 600 samples were noted. Is there a difference in the procedures at a 0.05 alpha level?
Solution: This is an example of a twotailed two proportion z test.
\(H_{0}\): The two proportions are the same.
\(H_{1}\): The two proportions are not the same.
As this is a twotailed test the alpha level needs to be divided by 2 to get 0.025.
Using this, the critical value from the z table is 1.96.
\(n_{1}\) = 200, \(n_{2}\) = 600
\(p_{1}\) = 18 / 200 = 0.09
\(p_{2}\) = 25 / 600 = 0.0416
p = (18 + 25) / (200 + 600) = 0.0537
z =\(\frac{p_{1}p_{2}0}{\sqrt{p(1p)\left ( \frac{1}{n_{1}} +\frac{1}{n_{2}}\right )}}\) = 2.62
As 2.62 > 1.96 thus, the null hypothesis is rejected and it is concluded that there is a significant difference between the two lines.
Answer: Reject the null hypothesis
FAQs on Z Test
What is a Z Test in Statistics?
A z test in statistics is conducted on data that is normally distributed to test if the means of two datasets are equal. It can be performed when the sample size is greater than 30 and the population variance is known.
What is a OneSample Z Test?
A onesample z test is used when the population standard deviation is known, to compare the sample mean and the population mean. The z test statistic is given by the formula \(\frac{\overline{x}\mu}{\frac{\sigma}{\sqrt{n}}}\).
What is the TwoSample Z Test Formula?
The two sample z test is used when the means of two populations have to be compared. The z test formula is given as \(\frac{(\overline{x_{1}}\overline{x_{2}})(\mu_{1}\mu_{2})}{\sqrt{\frac{\sigma_{1}^{2}}{n_{1}}+\frac{\sigma_{2}^{2}}{n_{2}}}}\).
What is a One Proportion Z test?
A one proportion z test is used to check if the value of the observed proportion is different from the value of the theoretical proportion. The z statistic is given by \(\frac{pp_{0}}{\sqrt{\frac{p_{0}(1p_{0})}{n}}}\).
What is a Two Proportion Z Test?
When the proportions of two samples have to be compared then the two proportion z test is used. The formula is given by \(\frac{p_{1}p_{2}0}{\sqrt{p(1p)\left ( \frac{1}{n_{1}} +\frac{1}{n_{2}}\right )}}\).
How Do You Find the Z Test?
The steps to perform the z test are as follows:
 Set up the null and alternative hypotheses.
 Find the critical value using the alpha level and z table.
 Calculate the z statistic.
 Compare the critical value and the test statistic to decide whether to reject or not to reject the null hypothesis.
What is the Difference Between the Z Test and the TTest?
A z test is used on large samples n ≥ 30 and normally distributed data while a ttest is used on small samples (n < 30) following a student t distribution. Both tests are used to check if the means of two datasets are the same.
visual curriculum