When it comes to statistical tests, **z-test** and **t-test** are two of the most commonly used. But what is the **difference **between **z-test** and **t-test**? And when should you use **Z-test vs T-test**? In this blog post, we will answer all these questions and more! We will start by explaining the difference between z-test and t-test in terms of their formulas. Then we will go over some examples so that you can see how each test is used in practice. As data scientists, it is important to understand the difference between z-test and t-test so that you can choose the right test for your data. Let’s get started!

Table of Contents

## Difference between Z-test and T-test

**Z-test is a statistical ****hypothesis testing technique** which is used to test the null hypothesis in relation to the following given that the * population’s standard deviation is known* and the data belongs to normal distribution:

- There is no difference between the sample and the population. Or, the difference between the sample and the population mean is not statistically significant. This hypothesis can be tested using one-sample Z-test for means. In other words, one-sample Z-test for means can be used to test the hypothesis that the sample belongs to the population. In this test, the mean of the sample is compared against the population mean in the sampling distribution. The standard error in the formula given below is the standard deviation of sample mean in the sampling distribution. The formula for Z-statistics for one-sample Z-test for means is the following. Read greater details in this blog, one-sample Z-test for means.

** Z = (X̄ – µ)/SE**

** = ****(X̄ – µ)/σ/√n, , **where **SE** is the standard error, **X̄ **is the sample mean, **µ **is the population mean, **σ **is the population standard deviation and the **n **is the sample size

- There is no difference between the two populations. Or, the difference between the two population means is not statistically significant. This hypothesis can be tested using two-sample Z-test for means. The formula for Z-statistics is the following. Read further details in this blog, Two-sample Z-test for means.
- There is no difference between the hypothesized proportion and the theoretical population proportion. This hypothesis can be tested using one-sample Z-test for proportion. Greater details can be read in this blog, one-sample Z-test for proportion.
- There is no difference between the proportions belonging to two different populations. This hypothesis can be tested using two-sample Z-test for proportions. Greater details can be read in this blog, two-sample Z-test for proportions.

**T-test is a**** statistical hypothesis technique** which is used to test the null hypothesis in relation to the following given the * population standard deviation is unknown*, data belongs to normal distribution, and the

*(size less than 30)*

__sample size is small__- There is no difference between the sample and the population given the population standard deviation is known and the sample size is small. This is very much similar to one-sample Z-test for means. Greater details can be read in this blog, one-sample t-test for means. The formula for t-statistics look like the following. Note that the sample mean is compared with the population mean as like in one sample Z-test. However, the
**difference**lies in how the standard error is calculated as the ratio of standard deviation of the sample and the square root of the sample size.

** T = (X̄ – μ) / SE**

** = (X̄ – μ) / S/√n, **where **SE** is the standard error, **X̄ **is the sample mean, **µ **is the population mean, **S **is the sample standard deviation and the **n **is the sample size. Note the difference between the Z-statistics and T-statistics in one-sample Z-test and one-sample T-test in relation to usage of population standard deviation **σ **in case of Z-test while sample standard deviation, **S** in case of T-test.

- There is no difference between the two populations given the population standard deviation is known and the sample size is small. This hypothesis can be tested using two-samples t-test for independent samples. In case of two-samples t-test for independent samples, different formula exists in case the variance of the two populations are equal or otherwise. In case the population variances are unequal, the
**pooled variance**is used to calculate the T-statistics. Read further details about two-sample t-test for independent samples in this blog, two-samples t-test for independent samples: formula and examples. Note the difference between the formula for two-samples Z-test for means and the two-samples t-test for means in the respective blogs. The formula for two-samples t-test for independent samples given population variances are equal is the following:

**Other differences between the Z-test and T-test** are the following:

- While Z-test makes use of
**Z-distribution**or standard normal distribution, T-test makes use of**T-distribution**. - While T-test makes use of
**degree of freedoms**for calculation of T-statistics, Z-test don’t need the determination of degrees of freedom. - For independent samples with equal variance, use t-statistics instead of z-tests as z-test only applies when populations don’t differ too much in their respective standard deviations.

## When to use Z-test vs T-test?

The following is a simplistic diagram which specifies when to use Z-test vs T-test:

Note some of the following in the above diagram:

- If the population standard deviation is known and the sample size is greater than 30, Z-test is recommended to be used.
- If the population standard deviation is known, and the size of the sample is less than or equal to 30, T-test is recommended
- If the population standard deviation is unknown, T-test is recommended.

## Summary

The z-test and t-test are different statistical hypothesis tests that help determine whether there is a difference between two population means or proportions. The z-statistic is used to test for the null hypothesis in relation to whether there is a difference between the populations means or proportions given the population standard deviation is known, data belongs to normal distribution, and sample size is larger enough (greater than 30). T-tests are used when the population standard deviation is unknown, the data belongs to normal distribution and the sample size is small (lesser than 30).

- Pandas: How to Create a Dataframe – Examples - September 29, 2022
- Central Limit Theorem: Concepts & Examples - September 25, 2022
- Probability concepts, formulas & real-world examples - September 25, 2022

Hello M. Ajitesh Kumar,

In this blog, below the diagram there is an error in the explanation,

Please see this sentence: If the population standard deviation is unknown, Z-test is recommended to be used.

Thank you for pointing that out. Corrected.

Great job!