I was going through this article and, on this page, I encountered the definition of a random variable and a sample space. According to this page:

A random variable is a set of possible values from a random experiment.

It then takes the example of flipping a coin, defines $Heads=0$ and $Tails=1$, and says that $X = \{0, 1\}$ is a random variable.

Next, it defines sample space as

A random variable's set of values is the sample space.

It then takes the example of throwing a dice, and states that the sample space is $\{1, 2, 3, 4, 5, 6\}$.

So, both terms are defined to be a set of outcomes for an experiment and, as a result, I got confused and couldn't differentiate between them.

What is the difference between sample space and random variable?

I've consulted WIkipedia too and although I can understood the article on Sample Space but the article on Random Variable appears too technical and I couldn't comprehend it.

  • 1
    $\begingroup$ Intuitively ( you say you don't like technical papers) a random variable is more than just the outcomes, it is the outcomes and the probability of each outcome ( not fully correct because I would have to introduce events) $\endgroup$
    – user83346
    Commented Feb 27, 2017 at 8:58
  • $\begingroup$ @fcop from what I recall from high school, event is any element of the power set of the set of all the outcomes. $\endgroup$
    – ankit
    Commented Feb 27, 2017 at 14:18
  • $\begingroup$ In the language of my post at stats.stackexchange.com/a/54894/919, the sample space is a set of tickets in a box and a random variable is a consistent way of writing numbers on those tickets. (Math sites rarely make this distinction because to their writers the world is built of sets. In the real world, though, a "value from an ... experiment" is a rich, complicated thing: it could be a tissue sample, a photo of a star field, or a collection of handwritten answers on a survey. It often does not start out as a numerical object: the numbers have to be added by means of measurement.) $\endgroup$
    – whuber
    Commented Feb 27, 2017 at 14:22
  • $\begingroup$ Well it is not necessarily the power set of the sample space; it should be a sigma-algebra on the sample space. Each element of the sigma-algebra should be measurable. As @whuber says the random variable is then a map from this sigma-algebra (the tickets) in the real set (the consistent way of writing numbers on the tickets). Because the tickets are measurable, (some) subsets of the real set will also be. $\endgroup$
    – user83346
    Commented Feb 27, 2017 at 16:45

6 Answers 6


From statistical inference by Casella and Berger,

Definition 1.1.1 The set, $S$, of all possible outcomes of a particular experiment is called the sample space for the experiment.

So sample space can be thought of as all possible observations one could make from a particular experiment. A sample space for a coin toss is a set $\{H, T\}$; a sample space for rolling a six-sided die is a set $\{1, 2, 3, 4, 5, 6\}$.

Definition 1.4.1 A random variable is a function from a sample space $S$ into the real numbers

so random variable can be thought of as a function. The notation used for random variable is an uppercase letter. So if we have a random variable that maps sample space to real numbers, we have $$X: S \to \mathbb{R}$$

No one really expresses random variables this way; instead, it's often denoted as $X$.

If that random variable $X$ is a set of possible values from a random experiment, then $$X: S \to S$$ so random variable is an identity function.


A sample space is the SET of values a random variable can take.

You can think of random variable as an unopened box. This unopened box contains each member of the sample space with some probability.

In your example of a dice roll, the sample space is {1,2,3,4,5,6}. The random variable that represents a roll of the dice has a probability of 1/6 of taking on each of these 6 values.

  • $\begingroup$ You have the concept of sample space right I wouldn't characterize the random variable as an unopened box. It is the value of the side of the die that you roll and each of the possible values has a probability associated with it such that the sum of the probabilities for each side is 1. $\endgroup$ Commented Oct 22, 2017 at 5:02
  • $\begingroup$ This is similat to what I say in my comment supra $\endgroup$
    – user83346
    Commented Oct 22, 2017 at 7:45
  • $\begingroup$ Although often (especially in elementary texts) sample spaces are conflated with values of random variables, this doesn't generalize well. For more complicated situations it is essential to separate the concepts of "element of the sample space" and "possible value of a random variable." Please see my comment to the question. $\endgroup$
    – whuber
    Commented Oct 22, 2017 at 16:32
  • $\begingroup$ @whuber Could you explain in which situations it is essential to separate both concepts? why can't we just take the values of the random variable as the elements of a sample space and so avoid the extra layer of complexity in the model? Thanks. $\endgroup$
    – FCardelle
    Commented Aug 6, 2020 at 19:55
  • $\begingroup$ @FCardelle Dealing with sequences of variables and their possible interrelationships becomes trickier. So does analyzing (and even defining) stochastic processes. Separating the sample space from the random variables is not an additional layer of complexity: it's a huge conceptual and mathematical simplification. $\endgroup$
    – whuber
    Commented Aug 6, 2020 at 19:59

Amazonian's answer is wrong. The sample space IS NOT the set of values a random variable can take. The sample space is the domain upon which a random variable is defined. The example Amazonian gave is one example of a random variable whose values happen to be the elements in the sample space.

A random variable is a function that assigns a value to every element in the sample space. There is nothing stopping you from defining a random variable X on the sample space S = {1, 2, 3, 4, 5, 6} where X = 10 * s for s in S. Then the values that X can take are {10, 20, 30, 40, 50, 60}.

  • $\begingroup$ Although I am sympathetic with this point of view (see my other comments in this thread), the reason the situation is not so clear-cut is that one can always create a random variable with the given distribution by defining it as the identity function on its support and endowing the support with a suitable probability distribution. Thus, it's going a little too far to assert Amazonian is wrong. Your answer could be found misleading, too, in strongly suggesting the sample space cannot be the range of the random variable (although I realize it doesn't quite come out and say that). $\endgroup$
    – whuber
    Commented Oct 1, 2020 at 20:37
  • 1
    $\begingroup$ The sample space should not be defined as the set of values a random variable can take. This seems to be a misleading definition that’s all over the internet. The sample space is the set of all possible outcomes of a random experiment. $\endgroup$ Commented Oct 1, 2020 at 21:23
  • $\begingroup$ The reason I object to Amazonian's answer is because it attempts to define the sample space and does so both incorrectly and backwards. If we want to define what a dog is, we don’t do so by giving the definition “a dog is a dachshund”. Instead, we say “a dog is a member of the family Canidae”. Can a dog be a dachshund? Sure, but that's an irrelevant piece of information that shouldn't be in the definition. $\endgroup$ Commented Oct 1, 2020 at 21:26
  • $\begingroup$ The statement “a dog is a dachshund” is not claiming that “some dogs are dachshunds”. It is claiming “all dogs are dachshunds”, which is clearly wrong. It is also misleading because it goes backwards (the concept of ‘dog’ does not rely on the concept of ‘dachshund’). $\endgroup$ Commented Oct 1, 2020 at 21:30
  • $\begingroup$ I did also make it a point to explicitly say that the elements in the sample space and the values taken by the random variable CAN be the same, by pointing out Amazonian’s example. If Amazonian wasn't trying to give a definition of the sample space (which seems highly unlikely), it's true that the statement "if s is a sample space, then it is the set of values a random variable can take" is not a strictly false statement. But it is highly misleading and misses the point of the original question.That's why I called Amazonian's answer wrong. $\endgroup$ Commented Oct 1, 2020 at 21:36

When the sample space consists

  • exclusively of real numbers (as in your examples),

there is no difference between the sample space and the random variable.

The difference arises in other situations, because

           the sample space may be a set of arbitrary elements, e.g. $\{\color{red} {\text{red}}, \color{green} {\text{green}}, \color{blue} {\text{blue}}\}$.

With such freedom of possible outcomes it is difficult to work. So someone invented to work not with arbitrary elements, but only with real numbers.

To reach it, the first thing is to map such elements to real numbers, e.g.

\begin{aligned} \color{red} {\text{red }} &\mapsto 6.72\\ \color{green} {\text{green}} &\mapsto -2\\ \color{blue} {\text{blue}} &\mapsto 19.5 \end{aligned}

And that mapping is called a random variable.

So now there is a difference, because

  • the sample space is $\{\color{red} {\text{red}}, \color{green} {\text{green}}, \color{blue} {\text{blue}}\}$, whereas
  • the random variable is that mapping, often freely interpreted as the set $\{\color{red} {6.72}, \color{green} {-2}, \color{blue} {19.5}\}$.


Why is that mapping so important?

Because we got rid of problems how to operate with arbitrary things — after choosing such a mapping we may perform calculation with numbers.


I believe the confusion comes from the choice of examples used. For sake of clarity lets use instead the example of the throw of 2 dices. Then, in that case the sample space would be: {(1,1),(1,2),(2,1),(1,3),(3,1),...,(5,6),(6,5),(6,6)}. A random variable is just a function having this set as domain and the Reals as codomain (in more advanced statistics one could use other more abstract codomains). So, for example, one could define a random variable as being the sum of the results of the dice. So the different result one could obtain are: {2,3,4,5,6,7,8,9,10,11,12}, and the probability of each one occurring is derived directly from the sample space and the probability associated with each element of the set (in this particular case each element has the same probability, but in general it could not be).

From a formal perspective a sample space is "more fundamental" than a random variable. There can be no random variable without the specification of the elements and its correspondent probabilities of the sample space of its domain.

From a practical perspective, a random variables give you 2 advantages over simple sample spaces: (i) they are numerical. That means that one can represent, for example, a coin toss {H,T} into the numerical values {1,0}, and then apply all sort of numerical tools that cannot be applied over qualitative elements. (ii) it makes easier to deal with elements with different probabilities. In the example given we easily created a distribution with different probabilities based on a simple calculation over a sample space with elements of equal probability. Trying to create the given result artificially could be confusing and laborious.

It is common to just use a random variable without the explicit specification of its sample space.


For flipping a coin:

  • The sample space is {head, tail},
  • the random variable is {0, 1}.

For rolling a die:

  • The sample space is {1, 2, 3, 4, 5, 6},
  • the random variable is {1, 2, 3, 4, 5, 6}, too,
    because the sample space already is the set of numbers only.

In other words, the sample space is the set of arbitrary elements, while the random variable is the set of numbers.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.