A prime sum is the total obtained by adding every prime number inside a chosen integer range. Enter two limits to calculate the exact total, see how many primes were found, and review the numbers included in the calculation.
Calculate the Sum of Primes in a Range
The calculator uses an inclusive range. A prime entered as either limit is included in the total.
Both values must be whole numbers between −1,000,000,000 and 1,000,000,000. One calculation may cover up to 1,000,000 consecutive integers.
Prime Numbers Included
What the Prime Sum Includes
For a range from a to b, the calculator checks every integer satisfying a ≤ n ≤ b. Prime values are kept and composite values are ignored. Both boundaries belong to the interval.
Values Below 2 Are Excluded
Prime numbers are positive integers greater than 1 with exactly two positive divisors: 1 and the number itself. Negative integers, 0, and 1 are not prime. A range such as −10 to 10 is valid, but only 2, 3, 5, and 7 contribute to its prime sum.
Two Is the Only Even Prime
Every even integer greater than 2 is divisible by 2. It therefore has more than two positive divisors and is composite. When a range contains 2, the calculator includes it and skips all later even values.
Composite Numbers Do Not Change the Total
A composite number is neither added nor subtracted. In the range 5 through 11, the values 6, 8, 9, and 10 drop out, leaving 5 + 7 + 11 = 23.
The Mathematical Definition
The sum of all primes in an inclusive interval can be written as:
Here, a is the lower limit, b is the upper limit, and p represents each prime inside the interval. The result depends on both the number of primes found and the size of those primes.
Testing one integer is a different operation. To check whether a single value is prime, use the Prime Number Checker.
How the Calculator Finds the Total
It Validates the Interval
Both entries must be whole numbers. The starting value must not exceed the ending value, and the selected interval must remain inside the displayed processing limits. The calculator reports a clear input message instead of silently changing an invalid range.
It Marks Composite Values
The calculation uses a segmented sieve. It first creates the smaller primes needed to examine the selected interval. It then marks multiples of those primes inside the range. Any unmarked integer greater than 1 is prime.
This method is better suited to range calculations than testing every candidate through repeated division. It can also examine a narrow interval near a large value without creating an array for every integer from 2 to the upper boundary.
It Adds Only Confirmed Primes
Each confirmed prime is added once. The supported endpoint and interval limits keep the largest possible total inside JavaScript’s exact safe-integer range, so the displayed sum does not require decimal rounding.
Prime Sum Examples
| Range | Primes Included | Count | Sum |
|---|---|---|---|
| 1–10 | 2, 3, 5, 7 | 4 | 17 |
| 2–2 | 2 | 1 | 2 |
| 10–30 | 11, 13, 17, 19, 23, 29 | 6 | 112 |
| 14–16 | None | 0 | 0 |
| 1–100 | 25 primes | 25 | 1,060 |
| 100–200 | 21 primes | 21 | 3,167 |
Worked Example: Primes From 10 to 30
The composite values are removed from the interval. Six primes remain:
11 + 13 + 17 + 19 + 23 + 29 = 112
The prime count is 6. The average included prime is 112 ÷ 6, which is about 18.6667.
Why Fewer Primes Can Produce a Larger Sum
Prime count alone does not determine the total. The values being added matter just as much.
The interval from 1 to 100 contains 25 primes with a total of 1,060. The interval from 100 to 200 contains only 21 primes, yet their total is 3,167. The second interval has fewer primes, but its primes are much larger on average.
Range Rules That Change the Result
| Input | Resulting Behavior |
|---|---|
| 1 to 10 | 1 is excluded; 2, 3, 5, and 7 are added. |
| 2 to 2 | The only value is prime, so the result is 2. |
| 15 to 15 | No prime is present, so the count and sum are 0. |
| −10 to 10 | Only 2, 3, 5, and 7 contribute to the total. |
| 30 to 10 | The limits must be swapped before calculation. |
| 2.5 to 20 | The decimal entry is rejected because primality applies to integers. |
| More than 1,000,000 consecutive integers | The interval must be narrowed before processing. |
Exact Totals and Displayed Averages
The Prime Sum Is a Whole Number
Every included value is an integer, so the total is also an integer. No decimal approximation is needed for the sum.
The Average May Use Decimal Places
The average is calculated by dividing the total by the number of primes found. When this division does not end evenly, the displayed average is rounded to four decimal places. That display choice does not alter the prime sum.
Long Prime Lists Are Shortened Initially
A large interval may contain thousands of primes. The calculator shows the first 200 by default so the result area remains readable. The full list can still be opened, copied, or downloaded.
Uses of a Prime Sum Calculator
Checking Mathematics Work
The displayed list helps identify whether an incorrect answer came from missing a prime, including a composite number, or adding the correct values incorrectly.
Testing Prime-Generating Code
A program’s prime count, list, and total can be compared with a known interval. A mismatch may reveal an endpoint error, an incorrect treatment of 1, or a sieve that failed to mark a composite value.
Exploring Prime Distribution
Equal-width intervals can contain different numbers of primes. Comparing the count, total, and average shows how prime frequency and prime size affect the result in different ways.
Preparing Reusable Number Sets
The CSV and JSON downloads provide structured prime lists for exercises, small data tests, sequence exploration, and calculator verification.
Common Prime Sum Errors
Adding Every Integer in the Range
The ordinary sum from 1 to 10 is 55. The prime sum is 17 because only 2, 3, 5, and 7 are included.
Treating 1 as Prime
Adding 1 changes the result but conflicts with the definition of a prime. One has only one positive divisor, not two.
Excluding Prime Endpoints
The calculator uses a closed interval. For the range 5–11, both endpoints are prime and both are included.
Confusing a Range Sum With a Target Decomposition
A range sum adds every prime between two limits. A target decomposition asks which primes can be combined to produce one chosen number. These operations have different inputs and outputs.
Questions About Prime Sums
Are both range limits included?
Yes. The calculator uses an inclusive interval. A prime entered as either limit is added to the total.
Does the calculator include 1?
No. One has only one positive divisor and is not prime.
Can a prime sum equal zero?
Yes. The result is zero when the selected interval contains no prime numbers.
Can negative numbers be entered?
Yes. Values below 2 are ignored because they are not prime. A negative lower limit does not change which positive primes are included.
Why are decimal values rejected?
Prime numbers are defined among integers. Decimal values do not have the divisor structure used by primality.
Is the prime sum rounded?
No. The sum uses exact whole-number arithmetic inside the supported limits. Only the displayed average may be rounded.
Does this add the first n prime numbers?
No. This calculator adds every prime between two selected boundaries. A first-n-primes calculation uses a number of terms instead of an ending boundary.