If you're seeing this message, it means we're having trouble loading external resources on our website.

If you're behind a web filter, please make sure that the domains *.kastatic.org and *.kasandbox.org are unblocked.

Main content

Fixed, variable, and marginal cost

PRD‑1 (EU)
PRD‑1.A (LO)
PRD‑1.A.4 (EK)
PRD‑1.A.5 (EK)
Explore how to think about average fixed, variable, and marginal costs, and how to calculate them, using a firm's production function and costs in this video. Created by Sal Khan.

Video transcript

We here at the Khan Academy are working on some type of a software project. And we need to think about what's the optimal number of programmers we should hire, at least think about how much productivity we're getting per programmer when we're working on this software project. And so what I've done over here-- this is a spreadsheet so I'm not going to be able to write. I'll only be able to type. This is Microsoft Excel right over here. In this column, I have the different numbers of programmers. And then let's say based on other studies or industry studies or our past experience, this tells us how many lines of programming code we can get per month. And obviously, lines of code isn't maybe the best way to measure things because someone can write good lines or bad lines of code. But let's just say this is one way of measuring productivity for software engineers. So the first thing I'm going to think about is what are my fixed costs? So what am I going to spend no matter how many software engineers I hire for this project? And for the sake of this video, my fixed costs will be the office space and the electricity and let's assume I just have an office that can accommodate any number of these programmers. So that's a fixed cost. That's not going to change depending on the number of programmers I have. And then the other fixed cost, let's say I have a product manager for this project. And I'm going to pay her salary to essentially help spec out what this software should actually do. So her salary is, let's say, $10,000 a month and then another $5,000 a month in office space for everybody. So it's going to come out to $15,000 a month. And that's not going to change regardless of however many programmers I have. So I'm going to go into Excel and go to this little bottom right right over here. And I'm going to drag that down. And so it's going to be $15,000 in fixed costs no matter how many programmers I end up hiring. Now the variable cost. Well, let's just say that the full compensation for a programmer is $10,000 a month. So if you include the cost of their salary, if you include the cost of their health insurance, you include the extra goodies that they will eat from the company kitchen, whatever it might be. So it's going to be $10,000 a month. So my variable my total variable costs are going to be $10,000 times the number of programmers. So here I'm going to write equals, and I'm going to write, it's going to be $10,000 per programmer times-- that little snowflake, I pressed Shift + 8 to get that snowflake-- times, and I could say times whatever is in that cell. So you see it's cell D7. And actually let me scroll this over so that you can see the cells. So that is cell D7. And let me press Enter. So it's $10,000 times D7, which is this one right over here. And I just selected that. And I can press Enter. And right now, that's nothing. Let me scroll over so we can see everything a little bit better. Let me scroll over a little bit. There you go. I'm having trouble. OK. There you go. Now, what are going to be my total costs? My total costs are my fixed costs plus my variable costs. So that's going to be equal to-- and I'm just using my arrow keys right now-- it's going to be equal to F7, right? That's cell F7 plus this one, plus my variable costs. My total costs are my fixed costs plus my variable costs. And so it's $15,000. And actually, I can make this true for every row over here. And this is one of the really useful things about a spreadsheet, is I defined this cell as being $10,000 times whatever this cell is right over here. And so what I can just do is I can just take that, drag that all the way down. And for every one of these, it's going to take $10,000 times the cell that's essentially three to its left. So now it's going to be 10,000 times D8. This will be 10,000 times D9. Let's get that. So that we can see it right there. 10,000 times D9. And you could, if you click on there, you can actually see what the formula is. 10,000 times D9. So by dragging that, I was able to get the right formula all the way down. Now the total cost for every row here is going to be two to the left plus one to the left. And so if I drag that down, it'll do that for every row over here. So now this is 25, is the 15 plus the 10. 105 is 15 plus 90,000. Our total costs are fixed costs plus variable costs. Now let's think about the average fixed cost. And the average fixed cost, we're going to think about it in fixed cost per line of code produced. And over here, line of code produced is 0. So we're going to divide by 0, which is undefined. So we could leave that blank. But we could fill this one in. So our total fixed costs-- this is going to be our total fixed costs, which is cell F8. I just used the arrow keys to select F8. Divided by our total lines of code per month. So divided by our total lines of code per month. And so that gets me $3.75 fixed costs per line of code. And then I can do the same thing that I've been doing before. I can drag this down. And then we see what the fixed cost is. So if at any given point if I take the fixed cost, $15,000, divided by the lines of code, I get $1.38. And this actually makes sense because the more programmers I add on to this project, the more lines of code I get, I'm using the same fixed costs I'm. Using the same project manager. I'm using the same office space. So the cost of that project manager and that office space gets spread out along more and more code. So the fixed cost per line of code goes down as we add more and more programmers. Now what is the average of variable cost? So once again, the variable cost is going to be whatever the variable cost is per lines of code per month. So when we're talking about average, we're talking about average cost per line of code. So this is per line of code. Let me write it over here. Per line of code. And I can even say per month. Per line of code per month. Actually, I wanted that spread out more. But the way I've set it up. So let me scroll down. Oops. I'm having issues here. All right. Well these are all average lines of code per month. And so let's think about what happens with our variable costs. So I'm also going to start here because I don't want to divide by 0. So in this month, our total variable costs were $10,000 and our total lines of code are going to be $4,000. G8 divided by E8. And so average variable cost per line of code is 2.50 . And then what happens? So let's do that for every row over here. So when we do it for every row, something interesting happens. Our average fixed cost went down because we're taking the same cost and we're spreading it out amongst more code. But our average variable cost went up. As we added more programmers, per line of code, it actually costs us a little bit more on average per line of code. And that's actually, if you look here, as we add the incremental lines of code we get per programmer is actually going down. That first programmer by themselves, she can write 4,000 lines of code. But then that second programmer you're not getting to 8,000, you're getting to 3,000. And probably because they have to coordinate with each other. They have to plan a little bit more. It's not all in one person's head. Then, when you're at the third one, you're not even adding 3,000 lines of code. You're only adding 2,000 lines of code. And this is actually a real phenomenon that actually happens in companies. The more people you add on to a project, obviously they can maybe do more work, but there's also more coordination. There's going to be more meetings. There's going to be more interruptions. And so each person's individual productivity is going to go down. And this isn't to say that this third coder is somehow worse than the first coder. On average, all of them are now only going to produce 3,000 lines of code a month, when maybe individually they could have each produced 4,000 lines of code, but they have to spend some of their energies now coordinating it. And so that's why our average variable cost per line of code is going up. As we add more and more people, incrementally it's becoming more and more expensive on average to write that line of code. And now if we look at average total cost, that's going to be-- and this is once again, this is per line of code-- is going to be our total cost, H8 divided by the total lines of code per month. So if we just hire one engineer, we're going to have $6.25 spent per line of code. And this is actually just the sum of these two right over here. And then, let me set that formula for every row. And so we see something interesting. When we start to hire a few engineers, we're able to spread out our fixed costs, even though our average variable cost per line of code are going up, our fixed costs are going down. So it's actually we're getting a little bit of a benefit because we're spreading our fixed cost per line of code. But then it starts to get expensive again because, as we said, the more people you have working on the project, they're going to have spend more time coordinating with each other and maybe even undoing each other's work or redoing each other's work as opposed to just writing the actual software. And now let's think about the marginal cost. The marginal cost, the best way to think about it is, what is the incremental cost of that next set of line of code? So one way to think about it-- so this is going to be how much more you're spending divided by how much more code you're getting. So for example, how much more-- and this is going to be, once again, per line of code. So when we go from zero programmers to one programmer, we're going from $15,000 of total cost to $25,000 of total cost. We do it in parentheses. If we're going from 15 to 25, that means we're increasing our expenditure by 25 minus 15. And so that's why I'm doing H8 minus H7. So that's how much more we're spending in expenditures. And then, how much more code are we getting? Well we're getting 4,000 minus 0 lines of code. And the reason why I'm doing the formula this way is so that when we drag it down on all the rows, the formula will be right because it's relatively taking the right cells into account. And the reason why I'm saying it's average is because this is saying, what's the incremental cost per line of code for this first 4,000 lines of code? And then we can go from there. And we can drag it down. And now this tells us the incremental cost per code for the next 3,000 lines of code. And once again, it got a little bit more expensive because we're getting a little bit less efficient as we add more and more people. And there's something very interesting that happens here. And you might have even noticed it in these numbers over here. We actually get a negative marginal cost. And this isn't meaning that when we add more lines of code somehow we're getting money. It's actually saying that as we spend more money, we're actually killing lines of code. Because at some point, if you have too many people on this one project team, they actually start killing each other's productivity. And you can even see it right here in the numbers. When we had seven people, we were able to write 11,400 lines of code. But then the eighth person, because of coordination-- it's not that this eighth person is incompetent, it's just when you have eight people on a team, everyone's productivity goes down so that you're only able to produce 11,200 lines of code. And that's why you had this negative marginal cost. Now, when you get to eight people, all of a sudden by spending more dollars, you're actually destroying some of what you were actually trying to produce. So what I wanted to do here is just to really get you behind the numbers and really maybe give you a little sense of how you can actually do this with a spreadsheet. And get you thinking a little bit about how a firm's cost structure might actually work.