Does Cyber Security Involve Math?—Yes, and It’s Not Scary
Explore where arithmetic and statistics appear in defensive cybersecurity work.
Quick Answer
Cybersecurity uses different kinds of mathematics for different tasks. Probability and statistics help analysts interpret alerts, while discrete mathematics and modular arithmetic explain ideas used in cryptography. The depth needed depends on the role.
Advertisement
Wait, Do Hackers Really Crunch Numbers All Day?
Picture this: I’m on a red-team engagement at a fintech startup. Their CTO brags about “bullet-proof” password storage. One rainbow-table attack later, our report shows 71 % of hashes cracked in under ten minutes—because they skipped the salt. That messy victory? 100 % powered by math.
Rapid-Fire FAQ (Read This Before You Flee to Marketing)
Question
Honest Answer
Is math used daily in cyber security?
Yup—especially modular arithmetic, probability, and basic statistics.
Hardest equation I’ll see?
RSA key-gen: n = p × q and φ(n) = (p – 1)(q – 1). But tools do the heavy lifting.
Can I succeed with a calculator & Python?
Absolutely. The pros script computations instead of hand-cranking them.
Where Math Sneaks Into Your Blue-Team Life
Encryption & Decryption
Prime Factorization underpins RSA.
Elliptic-Curve Point Addition feels like alien algebra but delivers shorter keys with stronger punch.
Pro Tip: I store a cheat-sheet card in my hoodie pocket with mod-arithmetic rules and common key sizes. Low-tech still rules during on-site audits.
Math Skill Levels by Cyber Role
Role
Math You’ll Use
My Survive-&-Thrive Tip
SOC Analyst
Log-rate averages, Z-scores
Let Splunk compute, but know why alerts spike.
Malware Reverse Engineer
Bit-shifts, XOR, finite fields
Practice CTF crackmes with a hex editor.
Cryptographer
Number theory, group theory
Coffee + “Handbook of Applied Crypto” = weekend sorted.
“I’m Math-Phobic”—3 Hacks That Saved My Sanity
Visualize It – Draw lattice diagrams for AES rounds; cartoons beat equations.
Code It Twice – First in Python, then in Bash one-liners. Repetition cements concepts.
Teach a Junior – Explaining mod 97 checksums out loud exposes every fuzzy gap.
Mini Case Story: When Probability Foiled a Phish
A bank’s spam filter let 0.4 % of emails through. Stats showed a p-value < 0.05 linking failures to a single sender domain. We tuned Bayesian weights, false positives dropped 73 %. Math paid for itself before lunch.
Do You Need Calculus?
Not really. Focus on:
Algebraic manipulation
Modular arithmetic (for keys)
Basic probability & stats (for detection)
If you can multiply large integers and read a normal distribution chart, you’re 90 % there.
Final Thought
Math in cyber security isn’t black-board torture; it’s the cheat code that turns “script kiddies” into respected engineers. Once you grasp the numbers, you’ll crack hashes faster, write tighter detections, and—yes—brag at conferences.
Advertisement
Read a false-alarm rate using actual counts
Imagine 1,000 routine classroom log entries. Ten record a known fault. A monitoring rule flags eight of those ten plus eighteen normal entries. Of the 26 flags, eight correspond to a known fault. The share is about 31 percent. The rule finds eight out of ten faults, or 80 percent. Those percentages answer different questions because the denominators differ.
Sampling and Gathering Data
The Digest's failure highlights the need for what is now considered the most important criterion for sampling: randomness. This randomness can be achieved in several ways. Here we cover some of the most common.
A simple random sample is chosen in a way that every unit in the population has an equal chance of being selected, and the chances of a unit being selected do not depend on the units already chosen. An example of this is choosing a group of people by drawing names out of a hat (assuming the names are well-mixed in the hat).
A systematic random sample is selected from an ordered list of the population (for example, names sorted alphabetically or students listed by student ID). First, we decide what proportion of the population will be in our sample. We want to express that proportion as a fraction with 1 in the numerator. Let’s call that number D. Next, we’ll choose a random number between one and D. The unit at that position will go into our sample. We’ll find the rest of our sample by choosing every Dth unit in the list, starting with our random number.
To walk through an example, let’s say we want to sample 2% of the population: . (Note: If the number in the denominator isn’t a whole number, we can just round it off. This part of the process doesn’t have to be precise.) We can then use a random number generator to find a random number between 1 and 50; let's use 31. In our example, our sample would then be the units in the list at positions 31, 81 (31 + 50), 131 (81 + 50), and so forth.
A stratified sample is one chosen so that particular groups in the population are certain to be represented. Let’s say you are studying the population of students in a large high school (where the grades run from 9th to 12th), and you want to choose a sample of 12 students. If you use a simple or systematic random sample, there’s a pretty good chance that you’ll miss one grade completely. In a stratified sample, you would first divide the population into groups (the strata), then take a random sample within each stratum (that’s the singular form of “strata”). In the high school example, we could divide the population into grades, then take a random sample of three students within each grade. That would get us to the 12 students we need while ensuring coverage of each grade.
A cluster sample is a sample where clusters of units are chosen at random, instead of choosing individual units. For example, if we need a sample of college students, we may take a list of all the course sections being offered at the college, choose three of them at random (the sections are the clusters), and then survey all the students in those sections. A sample like this one has the advantage of convenience: If the survey needs to be administered in person, many of your sample units will be located in one place at the same time.
Random Sampling
For each of the following situations, identify whether the sample is a simple random sample, a systematic random sample, a stratified random sample, a cluster random sample, or none of these.
A postal inspector wants to check on the performance of a new mail carrier, so she chooses four streets at random among those that the carrier serves. Each household on the selected streets receives a survey.
A hospital wants to survey past patients to see if they were satisfied with the care they received. The administrator sorts the patients into groups based on the department of the hospital where they were treated (ICU, pediatrics, or general), and selects patients at random from each of those groups.
A quality control engineer at a factory that makes smartphones wants to figure out the proportion of devices that are faulty before they are shipped out. The phones are currently packed in boxes for shipping, each of which holds 20 devices. The engineer wants to sample 100 phones, so he selects five crates at random and tests every phone in those five crates.
A newspaper reporter wants to write a story on public perceptions on a project that will widen a congested street. She stands on the side of the street in question and interviews the first five people she sees there.
An executive at a streaming video service wants to know if her subscribers would support a second season of a new show. She gets a list of all the subscribers who have watched at least one episode of the show, and uses a random number generator to select a sample of 50 people from the list.
An agent for a state’s Department of Revenue is in charge of selecting 100 tax returns for audit. He has a list of all of the returns eligible for audit (about 12,000 in all), sorted by the taxpayer’s ID number. He asks a computer to give him a random number between 1 and 120; it gives him 15. The agent chooses the 15th, 135th, 255th, 375th, and every 120th return after that to be audited.
Solution
To decide which type of random sample is being used in each of these, we need to focus on how the randomization is being incorporated.
The surveys are being given to households, so households are the units in this case. But households aren’t being chosen randomly; instead, streets are being chosen at random. These form clusters of units, so this is a cluster random sample.
In this case, the administrator isn’t selecting patients at random from the entire list of patients. Instead, she is choosing at random from the patients who were in each of the departments (ICU, pediatrics, general) separately. The departments form strata, so this is a stratified random sample.
The engineer is testing whether the phones are faulty, so those are the units. But the random process is being used to select the crates of phones. Those crates form clusters, so this is a cluster random sample.
The reporter isn’t using a random process at all, so this sample doesn’t belong to any of the types we have been talking about. A sample like this one is sometimes described as a convenience sample, and shouldn’t be used in a statistical setting.
The executive is choosing her sample completely at random from the full population, so this is a simple random sample.
The agent is choosing from the full population, but is only choosing the first unit for the sample at random; the rest are chosen by skipping down the list systematically. Thus, this is a systematic random sample.
Organizing Data
Once data have been collected, we turn our attention to analysis. Before we analyze, though, it’s useful to reorganize the data into a format that makes the analysis easier. For example, if our data were collected using a paper survey, our raw data are all broken down by respondent (represented by an individual response sheet). To perform an analysis on all the responses to an individual question, we need to first group all the responses to each question together. The way we organize the data depends on the type of data we’ve collected.
There are two broad types of data: categorical and quantitative. Categorical data classifies the unit into a group (or category). Examples of categorical data include a response to a yes-or-no question, or the color of a person’s eyes. Quantitative data is a numerical measure of a property of a unit. Examples of quantitative data include the time it takes for a rat to run through a maze or a person’s daily calorie intake. We’ll look at each type of data in turn when considering how best to organize.
Categorical Data Organization
The best way to organize categorical data is using a categorical frequency distribution. A categorical frequency distribution is a table with two columns. The first contains all the categories present in the data, each listed once. The second contains the frequencies of each category, which are just a count of how often each category appears in the data.
Creating a Categorical Frequency Distribution
A teacher records the responses of the class (28 students) on the first question of a multiple choice quiz, with five possible responses (A, B, C, D, and E):
A
A
C
A
B
B
A
E
A
C
A
A
A
C
E
A
B
A
A
C
A
B
E
E
A
A
C
C
Create a categorical frequency distribution that organizes the responses.
Solution
Step 1: For each possible response, count the number of times that response appears in the data. In the responses for this class, “A” appears 14 times, “B” 4 times, “C” 6 times, “D” 0 times, and “E” 4 times.
Step 2: Make a table with two columns. The first column should be labeled so that the reader knows what the responses mean, and the second should be labeled “Frequency.”
Response to First Question
Frequency
A
14
B
4
C
6
D
0
E
4
Step 3: Check your work. If you add up your frequencies, you should get the same number as the total number of responses. Twenty-eight students answered that first question, and .
Quantitative Data
We have a couple of options available for organizing quantitative data. If there are just a few possible responses, we can create a frequency distribution just like the ones we made for categorical data above. For example, if we’re surveying a group of high school students and we ask for each student’s age, we’ll likely only get whole-number responses between 13 and 19. Since there are only around seven (and likely fewer) possible responses, we can treat the data as if they’re categorical and create a frequency distribution as before.
Creating a Quantitative Frequency Distribution
Attendees of a conflict resolution workshop are asked how many siblings they have. The responses are as follows:
1
0
1
1
2
0
3
1
1
4
1
2
0
1
3
1
2
1
2
4
1
0
1
3
0
1
2
2
1
5
Create a frequency distribution to organize the responses.
Solution
Step 1: Count the number of times you see each unique response: “0” appears 5 times, “1” appears 13 times, “2” appears 6 times, “3” appears 3 times, “4” appears twice, and “5” appears once.
Step 2: Make a table with two columns. The first column should be labeled so that the reader knows what the responses mean, and the second should be labeled “Frequency.” Then fill in the results of our count.
Number of Siblings
Frequency
Number of Siblings
Frequency
0
5
3
3
1
13
4
2
2
6
5
1
Step 3: Check your work. If you add up your counts, you should get the same number as the total number of responses. Looking back at the raw data, there were 30 responses, and .
If there are many possible responses, a frequency distribution table like the ones we’ve seen so far isn’t really useful; there will likely be many responses with a frequency of one, which means the table will be no better than looking at the raw data. In these cases, we can create a binned frequency distribution. A binned frequency distribution groups the data into ranges of values called bins, then records the number of responses in each bin.
For example, if we have height data for individuals measured in centimeters, we might create bins like 150–155 cm, 155–160 cm, and so forth (making sure that every data value falls into a bin). We must be careful, though; in this scenario, it’s not clear which bin would contain a response of 155 cm. Usually, responses on the edge of a bin are placed in the higher bin, but it’s good practice to make that clear. In cases where responses are rounded off, you can avoid this issue by leaving a gap between the bins that couldn’t contain any responses. In our example, if the measurements were all rounded off to the nearest centimeter, we could make bins like 150–154 cm, 155–159 cm, etc. (since a response like 154.2 isn’t possible). We’ll use this method going forward. How do we decide what the boundaries of our bins should be? There’s no one right way to do that, but there are some guidelines that can be helpful.
Every data value should fall into exactly one bin. For example, if the lowest value in our data is 42, the lowest bin should not be 45–49.
Every bin should have the same width. Note that if we shift the upper limits of our bins down a bit to avoid ambiguity (like described above), we can’t simply subtract the lower limit from the upper limit to get the bin width; instead, we subtract the lower limit of the bin from the lower limit of the next bin. For example, if we’re looking at GPAs rounded to the nearest hundredth, we might choose bins like 2.00–2.24, 2.25–2.49, 2.50–2.74, etc. These bins all have a width of 0.25.
If the minimum or maximum value of the data falls right on the boundary between two bins, then it’s OK to bend the rule just a little in order to avoid having an additional bin containing just that one value. We’ll see an example of this in just a moment.
If we have too many or too few bins, it can be difficult to get a good sense of the distribution. Seven or eight bins is ideal, but that’s not a firm rule; anything between five and twelve is fine. We often choose the number of bins so that the widths are round numbers.
Creating a Binned Frequency Distribution
The GPAs of students enrolled in an advanced sociology class are listed in the following table. At this institution, 4.00 is the maximum possible GPA.
3.93
3.43
2.87
2.51
2.70
1.91
2.32
2.85
3.06
3.03
3.49
1.84
3.72
2.56
1.99
3.40
3.74
3.23
1.98
3.05
1.43
2.90
1.20
3.72
3.56
3.07
2.58
4.00
2.79
3.81
2.60
3.69
2.88
3.34
1.51
3.63
3.45
1.89
2.30
2.98
3.04
2.70
Create a binned frequency distribution for the data.
Solution
Step 1: Identify the max and min values in your bins. Looking at the dataset, you can see that the lowest value is 1.20, and the highest is 4.00.
Step 2: Get a rough idea of bin widths. Aim for seven or eight bins, give or take a couple. For eight bins, the minimum width can be found by taking the difference between the largest and smallest data values and dividing by the number of bins:
If we use 0.35 for our widths, starting at our minimum value of 1.20, we’ll get bins with these boundaries: 1.20, 1.55, 1.90, 2.25, 2.60, 2.95, 3.30, 3.65, 4.00.
Step 3: Consider the context of the values.
Because these are GPAs, there are natural breaks at 2.00 and 3.00 that are important. (People like whole numbers!) Since 0.35 is very close to , let’s use that for our bin width instead, and make sure that whole numbers fall on the boundaries. That means our first bin needs to start at 1.00 and go up to 1.33 to make sure our minimum value is included. The next bin will run from 1.34 to 1.66, and so forth.
Step 4: Create the distribution table. We
start our distribution table by filling in the bins:
GPA Range
Frequency
GPA Range
Frequency
GPA Range
Frequency
1.00–1.33
2.00–2.33
3.00–3.33
1.34–1.66
2.34–2.66
3.34–3.66
1.67–1.99
2.67–2.99
3.67–4.00
Notice that the last bin doesn’t follow the pattern; since our maximum data value is right on the upper boundary of that last bin, this is a case where we can bend that rule just a little to avoid creating a bin for 4.00–4.33 (which wouldn’t really make sense in the context of these GPAs anyway, since 4.00 is the maximum possible GPA).
Step 5: Complete the table with the frequencies. Finish the table by counting the number of data values that fall in each bin, and recording them in the frequency column:
GPA Range
Frequency
GPA Range
Frequency
GPA Range
Frequency
1.00–1.33
1
2.00–2.33
2
3.00–3.33
6
1.34–1.66
2
2.34–2.66
4
3.34–3.66
7
1.67–1.99
5
2.67–2.99
8
3.67–4.00
7
Step 6: Check your work. Add up the frequencies to make sure all the data values are included. We started with forty-two data values, and .
Visualizing Categorical Data
If the data we’re visualizing is categorical, then we want a quick way to represent graphically the relative numbers of units that fall in each category. When we created the frequency distributions in the last section, all we did was count the number of units in each category and record that number (this was the frequency of that category). Frequencies are nice when we’re organizing and summarizing data; they’re easy to compute, and they’re always whole numbers. But they can be difficult to understand for an outsider who’s being introduced to your data.
Let’s consider a quick example. Suppose you surveyed some people and asked for their favorite color. You communicated your results using a frequency distribution. Jerry is interested in data on favorite colors, so he reads your frequency distribution. The first row shows that twelve people indicated green was their favorite color. However, Jerry has no way of knowing if that’s a lot of people without knowing how many people total took your survey. Twelve is a pretty significant number if only twenty-five people took the survey, but it’s next to nothing if you recorded a thousand responses. For that reason, we will often summarize categorical data not with frequencies, but with proportions. The proportion of data that fall into a particular category is computed by dividing the frequency for that category by the total number of units in the data.
Proportions can be expressed as fractions, decimals, or percentages.
Finding Proportions
Recall worked example, in which a teacher recorded the responses on the first question of a multiple choice quiz, with five possible responses (A, B, C, D, and E). The raw data was as follows:
A
A
C
A
B
B
A
E
A
C
A
A
A
C
E
A
B
A
A
C
A
B
E
E
A
A
C
C
We computed a frequency distribution that looked like this:
Response to First Question
Frequency
A
14
B
4
C
6
D
0
E
4
Now, let's compute the proportions for each category.
Solution
Step 1: In order to compute a proportion, we need the frequency (which we have in the table above) and the total number of units that are represented in our data. We can find that by adding up the frequencies from all the categories: .
Step 2: To find the proportions, we divide the frequency by the total. For the first category (“A”), the proportion is We can compute the other proportions similarly, filling in the rest of the table:
Response to First Question
Frequency
Proportion
A
14
B
4
C
6
D
0
E
4
Step 3: Check your work: If you add up your proportions, you should get 1 (if you’re using fractions or decimals) or 100% (if you’re using percentages). In this case,
Now that we can compute proportions, let’s turn to visualizations. There are two primary visualizations that we’ll use for categorical data: bar charts and pie charts. Both of these data representations work on the same principle: If proportions are represented as areas, then it’s easy to compare two proportions by assessing the corresponding areas. Let’s look at bar charts first.
Bar Charts
A bar chart is a visualization of categorical data that consists of a series of rectangles arranged side-by-side (but not touching). Each rectangle corresponds to one of the categories. All of the rectangles have the same width. The height of each rectangle corresponds to either the number of units in the corresponding category or the proportion of the total units that fall into the category.
Building a Bar Chart
In worked example, we computed the following proportions:
Response to First Question
Frequency
Proportion
A
14
50%
B
4
14.3%
C
6
21.4%
D
0
0%
E
4
14.3%
Draw a bar chart to visualize this frequency distribution.
Solution
Step 1: To start, we’ll draw axes with the origin (the point where the axes meet) at the bottom left:
Step 2: Next, we’ll place our categories evenly spaced along the bottom of the horizontal axis. The order doesn’t really matter, but if the categories have some sort of natural order (like in this case, where the responses are labeled A to E), it’s best to maintain that order. We'll also label the horizontal axis:
Step 3: Now, we have a decision to make: Will we use frequencies to define the height of our rectangles, or will we use proportions? Let’s try it both ways. First, let’s use frequencies. Notice that our frequencies run from zero to 14; this will correspond to the scale we put on the vertical axis. If we put a tick mark for every whole number between 0 and 14, the result will be pretty crowded; let’s instead put a mark on the multiples of 3 or 5:
Step 4: Now, let’s draw in the first rectangle. The frequency associated with “A” is 14. So we’ll go to 14 on the vertical axis, and place a mark at that height above the “A” label:
Step 5: Then, draw vertical lines straight down from the edges of your mark to make a rectangle:
Step 6: Finally, we can build the rest of the rectangles, making sure that the bases all have the same length of the base = width of the rectangle, and the rectangles don’t touch. Notice that, since the frequency for “D” is zero, that category has no rectangle (but we’ll leave a space there so the reader can see that there is a category with frequency zero). Here’s the result:
Step 7: That’s it! Now, let’s use proportions instead of frequencies. We'll label the vertical axis with evenly spaced numbers that run the full range of the percentages in our table: 0% to 50%. We can divide that into five equal parts (so that each has width 10%), and use that to label our vertical axis:
Step 8: Then, we can fill in the rectangles just as we did before. The height of the “A” rectangle is 50%, the “B” rectangle goes up to 14.3%, “C” goes to 21.4%, there is no rectangle for “D” (since its proportion is 0%), and the “E” rectangle also goes up to 14.3%:
Step 9: Notice that the rectangles are basically identical in our two final bar charts. That’s no coincidence! Bar charts that use proportions and those that use frequencies will always look identical (which is why it doesn’t really matter much which option you choose). Here’s why: look at the bars for “B” and “C”. The frequencies for these are 4 and 6 respectively. Notice that 6 is 50% bigger than 4 (since ), which means that the “C” bar will be 50% higher than the “B” bar. Now look at the same bars using proportions: since , the bar for “C” will be 50% higher than the bar for “B.” The same relationships hold for the other bars, too.
In practice, most graphs are now made with computers. You can use Google Sheets, which is available for free from any web browser.
Now that we’ve explored how bar graphs are made, let’s get some practice reading bar graphs.
Reading Bar Graphs
The bar graph shown gives data on 2020 model year cars available in the United States. Analyze the graph to answer the following questions.
(data source: consumerreports.org/cars)
What proportion of available cars were sports cars?
What proportion of available cars were sedans?
Which categories of cars each made up less than 5% of the models available?
Solution
The bar for sports cars goes up to 10%, so the proportion of models that are considered sports cars is 10%.
The bar corresponding to sedan goes up past 30% but not quite to 35%. It looks like the proportion we want is between 33% and 34%.
We’re looking for the bars that don’t make it all the way to the 5% line. Those categories are hatchback and wagon.
Pie Charts
A pie chart consists of a circle divided into wedges, with each wedge corresponding to a category. The proportion of the area of the entire circle that each wedge represents corresponds to the proportion of the data in that category. Pie charts are difficult to make without technology because they require careful measurements of angles and precise circles, both of which are tasks better left to computers.
Pie charts are sometimes embellished with features like labels in the slices (which might be the categories, the frequencies in each category, or the proportions in each category) or a legend that explains which colors correspond to which categories. When making your own pie chart, you can decide which of those to include. The only rule is that there has to be some way to connect the slices to the categories (either through labels or a legend).
Making Pie Charts
Use the data that follows to generate a pie chart.
Type
Percent
Type
Percent
SUV
43.6%
Minivan
5.5%
Sedan
33.6%
Hatchback
3.6%
Sports
10.0%
Wagon
3.6%
(data source: www.consumerreports.org/cars)
Solution
First, enter the chart above into a new sheet in Google Sheets. Next, click and drag to select the full table (including the header row). Click on the “Insert” menu, then select “Chart.” The result may be a pie chart by default; if it isn’t, you can change it to a pie chart using the “Chart type” drop-down menu in the Chart Editor.
(data source: consumerreports.org/cars)
You can choose to use a legend to identify the categories, as well as label the slices with the relevant percentages.