The binomial distribution is a discrete probability distribution. It describes the outcome of n independent trials in an experiment. Each trial is assumed to have only two outcomes, either success or failure. If the probability of a successful trial is p, then the probability of having x successful outcomes in an experiment of n independent trials is as follows.
f(x) = _{n}C_{ x} * p^{x}(1p)^{nx } where x is 0,1,2….,n
A sample plot showing binomial distribution
A binomial experiment is an experiment which satisfies these four conditions.
 A fixed number of trials.
 Each trial is independent of others.
 There are only two outcomes.
 The probability of each outcome remains constant from trial to trial.
These can be summarized as: An experiment with a fixed number of independent trials, each of which can only have two possible outcomes.The fact that each trial is independent actually means that the probabilities remain constant.
Examples of binomial experiments.
 Tossing a coin 20 times to see how many tails occur.
 Asking 100 people if they watch BBC news.
 Rolling a die to see if a 2 appears.
Examples which are not binomial experiments.
 Rolling a die until a 6 appears. (Not a fixed number of trials)
 Asking 20 people how old they are? (Not two outcomes)
The most common form of binomial distribution is simply the Bernoulli distribution to model a response that has only two outcomes. Heads or tails. Yes or No. Male or female. Disease or control.
Binomial probability functions in R
Function  purpose  syntax  usage 
dbinom  Distribution function or density  dbinom(x,size,prob)
where x is vector of quantiles 
dbinom(4,size=12,prob=0.2)
[1] 0.1328756 Distribution function of an experiment with 4 success out of 12 trials, having 0.2 probability.

pbinom  Cumulative probability distribution function  pbinom(q, size, prob)where q is vector of quantiles  pbinom(24,size=50,prob=0.5)
[1] 0.4438624CDF of the above experiment is 0.4438 
qbinom  Quantile function  qbinom(p,size,prob)
Where p is vector of probabilities. 
qbinom(0.5,size=51,prob=0.5)
[1] 25 For 0.5 CDF we can observe 25 success. 
rbinom  To generate random numbers obeying binomial distribution  rbinom(n,size,prob)
Where n is number of observations. 
rbinom(5,size=100,prob=0.2)
[1] 13 16 24 18 25
Above random number gives binomial distribution.

Application of functions in solving problems.
Example 1: What is the probability of rolling exactly two 5’s in 6 rolls of a die?
solution:
There are 5 things we need to consider here.
 Define the Success first. Success must be for a single trial. Success= Rolling a 5 on a single die.
 Define the probability of success (p): p=1/6
 Find the probability of failure: q=5/6
 Define the number of trials=6
 Define the number of successes out of those trials: x=2
Rcode:
 dbinom(2,size=6,prob=1/6)
[1] 0.2009388
Therefore, The probability density function for having two 5’s in our 6 rolls of trial is 21%
 pbinom(3,size=6,prob=1/6)
[1] 0.991298
So, the probability of having 3 or less 5’s in our 6 rolls of trial is 99.12%
 qbinom(0.4,size=6,prob=1/6)
[1] 1
For CDF of 0.4 we can get 1 success.
Example 2: Suppose there are twenty multiple choice questions in a mathematics class quiz. Each question has five possible answers, and only one of them is correct. Find the probability of having six or less correct answers if a student attempts to answer every question at random.
Solution:
Since only one out of five possible answers is correct, the probability of answering a question correctly by random is 1/5=0.2.
 We can find the probability of having exactly 6 correct answers by random attempts as follows.
R code: dbinom(6, size=20, prob=0.2)
[1] 0.1090997
We can conclude that the probability density function for having 6 questions answered correctly by random attempt is 10.90% ·
 We can find the probability of having 6 or less questions answered correctly by random attempt.
R code: pbinom(6,size=20,prob=0.2)
[1] 0.9133075
From this, we can say that the probability of answering six or less questions correctly by a random attempt is 91.33%
 We can also find out the number of success for some particular CDF or probability distribution function value.
R code: qbinom(0.5,size=20,prob=0.2)
[1] For 0.5 CDF we can witness 4 successes.
References: