Linear Advance

In early April, a member of the Prusa i3 Facebook group posted about a feature of Marlin firmware that they had come across named linear advance. Documentation for the algorithm can be found here.

In a nutshell, LIN_ADVANCE enables a pressure control feature which sets the pressure inside the nozzle to the needed one according to the print speed. This way, bleeding edges and rough solid infill can be nearly eliminated.

When your 3D printer extrudes plastic, you’ll notice that it takes a little while after you’ve started extruding for the plastic to actually come out of the nozzle. It also doesn’t stop flowing out of the nozzle right after it stops extruding – some still oozes out. This is due to the pressure build up inside the nozzle when the plastic is pushed in. Even though it’s melted, it still takes some force to push it all through a tiny 0.4mm hole.

The force needed to move the filament through the nozzle depends on the speed you’re trying to push it through. If you push it fast (printing fast), the filament will first be compressed before the pressure inside the nozzle is high enough to extrude the required amount of material.

The documentation also mentions that when the linear advance is properly calibrated, your retraction distance should be able to be reduced to almost zero. This works because by using linear advance, the firmware is able to reduce the pressure inside the nozzle when it reaches the end of an extrusion such that it doesn’t keep oozing out. The benefits of linear advance extend far beyond this though. You’ll be able to see in the results section how big of an impact it really has.

After some research, I found that this linear advance feature had not yet been integrated in the Prusa branch of Marlin firmware. I added a feature request for it on the Prusa github here and after a few months it was developed and added to the firmware.

Set up

Before you begin, please ensure that you have calibrated your extruder. You need to be feeding the exact right amount of filament for this to work correctly.

Download the most recent firmware from the Prusa drivers page here, and flash it to your printer as usual. This version includes linear advance and a few other great features, especially enabling saving extruder steps to EEPROM again.. yay! There are instructions on how to flash the firmware here if you’re not familiar with it.

Now you have the capability to use linear advance on your printer!


There’s only one thing that you’ll need to calibrate for the linear advance algorithm, and that is the K factor. This is a measure of how much the printer should compensate for the springy nature of the filament (it compresses and builds up pressure before actually extruding).

A higher K factor means that the filament is more springy, and therefore the printer will compensate for it more. A lower K factor means that the extrusion behaviour is more linear, like the other axes on the printer. A K factor of zero means that there is no compensation at all.

The K factor is heavily dependent on the type of filament that you’re printing with, as plastics flow differently when melted and compressed. In order to find the perfect K factor for your filament, you’ll need to do a test print that uses different K values in different areas and choose where it looks best. Fortunately, Sebastianv650 on the github thread linked above has created a gcode file that makes this extremely easy. You can download it here: K Factor Test

Please note that this gcode uses PLA temperatures and will need to be changed for other material types.

This file will print a zig zag pattern, with each horizontal line using a different K value. The first line is K=0, and each following line increments K by 10. The horizontal lines consist of three segments – it starts slow (20mm/s) for 2cm, then goes fast (70mm/s) for 3cm, then slow again for the last 2cm. This is shown in the diagram below:

K Line Test Diagram

With no linear advance (K=0), this would create a thin section of the line where the printer speeds up, and a thicker section of the line where the printer slows down. If the K factor is set too high, then the opposite of this will occur. The line will be thick where the printer speeds up, and thin where the printer slows down. This shows it is over compensating. What we are aiming for is a line of uniform thickness all the way through, as the thin and thick sections represent under and over extrusion.

Once you have printed the K factor test gcode file, observe the lines that are left on the print bed. This is what mine looked like:

K Line Print


The picture isn’t the best quality, but you can definitely see that the first and last lines have thick and thin areas of under and over extrusion.

Find the line that looks the most consistent and uniform in thickness. In my case, the line for K=40 looks perfect, so that’s what I’ll set my K value as. If two lines look equally uniform to you, then you can choose the value in between. For example if K=40 and K=50 are both equal, then set your K value to 45.

To set the value, it’s as simple as including the command M900 K## in your starting gcode, where ## is your K value. The location of the command within the starting gcode isn’t important at all. Slic3r PE’s new filament specific starting gcode setting is perfect for this, because it allows you to set different K values for different filaments (which you should definitely be doing by the way).

If you download the new drivers from Prusa Research, they will include modified slic3r profiles with higher speeds and some default K values for different materials. I still recommend that you calibrate the K factor for your own filaments, as the values included by Prusa are on the conservative side.

One small note

During development, it was found that some slicers would produce gcode with small areas of very thin extrusion width randomly. With regular printing this isn’t an issue, because the fluid nature of molten filament evens out any tiny differences. However, it does cause some issues with the linear advance algorithm and throws it off.

Slic3r does not have this issue, but it appears that Cura does. In order to stop this from throwing off the linear advance algorithm, you can send a command to the printer telling it the layer height, filament diameter, and extrusion width of that particular print.

Do this with the command M900 W#.## H#.## D#.## where W is the extrusion width, H is the layer height, and D is the filament diameter. So for a 0.3mm layer height print with an extrusion with of 0.45mm using 1.75mm filament, the command would read M900 W0.45 H0.3 D1.75. Enter this into your starting gcode, in addition to the M900 K## command.

I would only recommend doing this specific command if you’re using Cura, as it will have negative effects if used on a print with variable layer heights or variable extrusion widths.


So what difference does any of this make? Well, here’s a list of some differences that you’ll notice when using linear advance:

  • Lower retraction distance necessary
  • No wipe or coast needed
  • Seams not as visible
  • Sharper corners resulting in greater dimensional accuracy
  • No over extrusion at the edges of solid infill
  • Much faster print speeds are possible with no negative effect on quality

Feel free to crank up your print speeds much more than you usually would. You’ll be amazed how the print quality still stays exactly the same. I’m having great results at around 120mm/s, and I could probably go even higher.

As I hinted at above, you should disable coast, wipe, combing, extra restart distance or any other feature like that which is designed to aid with pressure control. You’ll also be able to greatly reduce your retraction distance, but that is of course dependent on other things like print temperatures and filament type.

I hope you’ve found this guide helpful! If you have any problems, please let me know in the comments.


75 thoughts on “Linear Advance

  1. I have seen the bleed out, which i call light bulbing, on every of 3 different 3d printers I owned. I will do some K factor test for a creality. I believe it should fix my light bulbing.

    Side note, I don’t know how people printer under 100mm/s. Below 150 is out of the question.


  2. Hey i know this is not for klipper, but just wanted to let you know that these steps also work for configuring klipper’s Pressure Advance settings. i edited the test gcode file and replaced the M900 commands with klipper’s SET_PRESSURE_ADVANCE ADVANCE=0.XX gcode macro(replace XX with the values you want to test).
    i tested values from 0.0 to 0.45 first.
    then reran it with values ranging from 0.1 to 0.15 (the best 2 values from the first run)

    i was able to settle on .13 for my printer which i could then set permanently in the klipper configuration file.


  3. The test gcode is made for Prusa printers and uses Prusa-specific gcode in the starting section. That’s probably what’s making your printer hang. You can go into a text editor and change it to your regular starting and homing commands, that should fix it


  4. So, I’m using the newest version of marlin 1.1.8, arduino 1.8.5, mks sbase 1.5, simplify3d 4.0.1, I’m trying to send the gcode to the printer, on my sd and my printer cable, on the SD card the machine freezes, on the usb cable it just sits at preparing to print. Is there something special im missing in order to run this test?Do we know if this gcode is supported by marlin 1.1.8? Any ideas how to debug what might be going on?


  5. Hey Matt! Do you happen to know if Cura still suffers the problem you mention in your write-up? I’m just venturing into Cura and thought I should ask – my google-fu is letting me down 😛 Cheers!


    1. Hey Jerry, I’m not too sure about that. My advice would be to just try it out and listen for any weird motor noises for a bit while it’s printing. It should be all good though


    2. I’m using the latest cura and I have been going crazy with these weird under-extrusion issues that are rendering my prints useless a lot of the times, see here:

      I am going to try what the article mentions about setting the width height and diameter. Hopefully it helps. I’d also like to mention that linear advance made layer lines look a bit better but I do notice my extruder does click many times throughout a print since I’ve enabled it but.


  6. Thanks for your article, it was a great help for me!
    After having done some testing with Linear Advance on my Anet A8, I have found out the following, which might be interesting for others playing around with it and trying it out:

    1) When I read about how lin_adv works, my first thought was “cool – that sounds like the exact opposite of velocity painting!”, so i sliced a 2cm cube in vase mode and velocity painted it with some hard contrast texture to test if my thesis was right. And lo and behold – it was! 😉 The velocity painting is pretty much completely gone when you find the right K-Factor, which makes it a MUCH BETTER K-Factor-test for determining the K-Factor than the Gcode above, which requires a perfectly levelled bed and is pretty hard to tell apart! It also prints super fast and barely needs any filament cause it’s in vase mode! You can even print a velocity painted tower and change the K-factor every 5mm or so (hint: Make it interleaved, so you can clearly see where the different k-factors start, like 0-60-10-70-20-80-30-90-40-100-50-110, if you do it gradually it makes it very hard to say where which K-setting starts!), that way you can find the perfect K-Factor for any filament in a few minutes with one test print! If you wonder what “velocity painting” is, see here: (awesome, I didn’t even know they support that in Repetier these days! 😉 Still using that ancient windows program from the guy that figured this out!)

    2) If you want lin_adv off by default, you HAVE to enable it, but set the K-Factor to zero! Otherwise it will be on for EVERY print unless you set K=0 manually!

    3) K-Factors, once set, REMAIN IN EFFECT for all following prints until the machine/eeprom is reset OR you change it again with M900! Keep that in mind when you do your test prints, NOT setting a K-factor in the Gcode will mean that whatever your previous print set is still active!

    Liked by 1 person

  7. I’ve check a few sites but haven’t found an answer to my question. When changing nozzle sizes (from 0.4mm to 0.6mm) should the K value change or because it is material dependent remain the same?


  8. Hi Matt, thank you for the post, I will load the newest firmware onto my MK2S asap! Just a quick question, you said that we need to calibrate our extruder first (i did that a couple months back with another filament that I no longer use), with the newest firmware (3.1.0), we can directly save the E steps to EEPROM correct? No need to put in the calibrate E settings in the G code in slic3r? I remember using mattercontrol to calibrate the extruder, and then updating the EEPROM with the new E steps right in Mattercontrol. Thanks!


  9. Matt,

    I’ve only had my Prusa for the past couple of months and this is going to be the first time updating my firmware. I’m going to update it by using the official 3.1.0 release on GitHub, which includes the Linear Advance addition. My question is that, do I only flash the parts buy using the .hex file and the firmware updater, or do I have to use the source code via arduino? Along with the .hex files, they also provided a source cod .zip and there are instructions for those on arduino.


    1. The best way is just to flash the hex file using the firmware updater program. Make sure you flash the 13a version of the firmware because that’s what will suit your printer if it’s a new one


      1. Thank you, and one more question when people talk about changing the speed to 120mm/s for example, which speed are they talking about in slic3r? Is it the “permieter” speed?


      2. I see, I’ve figured out the speed and I’ve tried to add the M900 K## and I’m not sure if I’m adding it to the correct place. Do you write the command under the filament settings and in the start g-code box? If so, do you leave the ;filament settings line there or delete and replace with the M900 K##? Sorry to bother you again.


  10. Hello. Is the calibration g-code meant for a 0.4 nozzle? How would I change this g-code to perform with different sized nozzles? Thank you for anyone’s help ahead of time.


    1. Looks like I might have missed a part of the post. Would I do this in the beginning of the g-code by entering my specs with M900 W#.## H#.## D#.##?


      1. One more thing. If this code is in fact meant only for 0.4 mm nozzles, is there a way to adjust it to work for different sized nozzles? I apologize for the multiple posts and thank ahead of time or anyone’s help!


    2. Hi Andrey, yes the gcode is made for a 0.4mm nozzle. You don’t need to put in the M900 W.. H.. D.. line in for the calibration, so I’d leave that out. I think the best way to do it would be to increase the flow via the LCD on the printer until it gets to a stage where you’re getting consistent extrusion, and then re run the calibration with that flow %


      1. Hi Matt. Thank you for your response. I will try to find where I can adjust flow on the printer itself while printing tonight as I have never done this before. If I wanted to adjust my E values in the G-code itself to match the thicker extrusion widths required for a thicker nozzle size, do you know of a calculation that I can do this with since I can’t just reslice a new gcode? Somehow Sebastianv650 was able to calculate the E values required for a 0.4 nozzle provided an extruder motion displacement. I just need to do the same for my nozzle size.


  11. I finally got my CR10 upgraded to the point that i can customise and flash the firmware myself, and I have successfully flashed Marlin 1.1.6 with LIN_ADVANCE enabled.

    However when I print the test gcode file there is very little difference from start to finish. The higher settings might be better (which is what i would expect for a long bowden tube setup like mine) but the difference is so small that I’m really not sure if LIN_ADVANCE is actually doing anything. Any ideas on what i can check or change to get a clearer difference? Is there a maximum possible K value? i think i will try again with steps from 20 to 200 and see if i can see a more obvious difference…

    Any other ideas?


    1. Update – it took a setting of K210 or 240 or so to see a real improvement, and then I get thicker lines just as the movement slows down again. I think the slop in the long bowden tube and elasticity of the molten filament are kind of separate issues with separate curves and probably need two separate compensating factors added together!

      Liked by 2 people

      1. @Parenthetical
        I have a CR10s4 also. Upgrages – Bondtech BMG extruder, Volcanco heater block, Capricorn Bowden tube, steel nozzle, dual z axis lead screws and filament sensor.
        I’ve been having a hell of a time with blobs though on certain prints. No amount of retraction, negative extra retraction at start, coasting or nozzle wiped helped. (S3D)
        What did help was upping my extruder jerk and acceleration. I’m hoping using linear advance will help more. I have 1.1.16 marlin on there now also. In your post you mentioned K210, K240. I know I have to test myself and find my best number, but im looking to edit the gcode and start with a better range for my printer. Probably a waste to start at zero with a bowden setup.
        I wanted to ask what value you ended up on?


      2. there was no reply link below Khalil’s post, so this is a reply and also a request for more help.

        I’ve actually not settled on a value, and in fact I’m still not sure that LIN_ADVANCE is working at all on my setup…

        BTW has everyone seen this gcode test generator? very handy.

        Kahlil I think you need to be getting basically decent prints before trying to improve them further with lin advance otherwise it it just gets confusing. I would have said try the range K100 -300 but now I’m really not sure that any of my tests mean anything!

        I thought that maybe there were settings such as DEFAULT_MAX_FEEDRATE that could have been limiting the extruder motion and preventing it from working fully, but increasing that and a few other limits has made no difference.

        In fact what I’m seeing is that my fast section of line is always thinner than my slow section of line, and it never catches up. This doesn’t seem like a LIN_ADVANCE issue but something underlying. What could be causing underextrusion at faster speeds?


  12. Hi!
    I uploaded the FW suggested here and suddenly the printer started making weird stuff.
    Firstly it got slow – very slow. The calibration takes a lot, at some point the printer just seems to be stuck but goes on 4-5 minutes later.
    after the calibration i tried to print the cube for the extrusion multiplier but it is a pain in the …. first the usual procedure to heat up the bed and nozzle. then, suddenly the pinda heat up starts which it didn’t do before but ok, I understand the procedure.
    the print, again, starts fast (brim) but then it gets really really slow. at some point it seams the printer is stuck so the result of the first three layers is a catastrophy.
    The menu and jumping from menu item to the next is very slow. it takes ages. the display seems to refresh every few seconds and it just makes some weird stuff. there’s a creepy “beep” for every click with the button.

    Before the fw i had the latest from prusa with no issues. I wanted to try the linear advance method but with the issues mentioned, it’s impossible to do anything with it.
    Any suggestion?

    I have a video, hope the link works.




    1. Hi Rob, thanks for your comment. Were you printing via sd card or USB? This has been reported as a somewhat common issue with the beta release of the firmware from Prusa, and some users have been able to solve it by simply reflashing the firmware. There’s now an official beta release on the prusa github here if you’d prefer to use that: If you’re printing via USB I would also recommend trying it on the SD card. I hope that helps!


      1. Thanks Matt.
        Always printing via sd card. Most of my prints are 12h or longer.
        Thought i should reflash the FW, will try it in the next couple of days. If it doesn’t work, I’ll try the beta release.
        Thanks for the help!

        Liked by 1 person

  13. Hi Matt, you say you have to do extruder calibration before doing this. Doesn’t flashing the new firmware overwrite this setting anyway and I have to put my value back in after flashing ?


  14. Finally got around to flashing this. What you finding is a good retraction distance? Printing a small part right now and set retraction to like .2 and its leaving a bunch of wisps between the travel points.


  15. I tried this on my recent Creality CR10 but the printer doesn’t seem to respond to setting the K values. Is there something that needs to be set to turn the feature on? Is there a way to tell if my firmware even supports it?


      1. Thanks, I’m new to this, your guide was very helpful! Turns out the firmware is only 1.0 even though the printer is only a month old, do you know what version of Marlin is required? If I upgrade to 1.1 the feature should then be there, is that right?


    1. The current “nightly” Marlin has a good set of CR-10 configs. Linear Advance isn’t enabled, but it could be. Most CR-10 machines have no bootloader on the board, so you may need to flash a bootloader before you’ll be able to upgrade your firmware. Note that this may void your warrantee.


      1. so is the nightly better for the CR10 in some way than the 1.15 version? (which I notice has a CR10 config included). I haven’t flashed it yet.


      2. I’ve spent ages looking and nowhere can I find explicit instruction of where in the firmware you actually enable the LIN_ADVANCE feature. Can anyone tell me?

        I have found in the latest 1.1.6 Marlin, in the file Configuration_adv.h at line 624 the line: //#define LIN_ADVANCE – If I uncomment that line will that enable it? No doubt this is obvious to people already familiar with Marlin but since this is the first time I’ve looked at the Marlin files it is far from obvious how it all fits together!


      1. Thanks.
        I was unsure wether it meant that the whole feature can’t be used with variable or only that small part of it 🙂
        I’ll have to try this on my own printer 😉 Like E-step cal, and PID-tuning did offer good quality improvement I think that this will as well, or at least just give me the opportunity to go with a higher speed 😉
        Now the question is, do I just select the higher print speed in Slic3r and call it a day, or is there some other way to configure it to deaccelerate enough in the corners?


  16. Nice write up Matt and LA is really neat. Very happy to know this issue that plagues the original prusa printer is completely solvable as it’s something that i immediately noticed upon receiving my mk2 both on the printed parts and in my first test print and it really bugs me. Do you know how other firmware types get around this issue because I’ve never seen it be a problem on the many other 3d printers I’ve used before.


    Liked by 1 person

    1. Thanks Martin! I think it’s particularly an issue with the prusa because of the high moving mass on both axes. Some printers just move the print head rather than the bed which I think would help. I’m glad you’re happy with the guide


      1. “I think it’s particularly an issue with the prusa because of the high moving mass on both axes. Some printers just move the print head rather than the bed which I think would help.”

        – Hmm, but I thought the issue is purely due to extrusion pressure. The before and after photo’s I’ve seen seem to suggest so.


      2. I think it’s a combination of slight overshoot and extrusion pressure, and maybe the linear advance helps to compensate for that in part too. I don’t think it’s all isolated

        Liked by 1 person

  17. Very interesting …I never really goes deep into this new linear advance concept… Perhaps it’s time to test but now I own a MMU, I think there is no availbale firmware isn’t it ?


    1. I’ve included the MMU firmware in the compiled firmware zip file, so feel free to try it out! You’ll be one of the first to test it. You may need a k value that is significantly higher than usual, let me know how it goes


      1. I have a prusa style bowden setup, and when I ran the test, K90 seemed the best but still could use improvement. I am adding a K of 110. Is this normal?


Leave a Reply to Tommy Cole Cancel reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s